Dontbyteme
IS-IT--Management
The VBScript I created is supposed to ask what PC a person wants info on then go get that info, put it in a txt file that it has saved to the users c:\users\%username%\documents folder and then ask the person if they want to view that txt file. After the person clicks on Yes, it's supposed to open that txt file. But the script does not expand environment variables like %username%. However the scripting host Shell interface does but when I try to use it, I get an error message when I click on 'Yes' (to open the saved file) on Line 69 that says "Object doesn't support this property or method". Error code is 800A01B6 Char 3. Can you tell me a better way to do this please or how I can fix this so it will work? Thank you, here is my code:
Code:
Option Explicit
Dim objGroup, objFile, objSMBIOS, objItem, objWMIService
Dim strComputer, wmi, oTS, colSMBIOS, IPConfigSet, IPConfig, colItems
Dim objShell
Dim FSO, f
strComputer = Inputbox ("Enter the Computer name you want info on")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
MsgBox "This will take between 5 - 10 mins, so please be patient." & " " & _
"You will receive another message when scanning is complete." & VbCrLf & "Thank you."
'Gives user the option to view requested information (part 1 or 2)
Set objShell = CreateObject("WScript.Shell")
'File name for remote system results
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
Set f = fso.CreateTextFile("c:\users\" _
& createobject("wscript.shell").expandenvironmentstrings("%username%") & "\Documents" & strComputer & ".txt")
'On Error Resume Next
'Query network PC's for information
Set objGroup = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
f.WriteLine "Today is:" & FormatDateTime(Now,0)
f.WriteLine "Computer:" & strComputer
'Find serial number
Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
f.WriteLine "Serial Number: " & objSMBIOS.SerialNumber
Next
'Find MAC & IP
Set IPConfigSet = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=True")
For Each IPConfig in IPConfigSet
f.WriteLine "IP Address: " & Join(IPConfig.IPAddress,"|")
f.WriteLine "MAC Address: " & IPConfig.MACAddress
Next
'Query system to installed KB's
f.WriteLine
f.WriteLine "INSTALLED HOTFIXES"
f.WriteLine
Set colItems = objWMIService.ExecQuery("Select * from Win32_QuickFixEngineering")
For Each objItem in colItems
f.WriteLine "" & objItem.HotFixID
Next
'Print out list of installed software
f.WriteLine
f.WriteLine "INSTALLED SOFTWARE"
f.WriteLine
'Query system for installed software
Set colItems = objWMIService.ExecQuery("Select * from Win32_Product")
For Each objItem in colItems
f.WriteLine "Caption: " & objItem.Caption
f.WriteLine "Version: " & objItem.Version
f.WriteLine
Next