Page 1 of 1 1
Topic Options
#149745 - 2005-10-12 11:26 AM Hardware inventory script malfunction
yellowdog Offline
Starting to like KiXtart

Registered: 2005-06-14
Posts: 102
Hi,

I downloaded the script script_149.kix(Add Computer Info to Registry) from the AdminScriptEditor.com web site in order to extract S/N, Model, construcror ....
This script is working fine with windows 2000 and 2003 operating system. But with NT4 OS (I have installed WMINT4.EXE on NT4 machines)the S/N, model and manufacturer are blanked in the report and that's the main information I want to extract fom computers.


Is there any reason that the report is blank or does it exist an other script that could solve the problem.

Thanks

Here is the source of the script.
;===================================
;**** Last Modified on 8/6/02 at 11:58:59 AM by WVHETRICK ****
;===================================

Break on
; the default skip is 6
$Skip = 6
$Count = $skip
$Count2 = 1

$Answer = MessageBox("Do you want to manually update one at a time?","How do you want to update?",4)
If $Answer = 6
$RC = single()
Exit
EndIf

For Each $machine in netview("@LDOMAIN")

? "$MACHINE"

$Count = $Count + 1
$computer = $machine
$Comp = ""
$Model= ""
$Sernum =""
$Cpu = ""
$Mem = ""
$Computer2 = "\\"+$computer
ReDim $MEM2,$DIMM


;Shell ''%comspec% /c ping -n 2 "$Machine" | find /i "ttl" >nul 2>nul''
;If NOT @ERROR

$VERSION = ReadValue ($Computer2 + "\HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS NT\CURRENTVERSION","CURRENTVERSION")
$WMICORE = ReadValue ($Computer2 + "\HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WBEM","Build")
If $VERSION = "4.0" AND @ERROR <> 0 AND $WMICORE <> "1085.0005"
"Updating WMI"
$RC = UpdateProg(" c:\wmint4.exe /s","$computer")
EndIf

If KeyExist($Computer2 + "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ProductOptions")
$REG = ReadValue ($Computer2 + "\HKEY_LOCAL_MACHINE\SOFTWARE\CWOPA\MACHINE","SerialNumber")
If $REG = ""

$Sernum = Rtrim(WMIQuery("SerialNumber","Win32_BIOS"))
$SERNUM = CHECKREG($SERNUM,"SerialNumber")
$Comp = Rtrim(WMIQuery("Manufacturer","Win32_ComputerSystem"))
$Comp = CHECKREG($COMP,"MANUFACTURER")
$Model = Rtrim(WMIQuery("Model","Win32_ComputerSystem"))
$Model = CHECKREG($MODEL,"MODEL")
$CPU = Rtrim(WMIQuery("CurrentClockSpeed","Win32_Processor"))
$CPU = checkREG($CPU,"CurrentClockSpeed")
$Mem = Val(WMIQuery("TotalPhysicalMemory","Win32_LogicalMemoryConfiguration"))/1024
$MEM = CHECKREG($MEM,"TotalPhysicalMemory")
$smbios = Rtrim(WMIQuery("SMBIOSBIOSVersion","Win32_BIOS"))
$Smbiosdate = Rtrim(WMIQuery("Version","Win32_BIOS"))
$Modem = Rtrim(WMIQuery("Description","Win32_POTSModem"))
$Mem2 = Val(WMIQuery("TotalPhysicalMemory","Win32_LogicalMemoryConfiguration"))/1024
For Each $dimm in Split(WMIQuery("Capacity","Win32_PhysicalMemory"),"|")
$MEM2 = "" + $MEM2 + "|" + Ucase(Val($dimm) / 1048576)
Next
$x = loginfo("c:\COMINFO.txt","@DATE @TIME,$count,$Machine,$Comp,$Model,$Sernum,$Cpu Mhz,$Mem MB,$MEM2 MB,$SMBIOS,$SMBIOSDATE,$MODEM")
$count2 = $count2 + 1
"....DONE at @TIME"

EndIf
EndIf
;EndIf

ut

Next

Exit 1

