Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get remote OS version info with VB.NET

Posted on 2004-08-21
3
Medium Priority
?
1,117 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

824 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