[DllImport("netapi32.dll", SetLastError=true)]
static extern TODO NetServerGetInfo(TODO);
Declare Function NetServerGetInfo Lib "netapi32.dll" (ByVal ServerName As String, _
ByVal Level As Integer, ByRef ptrBuff As IntPtr) As Integer
Here is how you would define the SERVER_INFO_102 structure (100 and 101 can be defined in a similar way):
<StructLayout(LayoutKind.Sequential)> _
Private Structure SERVER_INFO_102
Dim sv102_platform_id As Integer
<MarshalAs(UnmanagedType.LPWStr)> Dim sv102_name As String
Dim sv102_version_major As Integer
Dim sv102_version_minor As Integer
Dim sv102_type As Integer
<MarshalAs(UnmanagedType.LPWStr)> Dim sv102_comment As String
Dim sv102_users As Integer
Dim sv102_disc As Integer
Dim sv102_hidden As Boolean
Dim sv102_announce As Integer
Dim sv102_anndelta As Integer
Dim sv102_licenses As Integer
<MarshalAs(UnmanagedType.LPWStr)> Dim sv102_userpath As String
End Structure
1. ptrBuff is a pointer to a structure of type SERVER_INFO_100, SERVER_INFO_101 or SERVER_INFO_102.
2. Pass in vbNullString as the first parameter if you are querying the local machine. Otherwise, just pass in the name of the machine.
Please add some!
Private Sub GetServerName( )
Dim ptrBuff As IntPtr
Dim strServerInfo As SERVER_INFO_102
Dim lRetCode As Integer
lRetCode = NetServerGetInfo(vbNullString, 102, ptrBuff)
strServerInfo = CType(Marshal.PtrToStructure(ptrBuff, GetType(SERVER_INFO_102)), SERVER_INFO_102)
Debug.WriteLine(strServerInfo.sv102_version_major)
Debug.WriteLine(strServerInfo.sv102_version_minor)
End Sub
Do you know one? Please contribute it!