|
Last-modified: 2004-01-26 (月) 21:45:52 (7394d)
一応説明すると、CIFS(Common Internet File System)とは、MicrosoftのSMBプロトコルを拡張し、その仕様が公開されているものです。 WMI(Windows Management Instrumentation)を使う.NETらしさを損なわない方法。NTドメインに対応していたり、リモートPCの制御までできるようですが、仕組みが少し複雑になりますね。System.Managament.dllを参照設定してusing System.Managementしてください。 ManagementPath path = new ManagementPath(); // remote server NetBios name or host name path.Server = "{computername}"; path.NamespacePath = @"root\CIMV2"; path.RelativePath = @"Win32_Share"; ConnectionOptions co = new ConnectionOptions(); // account with WMI access privileges on remote server // (Remote enabled, execute methods ....) //co.Username = "{username}"; //co.Password = "{userpassword}"; // downlevel domain name or server name if local account //co.Authority = "NTLMDOMAIN:domainname"; ManagementScope scope = new ManagementScope(path, co); ManagementClass mc = new ManagementClass(scope, path, null); ManagementBaseObject inParams = mc.GetMethodParameters("Create"); inParams["Name"] = "share_name"; inParams["Path"] = @"d:\share_folder"; inParams["Type"] = 0; inParams["Access"] = null; inParams["Description"] ="共有フォルダの説明"; inParams["MaximumAllowed"] = 5; ManagementBaseObject mbo = mc.InvokeMethod("Create", inParams, null); uint result = (uint) mbo.Properties["ReturnValue"].Value; // 0 = success Win32API(NetApi32.dll)を使う旧APIを使う方法もあります。次期WindowsからWin32APIが無くなるということなので、こういった方法は極力避けたいですね。 Windows Scripting Host Network object(WshNetwork)を使う WSHはこの辺の機能を独自に実装しています。COMとして公開されているので、C#からこれを呼び出すという手はあります。 |