[英]Can anyone help me with the Windows API NetApi32?
I am trying to get a list of shares on a specific machine. 我正在尝试获取特定计算机上的共享列表。 So I decided to use the Windows API NetApi32.dll. 因此,我决定使用Windows API NetApi32.dll。 Here is my code snippet: 这是我的代码段:
Dim svr As String = Environment.MachineName
Dim level As Integer = 2
Dim sharesRead As Integer, totalEntries As Integer, nRet As Integer, hResume As Integer = 0
Dim pBuffer As IntPtr = IntPtr.Zero
nRet = NetApi32.NetShareEnum(svr, level, pBuffer, -1, sharesRead, totalEntries, hResume)
I'm getting a return code of 1231, but can't seem to find what that equates to. 我得到的返回码为1231,但似乎找不到等于什么的代码。 Can anyone point me in the correct direction on how to do this if it an incorrect way? 如果这是不正确的方法,谁能指出正确的方向呢?
http://msdn.microsoft.com/en-us/library/ms681383(VS.85).aspx http://msdn.microsoft.com/zh-CN/library/ms681383(VS.85).aspx
ERROR_NETWORK_UNREACHABLE 1231 (0x4CF) ERROR_NETWORK_UNREACHABLE 1231(0x4CF)
The network location cannot be reached. 无法到达网络位置。
Are you sure that your NetShareEnum definition valid? 您确定您的NetShareEnum定义有效吗? I am not very familar with VB.NET, but I have worked with netapi32 in c# in the past, and in general without problems. 我对VB.NET不太熟悉,但是过去我曾在C#中使用过netapi32,并且通常没有问题。
But anyway, if you want to enumerate all shares on your computer, you can do it another way. 但是无论如何,如果您想枚举计算机上的所有份额,则可以采用另一种方式。 In the following registry key you can find all current computer shares: 在以下注册表项中,您可以找到所有当前的计算机共享:
HKLM\\System\\CurrentControlSet\\Services\\LanmanServer\\Shares HKLM \\ System \\ CurrentControlSet \\ Services \\ LanmanServer \\ Shares
There is one key-value pair per share. 每股有一对键值对。 Value is REG_MULTI_SZ type, that looks like simple ini. 值是REG_MULTI_SZ类型,看起来像简单的ini。 Check for "type=0" (file share), and read path. 检查“ type = 0”(文件共享),并读取路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.