VBScript – Get OS Name

The script below is simple – use it to get the name of the current OS (Windows XP, 7, etc).  Currently it outputs to a message box but can be used for case statements, if else, etc.

Code start

on error r
esume next

sRes = Inputbox(“Enter the Server or Computer name”, “OS”)
strComputer = sRes
if strComputer = “” then
Msgbox “No server was enter, will use current computer”,vbCritical,”Warning”
strComputer = “.”
end if
Set objWMIService = GetObject(“winmgmts:\\”  & strComputer & “\root\cimv2”)
Set colItems = objWMIService.ExecQuery(“Select * from Win32_OperatingSystem”,,48)
For Each objItem in colItems
Msgbox objItem.Caption,VbInformation,”Running on ” & strComputer & ” is:”
Code End


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s