Click here to Skip to main content
Licence 
First Posted 23 Mar 2005
Views 17,934
Bookmarked 13 times

OSInfo with UserInfo

By | 23 Mar 2005 | Article
This application reads the Userinformation(Auth. Type, ...) and the OS with ServicePack out

Introduction

This application reads the OS version, the ServicePack and the user's properties out.

 

Code-Blocks

</FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> Form1_Load(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> System.Object, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> System.EventArgs) </FONT><FONT color=#0000ff size=2>Handles</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>MyBase</FONT><FONT size=2>.Load
</FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> usid </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>New</FONT><FONT size=2> User.Identity
Label1.Text = usid.CurrentUserName
Label2.Text = usid.CurrentMaschineName
Label3.Text = usid.DomainName
Label4.Text = usid.UserIdentityName
Label5.Text = usid.IsAuthenticated
Label6.Text = usid.AuthenticationType
OSVer.Text = Environment.OSVersion.ToString
ReadOS()
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub
#</FONT><FONT color=#0000ff size=2>Region</FONT><FONT size=2> "OS"
</FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> objWMI </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Object
</FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> colItems </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Object
</FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> objItem </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Object
</FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> ReadOS()
</FONT><FONT color=#008000 size=2>'Check if WMI is installed
objWMI = GetObject("WinMgmts:")
</FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> Err.Number <> 0 </FONT><FONT color=#0000ff size=2>Then
OSSP.Text = "Kein WMI installiert!"
Err.Clear()
objWMI = </FONT><FONT color=#0000ff size=2>Nothing
</FONT><FONT color=#0000ff size=2>Exit</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>If
</FONT><FONT color=#008000 size=2>'create and query WMI-Object
objWMI = GetObject("WinMgmts:/root/cimv2")
colItems = objWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem")
</FONT><FONT color=#0000ff size=2>For</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Each</FONT><FONT size=2> objItem </FONT><FONT color=#0000ff size=2>In</FONT><FONT size=2> colItems
</FONT><FONT color=#008000 size=2>'Check if it's 'Windows NT', 'Windows 2000' or 'Windows XP'
</FONT><FONT color=#008000 size=2>'All NT-OSs have OSType 18
</FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> objItem.OSType = 18 </FONT><FONT color=#0000ff size=2>Then</FONT><FONT color=#008000 size=2>
OSSP.Text = objItem.Caption & vbNewLine & objItem.CSDVersion
</FONT><FONT color=#0000ff size=2>Else
OSSP.Text = "The ServicePack can only be accessed for " & " the OSs 'Windows NT, 2000 and XP' "
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>If
</FONT><FONT color=#0000ff size=2>Next</FONT><FONT size=2> objItem
</FONT><FONT color=#008000 size=2>'clear
objItem = </FONT><FONT color=#0000ff size=2>Nothing
colItems = </FONT><FONT color=#0000ff size=2>Nothing
objWMI = </FONT><FONT color=#0000ff size=2>Nothing
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub
#</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Region

 

Imports</FONT><FONT size=2> System.Environment
Imports</FONT><FONT size=2> System.Security.Principal
 
Namespace</FONT><FONT size=2> User
</FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Class</FONT><FONT size=2> Identity
</FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> m_User </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>New</FONT><FONT size=2> WindowsPrincipal(WindowsIdentity.GetCurrent)
</FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>ReadOnly</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Property</FONT><FONT size=2> CurrentUserName() </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String
</FONT><FONT color=#0000ff size=2>Get
</FONT><FONT color=#0000ff size=2>Return</FONT><FONT size=2> UserName
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Get
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Property
</FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>ReadOnly</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Property</FONT><FONT size=2> CurrentMaschineName() </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String
</FONT><FONT color=#0000ff size=2>Get
</FONT><FONT color=#0000ff size=2>Return</FONT><FONT size=2> MachineName
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Get
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Property
</FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>ReadOnly</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Property</FONT><FONT size=2> DomainName() </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String
</FONT><FONT color=#0000ff size=2>Get
</FONT><FONT color=#0000ff size=2>Return</FONT><FONT size=2> UserDomainName
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Get
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Property
</FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>ReadOnly</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Property</FONT><FONT size=2> UserIdentityName() </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String
</FONT><FONT color=#0000ff size=2>Get
</FONT><FONT color=#0000ff size=2>Return</FONT><FONT size=2> m_User.Identity.Name
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Get
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Property
</FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>ReadOnly</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Property</FONT><FONT size=2> IsAuthenticated() </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String
</FONT><FONT color=#0000ff size=2>Get
</FONT><FONT color=#0000ff size=2>Return</FONT><FONT size=2> m_User.Identity.IsAuthenticated.ToString
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Get
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Property
</FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>ReadOnly</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Property</FONT><FONT size=2> AuthenticationType() </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String
</FONT><FONT color=#0000ff size=2>Get
</FONT><FONT color=#0000ff size=2>Return</FONT><FONT size=2> m_User.Identity.AuthenticationType
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Get
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Property
</FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Class
End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Namespace</FONT>
 

Well that's everything. I won't explain here everything because Basic is an easy readeble

language and some functions tell with their name what they do.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Merz_Konstantin_FFB

Web Developer

Germany Germany

Member

My hobbies are C++(managed and not manged(i'm a total tiro at this), Visual Basic .Net, Inside Win2k, Tennis and maths.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 23 Mar 2005
Article Copyright 2005 by Merz_Konstantin_FFB
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid