Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Get WMI information from remote PC. Useful for admins!

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,51959
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Get WMI information from remote PC. Useful for admins!
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Get WMI information from remote PC. Useful for admins! - 9/18/2007 7:23:50 AM   
  ThrashersFan

 

Posts: 7
Score: 0
Joined: 9/18/2007
Status: offline
<HTML>
<HEAD>
<HTA:Application
   Border = Thick
   BorderStyle = Complex
   ShowInTaskBar = YES
   MaximizeButton = YES
   MinimizeButton = YES
>
<SCRIPT LANGUAGE="VBScript">
Sub window_onLoad
   Set objDocument = self.Document
   objDocument.open

'This script was pieced together by ThrashersFan on 09/15/07-09/18/07
'Snippets were taken from the MS scripting book and some code is original
'This script gets some WMI information from a remote computer that is useful to admins. It pings the computer
'to make sure it's available first. If the computer can be pinged, it gets the information and displays it in
'an Internet Explorer window.

'Get name of target computer from user
strComputer = InputBox("Enter the name or IP of the computer you want information from. (Enter '.' for the local computer):")

'Verify information was entered by the user and close window if there was none.
If strcomputer = "" Then Window.Close()

'Ping computer specified by user input. If the computer doesn't respond to a ping, display a message box to the user
'letting them know.  Then, close window.
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
   ExecQuery("select * from Win32_PingStatus where address = '"_
       & strcomputer & "'")
For Each objStatus in objPing
   If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
   MsgBoxValue = MsgBox ("Computer " & strComputer & " cannot be reached", 65, "Computer unavailable")
   window.close()
   End If
Next

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'Define constants
Const wbemFlagReturnImm = &h10
Const wbemFlagForward = &h20
Const HARD_DISK = 3

'Query the WMI information of the computer
Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
   strComputer = objItem.Name
Next

'Query processor properties
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", wbemFlagReturnImm + wbemFlagForward)

'Prepare display of results for processor entries
For Each objItem In colItems
   ProcType = ltrim(objItem.Name)
Next

Set objDomain = getObject("LDAP://rootDse")
DC = objDomain.Get("dnsHostName")

Set colSettings = objWMIService.ExecQuery _
   ("Select * from Win32_OperatingSystem")

