Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 16th, 2005, 11:11 AM   #1
FelixM
Newbie
 
Join Date: May 2005
Posts: 7
Rep Power: 0 FelixM is on a distinguished road
Asset Management Tracking - nice but not good enough

I have hacked together a vb script to get what I need from our network. It runs but it's not complete - it's well commented but here it is again - save the file as that of the user who runs it and secondly, add in the IP address - to this file. All the code is there, just not in the right order...I understand it's prob not as simple as I'd hoped.

'[code]

' Check command line parameters
Select Case WScript.Arguments.Count
Case 0
' Default if none specified is local computer (".")
Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
strComputer = objItem.name
Next
Case 1
' Command line parameter can either be a computer
' name or "/?" to request online help
strComputer = UCase( Wscript.Arguments(0) )
if InStr( strComputer, "?" ) > 0 Then Syntax
Case Else
' Maximum is 1 command line parameter
Syntax
End Select


' ****Show current logged on user*******
dim user
set user=createobject("WScript.Network")
msgbox user.UserName
Set user = Nothing

' ****Show IP address*******************
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration ")

For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) _
to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
Next
End If
Next

'****End - I would like two things - 1: all info in 1 text file & 2, save the file the username returned.*******

Dim outFile

' Header line for screen output
strMsg = vbCrLf & "Hardware summary for " & strComputer & ":" & vbCrLf & vbCrLf

' Enable error handling
On Error Resume Next

' Connect to specified computer
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
' Display error number and description if applicable
If Err Then ShowError

' Query processor properties
Set colItems = objWMIService.ExecQuery( "Select * from Win32_Processor", , 48 )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
For Each objItem in colItems
strMsg = strMsg & "Processor(s)" & vbCrLf _
& " Name: " _
& Strip( objItem.Name ) & vbCrLf _
& " Manufacturer: " _
& objItem.Manufacturer & vbCrLf _
& " Description: " _
& objItem.Description & vbCrLf _
& " Current Clock Speed: " _
& objItem.CurrentClockSpeed & " MHz" _
& vbCrLf & vbCrLf
Next

' Query memory properties
Set colItems = objWMIService.ExecQuery( "Select * from Win32_LogicalMemoryConfiguration", , 48 )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
For Each objItem in colItems
strMsg = strMsg & "Memory" & vbCrLf _
& " Total Physical Memory: " _
& Int( ( objItem.TotalPhysicalMemory + 1023 ) / 1024 ) _
& " MB" & vbCrLf & vbCrLf
Next

' Query harddisk properties
Set colItems = objWMIService.ExecQuery( "Select * from Win32_DiskDrive", , 48 )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
For Each objItem in colItems
strMsg = strMsg & "Harddisk(s)" & vbCrLf _
& " Manufacturer: " _
& objItem.Manufacturer & vbCrLf _
& " Model: " _
& objItem.Model & vbCrLf _
& " Size: " _
& Int( ( objItem.Size + 536870912 ) / 1073741824 ) _
& " GB" & vbCrLf & vbCrLf
Next

' Query video adapter properties
Set colItems = objWMIService.ExecQuery( "Select * from Win32_VideoController", , 48 )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
For Each objItem in colItems
strMsg = strMsg & "Video" & vbCrLf _
& " Name: " _
& objItem.Name & vbCrLf _
& " Description: " _
& objItem.Description & vbCrLf _
& " Video Processor: " _
& objItem.VideoProcessor & vbCrLf _
& " Adapter RAM: " _
& Int( ( objItem.AdapterRAM + 524288 ) / 1048576 ) _
& " MB" & vbCrLf _
& " Video Mode Description: " _
& objItem.VideoModeDescription & vbCrLf & vbCrLf
Next


' Display results
WScript.Echo strMsg


dim FSobj
set FSobj=CreateObject("Scripting.FileSystemObject")

set outFile= FSobj.CreateTextFile("C:\test\outFile.txt", 2, True)
outFile.write strMsg
outFile.Close

WScript.Echo "Output stored to C:\test\outFile.txt folder."


'Done
WScript.Quit(0)

Sub ShowError()
strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
Err.Description & vbCrLf & vbCrLf
Syntax
End Sub


Sub Syntax()
strMsg = strMsg & vbCrLf _
& "Hardware.vbs, Version 1.11" & vbCrLf _
& "Display basic hardware summary for " _
& "any computer on the network" & vbCrLf & vbCrLf _
& "Usage: CSCRIPT //NOLOGO HARDWARE.VBS " _
& "[ computer_name ]" & vbCrLf & vbCrLf _
& "Where: " & Chr(34) & "computer_name" & Chr(34) _
& " is the optional name of a remote" & vbCrLf _
& " computer (default is local computer " _
& "name)" & vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
& "Created with Microsoft's Scriptomatic tool" & vbCrLf _
& "http://www.microsoft.com/technet/treeview/default.asp" _
& "?url=/technet/scriptcenter/WMImatic.asp" & vbCrLf
WScript.Echo strMsg
WScript.Quit(1)
End Sub


Private Function Strip( strInput )
Do While Left( strInput, 1 ) = " "
strInput = Mid( strInput, 2 )
Loop
Strip = strInput
End Function




'[code/]
FelixM is offline   Reply With Quote
Old May 16th, 2005, 5:58 PM   #2
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Cool, that looks like a lot of work, especially without Intellisense! You could use the .NET framework to write a simple console app to do it though, if the volume and speed of code is a concern. Also, there many more objects exposed to managed code than just through plain WMI and obviously you need SP4 or whatever, and its quite crippled on a default setup for security reasons (I got an ActiveX component can't create object when I tried to run it).
Rory is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:38 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC