Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

NetServerGetInfo (netapi32)
 
.
Summary
Retrieves the current OS configuration information of the specified server

C# Signature:

[DllImport("netapi32.dll", SetLastError=true)]
static extern TODO NetServerGetInfo(TODO);

VB Signature:

Declare Function NetServerGetInfo Lib "netapi32.dll" (ByVal ServerName As String, _
    ByVal Level As Integer, ByRef ptrBuff As IntPtr) As Integer

User-Defined Types:

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

Notes:

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.

Tips & Tricks:

Please add some!

Sample Code:

    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

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

****************************************

I have tried using NetShareGetInfo. I want to find the sharename of local machine's shared folder. Below mentioned the code snippet. The call to NetShareGetInfo always return the error code as 2310(ERROR_ACCESS_DENIED). I am not able to figure out the problem. Please help me on this issue.

public class UnManagedTrialForShare

{

    [DllImport("Netapi32.dll")]
         public static extern NET_API_STATUS NetShareGetInfo (
        [MarshalAs(UnmanagedType.LPWStr)]
       string ServerName, string  NetName, Int32 Level, out IntPtr buffer);

       public static string GetNetShareInfo(string ServerName, string NetName)
       {
         int Level = 0;
        IntPtr buffer;
        SHARE_INFO_0 shareInfo = new SHARE_INFO_0();            
        NET_API_STATUS status = NetShareGetInfo(null,NetName,Level,out buffer);
        object obj = Marshal.PtrToStructure(buffer,typeof(SHARE_INFO_0));            return ((SHARE_INFO_0)obj).shi0_netname.ToString();
         }

}

[ StructLayout( LayoutKind.Sequential )]

public struct SHARE_INFO_0

{

    [MarshalAs(UnmanagedType.LPWStr)]
    public string shi0_netname;

}

public enum NET_API_STATUS

{

    ERROR_ACCESS_DENIED,
    ERROR_INVALID_LEVEL,
    ERROR_INVALID_PARAMETER,
    ERROR_MORE_DATA,
    ERROR_NOT_ENOUGH_MEMORY,
    NERR_BufTooSmall,
    NERR_NetNameNotFound

}

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions