0
我的程序需要读取和写入其他机器上可能位于另一个域中的文件夹。所以我使用System.Runtime.InteropServices来添加共享文件夹。当它在我的Windows服务的主菜单中被硬编码时,它工作得很好。但是从那以后出了点问题,我不知道它是编码错误还是配置错误。如何查看我的程序可以访问哪些共享文件夹?
- 共享文件夹的范围是什么?如果我的程序中有一个线程添加共享文件夹,整个本地机器能否看到它?
有没有办法查看共享文件夹已被添加?或者有没有办法查看何时添加文件夹?
[DllImport("NetApi32.dll", SetLastError = true, CharSet = CharSet.Unicode)] internal static extern System.UInt32 NetUseAdd(string UncServerName, int Level, ref USE_INFO_2 Buf, out uint ParmError); [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] internal struct USE_INFO_2 { internal LPWSTR ui2_local; internal LPWSTR ui2_remote; internal LPWSTR ui2_password; internal DWORD ui2_status; internal DWORD ui2_asg_type; internal DWORD ui2_refcount; internal DWORD ui2_usecount; internal LPWSTR ui2_username; internal LPWSTR ui2_domainname; } private void AddSharedFolder(string name, string domain, string username, string password) { if (name == null || domain == null || username == null || password == null) return; USE_INFO_2 useInfo = new USE_INFO_2(); useInfo.ui2_remote = name; useInfo.ui2_password = password; useInfo.ui2_asg_type = 0; //disk drive useInfo.ui2_usecount = 1; useInfo.ui2_username = username; useInfo.ui2_domainname = domain; uint paramErrorIndex; uint returnCode = NetUseAdd(String.Empty, 2, ref useInfo, out paramErrorIndex); if (returnCode != 0) { throw new Win32Exception((int)returnCode); } }
谢谢。我确实解决了这个问题,这似乎是程序没有正确读取配置文件的一部分。 – 2011-01-14 13:04:44