Function mapdrive($drive, $unc, optional $persistence)
Dim $mount,$subkey, $regvalue, $retcode, $errorcode
If NOT VarType($persistence)
$persistence=0
EndIf
If $persistence
$persistence=1
EndIf
; If @INWIN=2
; $persistence=0
; EndIf
$drive=Ucase($drive)
$mount=$drive+'':''
$mapdrive=0
; check for a valid drive letter
If $drive>''C'' AND $drive<''Z''
; check for incorrent persistent connections
$subkey=$HKCU+''\Network\''+$drive
If KeyExist($subkey)
$regvalue=Lcase(ReadValue($subkey,''RemotePath''))
If $regvalue<>Lcase(Trim($unc)) OR $persistence=0
Use $mount /delete /persistent
$retcode=DelKey($subkey)
EndIf
EndIf
; check if the UNC path actually exists
If Exist($unc)
; delete an already existing mount
If Exist($mount+''\nul'')
If $VERBOSE
$retcode=displaytext(''Deleting existing drive mapping for drive ''+$mount)
EndIf
Use $mount /delete /persistent
$retcode=err(''Cannot delete existing drive mapping for drive ''+$mount)
EndIf
; map the drive to the UNC path
If NOT Exist($mount+''\nul'')
If @INWIN=2 AND InStr($unc,''\\''+@WKSTA+''\'')
;Windows 9x cannot map to its own shares
Else
$retcode=displaytext(''Mounting drive letter ''+$mount+'' to ''+$unc)
If $persistence=1
Use $mount $unc /persistent
$errorcode=@ERROR
Else
Use $mount $unc
$errorcode=@ERROR
EndIf
EndIf

; display some important error codes
If $errorcode
Select
Case $errorcode=85
; drive is already mapped
$retcode=warning(''Drive letter ''+$mount+'' is already mounted to ''+$unc)
Case $errorcode=1202
; error is generated under Win9x if persistent connection is already listed in registry
$retcode=warning(''Drive letter ''+$mount+'' is already mounted persistently to ''+$unc)
Case $errorcode=2250
$retcode=warning(''Drive letter ''+$mount+'' is already mounted to ''+$unc)
Case 1
$retcode=err(''Cannot mount drive letter ''+$mount+'' to ''+$unc)
EndSelect
EndIf
Else
$retcode=warning(''Drive letter ''+$mount+'' is already mounted'')
EndIf
Else
$retcode=warning(''Drive share ''+$unc+'' is not available'')
EndIf
Else
$retcode=warning(Ucase($drive)+'':\ is an invalid drive mapping'')
EndIf
$mapdrive=@error
EndFunction


Function UpdateProg($Command2,$Computer)
Use J: /DELETE
$RC = MAPDRIVE("J","\\$COMPUTER\C$")
If @ERROR = 0
Copy "C:\WMINT4.EXE" "J:"
$runner = "c:\SC.EXE \\" + $Computer + " start Schedule "
Shell $runner
$filetime = @TIME
$MINUUT = Val(SubStr($filetime,4,2))
$UUR = Val(SubStr($filetime,1,2))
If $Minuut > 44
$Uur = $Uur + 1
$Minuut = $Minuut - 45
Else
$Minuut = $Minuut + 15
EndIf
$FILETIME = "$UUR:$MINUUT:00"
$Command = "AT \\" + $Computer + " "
Shell $command + $FILETIME + $COMMAND2
Use J: /DELETE

Else
"FILE NOT COPIED "
EndIf

EndFunction

Function Single()

;For single machines make sure you rem out the For Each AND unrem the Six below.
? "Machine name? " Gets $machine
While $machine <> "Exit"

$computer = $machine
$Comp = ""
$Model= ""
$Sernum =""
$Cpu = ""
$Mem = ""
$Computer2 = "\\"+$computer

$VERSION = ReadValue ($Computer2 + "\HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS NT\CURRENTVERSION","CURRENTVERSION")
$WMICORE = ReadValue ($Computer2 + "\HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WBEM","Build")
If $VERSION = "4.0" AND @ERROR <> 0 AND $WMICORE <> "1085.0005"
"Updating WMI"
$RC = UpdateProg(" c:\wmint4.exe /s","$computer")
EndIf

