I am trying to get a list of shares on a specific machine. So I decided to use the 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. 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
ERROR_NETWORK_UNREACHABLE 1231 (0x4CF)
The network location cannot be reached.
Are you sure that your NetShareEnum definition valid? I am not very familar with VB.NET, but I have worked with netapi32 in c# in the past, and in general without problems.
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
There is one key-value pair per share. Value is REG_MULTI_SZ type, that looks like simple ini. Check for "type=0" (file share), and read path.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.