Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get remote OS version info with VB.NET

Posted on 2004-08-21
3
Medium Priority
?
1,105 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

722 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