Shell '%comspec% /c ping -n 2 "$Machine" | find /i "ttl" >nul 2>nul'
If NOT @ERROR
ReDim $MEM2,$DIMM
"$Count, "
$Sernum = Rtrim(WMIQuery("SerialNumber","Win32_BIOS"))
$SERNUM = CHECKREG($SERNUM,"SerialNumber")
"A, "
$Comp = Rtrim(WMIQuery("Manufacturer","Win32_ComputerSystem"))
$Comp = CHECKREG($COMP,"MANUFACTURER")
"B, "
$Model = Rtrim(WMIQuery("Model","Win32_ComputerSystem"))
$Model = CHECKREG($MODEL,"MODEL")
"C, "
$CPU = Rtrim(WMIQuery("CurrentClockSpeed","Win32_Processor"))
$CPU = checkREG($CPU,"CurrentClockSpeed")
"D, "
$Mem = Val(WMIQuery("TotalPhysicalMemory","Win32_LogicalMemoryConfiguration"))/1024
$MEM = CHECKREG($MEM,"TotalPhysicalMemory")
"E, "
$smbios = Rtrim(WMIQuery("SMBIOSBIOSVersion","Win32_BIOS"))
"F, "
$Smbiosdate = Rtrim(WMIQuery("Version","Win32_BIOS"))
"G, "
$Modem = Rtrim(WMIQuery("Description","Win32_POTSModem"))
"H, "
$Mem2 = Val(WMIQuery("TotalPhysicalMemory","Win32_LogicalMemoryConfiguration"))/1024
For Each $dimm in Split(WMIQuery("Capacity","Win32_PhysicalMemory"),"|")
$MEM2 = "" + $MEM2 + "|" + Ucase(Val($dimm) / 1048576)
Next
"End."
$x = loginfo("c:\COMINFO.txt","@DATE @TIME,$count,$Machine,$Comp,$Model,$Sernum,$Cpu Mhz,$Mem MB,$MEM2 MB,$SMBIOS,$SMBIOSDATE,$MODEM")
Else
? "Cannot find Computer"
EndIf

? "Machine name? "
Gets $machine
Loop
Exit

EndFunction
;Used to make login script log files.
;Example LogInfo("\\server\log$\VERSION.LOG","@DATE @TIME,@WKSTA,@USERID,$Macver,$regver,$engver")
Function LOGINFO($FILE,$STRING)
$junk = ReDirectOutput($file)
$string ?
$junk = ReDirectOutput("")
EndFunction

Function CHECKREG($VALUE,$WHERE)
$REG = ReadValue ($Computer2 + "\HKEY_LOCAL_MACHINE\SOFTWARE\CWOPA\MACHINE", "$WHERE")
If $value = " " OR Len($Value) = 0
$Checkreg = $reg
Else
If NOT KeyExist($Computer2 + "\HKEY_LOCAL_MACHINE\SOFTWARE\CWOPA\MACHINE")
$ReturnCode = AddKey($Computer2 + "\HKEY_LOCAL_MACHINE\SOFTWARE\CWOPA\MACHINE")
EndIf
$X = WriteValue ($Computer2 + "\HKEY_LOCAL_MACHINE\SOFTWARE\CWOPA\MACHINE", "$WHERE","$value","REG_SZ")
$CHECKREG = $VALUE
EndIf

Return
EndFunction

Function WMIQuery($what,$where,)
Dim $strQuery, $objEnumerator, $value
$strQuery = "Select $what From $where"
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//$computer")
If VarType($systemSet) <> 9 AND @error <> 0 Exit(@error) EndIf
$objEnumerator = $SystemSet.ExecQuery($strQuery)
For Each $objInstance in $objEnumerator
;If @Error = 0 AND $objInstance <> ""
$junk=Execute("$$value = $$objInstance.$what")
$WMIQuery="$value"+"|"+"$WMIQuery"
;EndIf
Next

$WMIQuery=Left($WMIQuery,Len($WMIQuery)-1)
$Systemset = nothing
Exit @error
EndFunction

Function netview(optional $domain)
Dim $array[255]
Dim $ReDim $ReDim = 255
Dim $i $i = 0
Dim $j $j = 0
Dim $tempfile $tempfile = "%temp%\netview2.tmp"
If $domain
$domain = "/domain:$domain"
EndIf
If Exist("$tempfile")
Del "$tempfile"
EndIf
Shell '%comspec% /c net view $domain >"$tempfile"'
If @error = 0
If Open(10,$tempfile) = 0
For $j = 1 to $Skip
$line = ReadLine(10) ; skip headings
Next
While @error = 0
$array[$i] = Rtrim(SubStr($line,3,InStr($line," ")-1))
$i=$i+1
If $i = $ReDim
$ReDim=$ReDim*2
ReDim preserve $array[$ReDim]
EndIf
$line = ReadLine(10)
Loop
$=Close(10)
Del "$tempfile"
If $i
ReDim preserve $array[$i-4]
$netview = $array
Exit @error
EndIf
EndIf
EndIf
$netview = 0
Exit @error
EndFunction

