Solved

Get remote OS version info with VB.NET

Posted on 2004-08-21
3
1,089 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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