Solved

Get remote OS version info with VB.NET

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Store results in vb.net 3 20
export data table to excel in vb.net 10 22
Database Connections Not being returned to Connection Pool 7 24
Help with exporting to excel 4 25
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 …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

14 Experts available now in Live!

Get 1:1 Help Now