简体   繁体   English

如何查看我的程序可以访问哪些共享文件夹?

[英]How can I see which shared folders my program has access to?

My program needs to read and write to folders on other machines that might be in another domain. 我的程序需要读写可能位于另一个域中的其他计算机上的文件夹。 So I used the System.Runtime.InteropServices to add shared folders. 因此,我使用System.Runtime.InteropServices添加共享文件夹。 This worked fine when it was hard coded in the main menu of my windows service. 当我在Windows服务的主菜单中对其进行硬编码时,此方法效果很好。 But since then something went wrong and I don't know if it is a coding error or configuration error. 但是从那以后出现了问题,我不知道这是编码错误还是配置错误。

  • What is the scope of a shared folder? 共享文件夹的范围是什么? If a thread in my program adds a shared folder, can the entire local machine see it? 如果程序中的线程添加了共享文件夹,则整个本地计算机都可以看到它吗?
  • Is there a way to view what shared folders has been added? 有没有办法查看已添加了哪些共享文件夹? Or is there a way to see when a folder is added? 还是有办法查看何时添加文件夹?

     [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); } } 

Each thread in a computer runs under a specific user account. 计算机中的每个线程都以特定的用户帐户运行。 Shared folder have security settings, ie they are subject to ACL-based access control, so that some users may have access permission and others may not. 共享文件夹具有安全设置,即它们受基于ACL的访问控制的约束,因此某些用户可能具有访问权限,而其他用户则没有。 This means that the thread in your program may be able to "see" some shared folders, while other threads in the same computer (including the interactive user using the desktop) might be unable to "see" those folders. 这意味着程序中的线程可能能够“查看”某些共享文件夹,而同一计算机(包括使用桌面的交互式用户)中的其他线程可能无法“查看”那些文件夹。

In summary: you should assume very little. 总结:您应该承担很少的责任。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM