Solved

Get remote OS version info with VB.NET

Posted on 2004-08-21
3
1,082 Views
Last Modified: 2010-07-27
Hi,

I try to obtain the OS version of a specified computer on the network

I have an error on line "nresult = NetServerGetInfo(srv(0), 102, hbuffer)" with the code below :

Public Declare Function NetServerGetInfo Lib "netapi32" ( _
ByVal ServerName As Byte, _
ByVal Level As Long, _
ByVal buffer As Long) As Long

Dim server As String
Dim srv() As Byte
Dim nresult As Long
Dim hbuffer As Long
Dim txtEncoder As New UTF8Encoding
server = "GLOBO"
hbuffer = 0
server = server & vbNullChar
srv = txtEncoder.GetBytes(server)
nresult = NetServerGetInfo(srv(0), 102, hbuffer)
Label1.Text = nresult


Thanks for your help!
0
Comment
Question by:Yerk
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
imu79 earned 500 total points
ID: 11865129
Here's a working example of using NetServerGetInfo:

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

<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

 Private Sub GetServerName( )
        Dim ptrBuff As IntPtr
        Dim strServerInfo As SERVER_INFO_102
        Dim lRetCode As Integer
        lRetCode = NetServerGetInfo("ABACUS", 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

Note that the level is a DWORD which is a 32 bit integer and hence must be of type 'Integer' in the declaration.

hope this helps..
Imran.
0
 

Author Comment

by:Yerk
ID: 11869451
Hi Imran,

Your solution works perfectly, Thanks a lot for this great job.

Have a nice day,

Didier
0
 
LVL 3

Expert Comment

by:imu79
ID: 11869599
happy to help :)

have a great day !

Imran.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now