Top
#149746 - 2005-10-12 01:26 PM Re: Hardware inventory script malfunction
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Some questions:

-1 Are these all the same systems? Some manufacturers do not use these fields so it gives a blank value.
-2 You say WMI is installed, is the service also started?
-3 When you install a NT4 machine with 2K or even XP does it return something then or are the fields still blank?

BTW: A small tip, please use the code tags when posting code so the formatting gets preserved and its more readable.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#149747 - 2005-10-12 06:48 PM Re: Hardware inventory script malfunction
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
My guess without testing it is that WMI on NT4 does not support the information you're trying to return.

Just because you have WMI installed does not mean the OS supports the call. There are WMI calls that are specific to every OS. i.e. There are many calls in 2003 that NT/2000/XP do not understand, there are calls for XP that NT/2000 do not understand.

I'm not saying that NT4 does not, but you would need to try and track down and run some of your own WMI test scripts, and/or read some WMI documentation to see if the call is supported on NT4 to know for sure.
 

Top
#149748 - 2005-10-13 11:17 AM Re: Hardware inventory script malfunction
yellowdog Offline
Starting to like KiXtart

Registered: 2005-06-14
Posts: 102
Hi,
1-we get IBM and DELL machines in our park
2-the WMI service is installed and started
3-when I install a W2K OS on a former machine where NT4 was installed, the information about S/N, Model and manufacturer are fairly extracted (it's not blanked).
Are the NT4 WMI object different from W2K, in that case what are the variable names to extract.

Thanks for the answer.

Top
#149749 - 2005-10-13 01:35 PM Re: Hardware inventory script malfunction
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
is the user local admin when running the script?
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#149750 - 2005-10-13 02:21 PM Re: Hardware inventory script malfunction
yellowdog Offline
Starting to like KiXtart

Registered: 2005-06-14
Posts: 102
The script is launched from a workstation with domain administrator privileges.
The script analyses all the machines from the domain.

Top
#149751 - 2005-10-13 02:38 PM Re: Hardware inventory script malfunction
yellowdog Offline
Starting to like KiXtart

Registered: 2005-06-14
Posts: 102
MART,
Have a look to my answers and comment it if you can...

Top
#149752 - 2005-10-13 03:00 PM Re: Hardware inventory script malfunction
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Well, I'm not such a WMI guru but like Doc said the WMI calls could be different in NT4, 2K, XP or 2K3. Don't know.

If it returns something when not on NT4 looks like this is the case.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#149753 - 2005-10-13 03:30 PM Re: Hardware inventory script malfunction
yellowdog Offline
Starting to like KiXtart

Registered: 2005-06-14
Posts: 102
If this is the case, is it just a matter of variable names or it is not possible to extract those data from a workstation?
Top
#149754 - 2005-10-13 04:04 PM Re: Hardware inventory script malfunction
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Changing the names of the values to be retrieved could work if the OS supports it and you should know the ones to use. I do not know the names to use, this is something that can probably be found at Microsoft.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#149755 - 2005-10-14 01:47 AM Re: Hardware inventory script malfunction
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Try running this code directly while logged onto the NT4 Computer in question. According to the WMI docs it should support it as long as the Mfg filled it in.


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_computersystem.asp

http://msdn.microsoft.com/library/defaul...emenclosure.asp

Both say:
Quote:

Requires Windows "Longhorn", Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0 SP4 and later.




Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')

Dim $strComputer, $objWMIService, $colItems, $objItem
$strComputer = "."
$objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

For Each $objItem in $colItems
"Manufacturer: " + $objItem.Manufacturer ?
"MFG Model: " + $objItem.Model ?
Next

$colItems = $objWMIService.ExecQuery("Select * from Win32_BIOS where PrimaryBIOS = true", , 48 )
For Each $objItem in $colItems
"Serial: " + $objItem.SerialNumber ?
Next

$colItems = $objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")
For Each $objItem in $colItems
"Enclosure Model: " + $objItem.Model ?
Next

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1607 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.065 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org