VBscript retrieve info

D

derek

Hello~~

I am using XP Embedded Feature Pack 2007 on a Intel 915GME platform. I
am having some difficulties on retrieving data by VBscript. Please
kindly give me any advice if you have any thought.

Someone gave me a VBscript file, and he wishes to run and retrieve
some data from the XPe PC.
However, I think the VBscript is running well, and it generated an
output file as expected, but the file is empty, it just couldn't
retrieve any data from the XPe target PC.
The VBscript can retrieve data in the output file from my laptop and
also the same XPe target PC but with XP Pro.

I have added a lot of related components but without any success.
- Windows Script Engine
- Windows Management Instrumentation Technologies (WMI related macro
component)
- Visual Basic 6.0 Runtime Library
- Internet Explorer
- ....etc

The original script content is as below.
Could anyone please help me and let me know what else I can try ?
Any help and suggestion is appreciated !!

==========================================
On Error Resume Next

''''''''''''''''''''''
' DEBUG: TIMER START
StartTime = Timer
''''''''''''''''''''''

' ** Startup variables
Set colNamedArguments = WScript.Arguments.Named

' ** Set target computer as local host
strComputer = "."
CreateLog=0 ' Set this to 1 to activate logging

Set WshShell = CreateObject("wscript.Shell")
Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
\"
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")
strDigitalProductId="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion
\DigitalProductId"
strXPKey=GetKey(WshShell.RegRead(strDigitalProductId))


' ** Functions

Function LogWrite(sMessage)
If CreateLog <> 0 Then
objLogFile.WriteLine(Now & " - " & sMessage)
End If
End Function


' ** Log file object
If CreateLog <> 0 Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("Inventory.log",8,True)
End If


LogWrite("Application start")


Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

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


' ** Verify if WMI connection was established
' ** Normally the WMI connection will timeout after 48 seconds
If objWMIService Is Nothing Then
LogWrite("[ERROR] Could not connect to WMI provder.")
LogWrite("Application stopped." & vbNewLine)
WScript.Quit
Else
LogWrite("Connected to WMI provider.")
End IF


LogWrite("Retrieving WMI information..")


' ** WMI Queries
Set colOSSettings = objWMIService.ExecQuery("SELECT * FROM
Win32_OperatingSystem")
Set colSettings = objWMIService.ExecQuery("SELECT * FROM
Win32_ComputerSystem")
Set colProc = objWMIService.ExecQuery("SELECT * FROM Win32_Processor")
Set colDisks = objWMIService.ExecQuery("SELECT * FROM
Win32_LogicalDisk")
Set colBIOS = objWMIService.ExecQuery("Select SerialNumber from
Win32_BIOS")

' ** Get information from WMI queries
For Each objOperatingSystem in colOSSettings
OSName = objOperatingSystem.Caption
OSVersion = objOperatingSystem.Version
ServicePack = objOperatingSystem.ServicePackMajorVersion & "." &
objOperatingSystem.ServicePackMinorVersion
AvPhysMem = objOperatingSystem.FreePhysicalMemory
Next


For Each objComputer in colSettings
SystemName = objComputer.Name
Manufacturer = objComputer.Manufacturer
Model = objComputer.Model
TotPhysMem = objComputer.TotalPhysicalMemory
Next


For Each objProcessor in colProc
SystemType = objProcessor.Architecture
SystemSpeed = objProcessor.currentclockspeed
Next


For each objDisk in colDisks
' ** Get the row that contains the C: drive
If InStr("C:",objDisk.DeviceID) then
Cdrive = objDisk.DeviceID
Cspace = objDisk.FreeSpace
If CSpace = "" Then
CSpace = "0"
End If
CSize = objDisk.Size
If CSize = "" Then
CSize = "0"
End If
end if

' ** Get the row that contains the D: drive
If InStr("D:", objDisk.DeviceId) then
Ddrive = objDisk.DeviceID
Dspace = objDisk.FreeSpace
If isNull(DSpace) = true then
DSpace = "0"
End If
DSize = objDisk.Size
If isNull(DSize) = true then
DSize = "0"
End If
end if

Next

For each objBIOS in colBIOS
SerialNumber = objBIOS.SerialNumber
Next



LogWrite("Done Retrieving WMI information..")
LogWrite("Writing output file")



Set objFSO = CreateObject("Scripting.FileSystemObject")

' ** Open destination file
Set objTextFile = objFSO.OpenTextFile(SystemName & "_Inventory.csv",
8, True)


' ** Write selected information in csv format
objTextFile.WriteLine(SystemName & "," & _
Trim(SerialNumber) & "," & _
strXPKey & "," & _
Trim(Manufacturer) & "," & _
Trim(Model) & "," & _
OSName & "," & _
OSVersion & "," & _
ServicePack & "," & _
Round(FormatNumber(TotPhysMem / 1024 / 1024, 2), 0) & " MB" & "," &
_
SystemSpeed & " mhz" & "," & _
CDrive & " " & _
Round(CSpace / 1024 / 1024, 0) & " MB" & "," & _
DDrive & " " & _
Round(DSpace / 1024 / 1024, 0) & " MB")

objTextFile.Close

LogWrite("Done writing output file")

''''''''''''''''''''''''
' DEBUG: TIMER STOP
EndTime = Timer
'''''''''''''''''''''''''


LogWrite("Time to run: " & round(EndTime-StartTime,2) & " seconds" &
vbNewLine)
objLogFile.Close








Function GetKey(rpk)

Const rpkOffset=52:i=28
szPossibleChars="BCDFGHJKMPQRTVWXY2346789"

Do 'Rep1
dwAccumulator=0 : j=14
Do
dwAccumulator=dwAccumulator*256
dwAccumulator=rpk(j+rpkOffset)+dwAccumulator
rpk(j+rpkOffset)=(dwAccumulator\24) and 255
dwAccumulator=dwAccumulator Mod 24
j=j-1
Loop While j>=0
i=i-1 : szProductKey=mid(szPossibleChars,dwAccumulator+1,1)
&szProductKey
if (((29-i) Mod 6)=0) and (i<>-1) then
i=i-1 : szProductKey="-"&szProductKey
End If
Loop While i>=0 'Goto Rep1

GetKey=szProductKey
End Function
====================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top