'Query the OS properties
Set colOperatingSystems = objWMIService.ExecQuery _
   ("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
   OS = objOperatingSystem.Caption
   OSVersion = objOperatingSystem.Version
Next

'Set variable values for OS properties retrieved
For Each objOperatingSystem in colSettings
   OSServicePack = objOperatingSystem.ServicePackMajorVersion
   WinDir = objOperatingSystem.WindowsDirectory
   PhysMem = objOperatingSystem.FreePhysicalMemory
   VirtMem = objOperatingSystem.TotalVirtualMemorySize
   AvailVirtMem = objOperatingSystem.FreeVirtualMemory
Next

'Collect information about the computer itself, or the motherboard if it's a custom-built PC
Set colSettings = objWMIService.ExecQuery _
   ("Select * from Win32_ComputerSystem")

For Each objComputer in colSettings
   CompName = objComputer.Name
       CompManufacturer = objComputer.Manufacturer
       CompModel = objComputer.Model
   CompPhysMem = objComputer.TotalPhysicalMemory
Next

'Find out who is logged in on the computer and store the username
Set colComputer = objWMIService.ExecQuery _
   ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
   UserName = objComputer.UserName
Next

Set colSettings = objWMIService.ExecQuery _
   ("Select * from Win32_Processor")

Set colSettings = objWMIService.ExecQuery _
   ("Select * from Win32_BIOS")

For Each objBIOS in colSettings
   BIOSVer = objBIOS.Version
Next

'Get hard drive information
strComputer = "."
Set colDisks = objWMIService.ExecQuery _
   ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")

For Each objDisk in colDisks
   HDID = objDisk.DeviceID       
   HDFree = objDisk.FreeSpace
Next

'Begin displaying the information
objdocument.WriteLn "<B>"
objdocument.WriteLn "<U>"
objdocument.WriteLn "Computer Information" & "<br>"
objdocument.WriteLn "</U>"
objdocument.WriteLn "</B>"
objdocument.WriteLn "Computer Name:        " & CompName & "<br>"

'Get IP address of the computer and display it in the window
Set IPConfigSet = objWMIService.ExecQuery _
   ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")

For Each IPConfig in IPConfigSet
   If Not IsNull(IPConfig.IPAddress) Then
       For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
           objdocument.WriteLn "IP Address:        " & IPConfig.IPAddress(i) & "<br>"
       Next
   End If
Next

objdocument.WriteLn "Computer Manufacturer:    " & CompManufacturer & "<br>"
objdocument.WriteLn "Computer Model:        " & CompModel & "<br>"
objdocument.WriteLn "Processor Type:        " & ProcType & "<br>"
objdocument.WriteLn "BIOS Version:        " & BIOSVer & "<br>"
objdocument.WriteLn "User Logged In:        " & UserName & "<br>"
objdocument.WriteLn "DC Logged Onto:        " & DC & "<br>"
objdocument.WriteLn "<br>"

objdocument.WriteLn "<B>"
objdocument.WriteLn "<U>"
objdocument.WriteLn "Operating System Information" & "<br>"
objdocument.WriteLn "</U>"
objdocument.WriteLn "</B>"
objdocument.WriteLn "OS:        " & OS & "<br>"
objdocument.WriteLn "OS Version:    " & OSVersion & "<br>"
objdocument.WriteLn "OS Service Pack:    " & OSServicePack & "<br>"
objdocument.WriteLn "Windows Directory:    " & WinDir & "<br>"
objdocument.WriteLn "<br>"

objdocument.WriteLn "<B>"
objdocument.WriteLn "<U>"
objdocument.WriteLn "Hard Drive Information" & "<br>"
objdocument.WriteLn "</U>"
objdocument.WriteLn "</B>"
objdocument.WriteLn "Hard Drive ID:        " & HDID & "<br>"
objdocument.WriteLN "Free Space:        " & HDFree & "<br>"
objdocument.WriteLN "<br>"

objdocument.WriteLn "<B>"
objdocument.WriteLn "<U>"
objdocument.WriteLn "Memory Information" & "<br>"
objdocument.WriteLn "</U>"
objdocument.WriteLn "</B>"
objdocument.WriteLn "Total Physical Memory:    " & CompPhysMem & "<br>"
objdocument.WriteLn "Free Physical Memory:    " & PhysMem & "<br>"
objdocument.WriteLn "Total Virtual Memory:    " & VirtMem & "<br>"
objdocument.WriteLn "Free Virtual Memory:    " & AvailVirtMem & "<br>"
objdocument.WriteLn "<br>"

End Sub

</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
 
 
Post #: 1
 
 RE: Get WMI information from remote PC. Useful for admins! - 2/28/2008 8:30:54 PM   
  twinm4k3r

 

Posts: 2
Score: 0
Joined: 2/28/2008
Status: offline
Hi, new to this.

Is there anyway to add other information to this script? i.e

1) Mapped network drives and paths
2) installed printers and which one is the default
3)list of files from a specific location ( citrix apps that have been pulled down according to the users profile )

Basically trying to piece together a script that will gather audit information regarding a user and their hardware profile/software profile - that will be outputted to a printable file?

ANy help with this would be greatly appreciated.

Thanks

(in reply to ThrashersFan)
 
 
Post #: 2
 
 RE: Get WMI information from remote PC. Useful for admins! - 2/28/2008 9:10:55 PM   
  ginolard


Posts: 1005
Score: 21
Joined: 8/10/2005
Status: offline
Take a look at my sig.  ManagePC is a tool that will do all that and more.  It's written in .NET now but there's still an HTA version available for download

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to twinm4k3r)
 
 
Post #: 3
 
 RE: Get WMI information from remote PC. Useful for admins! - 2/28/2008 11:45:34 PM   
  twinm4k3r

 

Posts: 2
Score: 0
Joined: 2/28/2008
Status: offline
Thanks for the reply.

Before i continue...congrats on a super application, thanks for sharing it.

I have tried running the app and works fine, although for some reason there are bits of info that it doesn't pick up.
1) Mapped network drives
2) logged on users

Any ideas why not?

(in reply to ginolard)
 
 
Post #: 4
 
 RE: Get WMI information from remote PC. Useful for admins! - 3/9/2008 9:19:02 PM   
  ginolard


Posts: 1005
Score: 21
Joined: 8/10/2005
Status: offline
What version are you talking about?  The HTA or the .NET version? 

The .NET version should be able to retrieve the mapped drives and logged on users from Win2K and XP machines.  It's not (fully) Vista compatible yet.

The HTA version isn't under development any more.

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to twinm4k3r)
 
 
Post #: 5
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Get WMI information from remote PC. Useful for admins! Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts