Page 2 of 2 <12
Topic Options
#114225 - 2004-03-08 05:16 PM Re: Inventory to DB Script
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I agree to a point. The point where I am wrestling with this is that the WMIQuery() UDF does not handle wildcards (more than one element at a time for say multiple mapped drives) to extract data needed. Am I missing the point? The DB*() UDFs may cover some simplification of this, we should be able to cover this with say a couple of lines. Anyway, I can ponder this one.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#114226 - 2004-03-09 02:32 PM Re: Inventory to DB Script
Andreasfcelie Offline
Fresh Scripter

Registered: 2004-03-08
Posts: 6
I have tried both.
Ik have created an database on the SQL server which I also prefer, I thin k I have troubles with the WMIQuery. I am using windows XP and have tried to use the script locally on my machine where I installed the personal version of SQL Server 2000. I also tried the Access database but also no luck. And how do I use the UDF's? Where to place them, I am not familiar wth this.

Thanx

Top
#114227 - 2004-03-09 02:51 PM Re: Inventory to DB Script
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
First, you want to go to the UDF Forum here on this site and grab the code for WMIQuery and paste it in your script..

BTW, these may come in handy for you..

KiXtart FAQ & How to's

How to use UDFs

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#114228 - 2004-03-09 03:09 PM Re: Inventory to DB Script
Andreasfcelie Offline
Fresh Scripter

Registered: 2004-03-08
Posts: 6
Is there anyone who had a full working script including all of the UDF etc, please.

Thanx

Top
#114229 - 2004-03-09 04:30 PM Re: Inventory to DB Script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
Full working script for what?

The script in the first post is complete.

I can't be that hard to copy and paste some UDFs into a text file. The FAQ Forum has lots of helpful FAQs for this.

You will also most likely adapt the script code to your particular environment, not something we can help with as do not know your environment.


Edited by sealeopard (2004-03-09 04:31 PM)
_________________________
There are two types of vessels, submarines and targets.

Top
#114230 - 2004-03-24 10:47 PM Re: Inventory to DB Script
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: Lincoln, NE
kdyer

I notice you are calling a script called funct.kix. What is this script doing?

Thanks.

tjcarst

Top
#114231 - 2004-03-24 11:11 PM Re: Inventory to DB Script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
They will most likely include the UDFs he's using throughout the code. See the FAQ Forum for details on UDFs.

Edited by sealeopard (2004-04-08 05:55 PM)
_________________________
There are two types of vessels, submarines and targets.

Top
#114232 - 2004-03-25 07:11 AM Re: Inventory to DB Script
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Funct.kix is used to store functions like those of say a VB-Include.

WMIQuery() UDF

You should include the DB*() UDFs instead.

While this version works, the DB*() UDFs will clean up this code a bit more.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#114233 - 2004-04-08 05:46 PM Re: Inventory to DB Script
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: Lincoln, NE
sealeopard - I do realize what UDF's are and use them in my scripts. I do not, however, claim to know enough to write them. Searching the boards for my posts will show my lack of inexperience but also my desire to learn. Please be kind enough to teach me a little so I stop pestering so much. A few words of explanation is all it takes to send me in the right direction.

kdyer - Your patience with those of us not expert in kix is appreciated. Thanks for the follow-up explanation.

tjcarst

Top
#114234 - 2004-04-08 05:56 PM Re: Inventory to DB Script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
Who said anything about writing them? You asked what FUNCT.KIX is and I said that they contain UDFs used in the code. Thus, you'll need to look at the code, identify the UDFs used, copy the UDFs from the UDF Forum into FUNCT.KIX and then run the code.
_________________________
There are two types of vessels, submarines and targets.

Top
#114235 - 2004-04-08 08:23 PM Re: Inventory to DB Script
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: Lincoln, NE
Thanks for the follow up, sealeopard.

tjcarst

Top
#114236 - 2004-08-12 09:14 AM Re: Inventory to DB Script
murk Offline
Lurker

Registered: 2004-08-12
Posts: 1
Radimus which UDF of WMIQuery did you use for the software inventory to access DB?
I get the error message like beneath when i use the WMIQuery that is posted.

ERROR : Error in expression: this type of array not supported in expressions.!
Script: Y:\Netlogon\Tools\test.kix
Line : 2

Top
#205985 - 2012-10-11 01:49 PM Re: Inventory to DB Script [Re: Sealeopard]
GeorgeLittle Offline
Fresh Scripter

Registered: 2011-02-08
Posts: 47
Loc: UK
I have just tried the SQL version of the script and I get an error on line 68 unkown command WMIQuery
Top
#205986 - 2012-10-11 01:58 PM Re: Inventory to DB Script [Re: GeorgeLittle]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22333
Loc: OK
lol. scroll back to the top and read the first line of the first post.
_________________________
!

download KiXnet

Top
#206005 - 2012-10-12 07:27 AM Re: Inventory to DB Script [Re: Lonkero]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11567
Loc: CA
Well not to mention the code and post is about 8 years old too.
Though I suppose it should still work at the level it was left at.

Top
#206028 - 2012-10-16 04:59 PM Re: Inventory to DB Script [Re: NTDOC]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
This is still in use, run as a service on each domain PC

 Code:
Break on
$ = SetOption('wrapateol','on')
$ = SetConsole("hide")
$ = RedirectOutput('c:\logfiles\SQLInv.log', 1)
$InvVer = '2012/05/09 - Production Server'

? 
? $InvVer
? @DATE + '	'+ @TIME

$start = @ticks

	$Make 	=Trim(Split(WMIQuery("Manufacturer","Win32_ComputerSystem"))[0])
	$Model	=Trim(WMIQuery("Model","Win32_ComputerSystem"))
	$SerNo	=WMIQuery("SerialNumber","Win32_BIOS")
		If Len($SerNo) < 2 	
			$SerNo=WMIQuery("SerialNumber","Win32_SystemEnclosure")
			If InStr($serno,"|")
				For Each $Return in Split($serno,"|")
					If Len($Return)<10	$serno=$Return		EndIf
					Next
				EndIf
			EndIf
	$SerNo	=Trim(UCase($SerNo))
	If $serNo < '1'		Quit		EndIf

	$asset	=WMIQuery("SMBIOSAssetTag","Win32_SystemEnclosure")
	If InStr($asset,"|")
		For Each $return in Split($asset,"|")
			If $return	$asset=$return		EndIf
		Next
	EndIf

	$asset	= Join(Split($asset,"|"),'')
	$asset	= Trim(UCase($asset))

	$objWMIService = GetObject("winmgmts:\\.\root\cimv2")
	if $objWMIService and not @error
		$colOperatingSystems = $objWMIService.ExecQuery("Select * From Win32_PerfFormattedData_PerfOS_System")
		if $colOperatingSystems and not @error
 			For Each $objOS in $colOperatingSystems
		 	   $uptime = val($objOS.SystemUpTime) / 60 /60
			Next
		endif
	endif


	$CPUsp	=WMIQuery("CurrentClockSpeed","Win32_Processor")
		Select
			Case Left($CPUsp,3) = "339"		$CPUsp=3400
			Case Left($CPUsp,3) = "319"		$CPUsp=3200
			Case Left($CPUsp,3) = "299"  		$CPUsp=3000
			Case Left($CPUsp,3) = "279"		$CPUsp=2800
			Case Left($CPUsp,3) = "269"		$CPUsp=2600
			Case Left($CPUsp,3) = "239"		$CPUsp=2400
			Case Left($CPUsp,3) = "229"		$CPUsp=2200
			Case Left($CPUsp,3) = "220"		$CPUsp=2200
			Case Left($CPUsp,3) = "199"		$CPUsp=2000
   			Case Left($CPUsp,3) = "186"  		$CPUsp=1860
   			Case Left($CPUsp,3) = "182"  		$CPUsp=1830
			Case Left($CPUsp,3) = "179"		$CPUsp=1800
			Case Left($CPUsp,3) = "169"		$CPUsp=1700
			Case Left($CPUsp,3) = "159"		$CPUsp=1600
			Case Left($CPUsp,3) = "139"		$CPUsp=1400
			Case Left($CPUsp,3) = "106"		$CPUsp=1100
			Case Left($CPUsp,2) = "99"		$CPUsp=1000
			Case Left($CPUsp,2) = "90"		$CPUsp=900
			Case Left($CPUsp,2) = "85"		$CPUsp=850
			Case Left($CPUsp,2) = "70"		$CPUsp=700
			Case Left($CPUsp,2) = "66"		$CPUsp=667
			Case Left($CPUsp,2) = "59"		$CPUsp=600
			Case Left($CPUsp,2) = "49"		$CPUsp=500
			Case Left($CPUsp,2) = "39"		$CPUsp=400
			EndSelect

	$dimms	=Split(WMIQuery("Capacity","Win32_PhysicalMemory"),"|")
		For $a=0 to UBound($dimms)
			$=Execute("$$dimm$a=val($$dimms[$a]) / 1048576")
			$=Execute("$$memory=val($$Memory)+val($$dimm$a)")
		Next

	$nic=0
	Do
		$ip 	= EnumIPInfo($nic,0)
		$snm	= EnumIPInfo($nic,1)
		$NicDesc= EnumIPInfo($nic,2)
		$mygw	= EnumIPInfo($nic,3)
		$nic=Val($nic)+1
	Until InStr($ip,'192.168.') Or InStr($ip,'192.168.24') Or InStr($ip,'192.168.201.') Or Val($nic) > 10
	
	$network = Left($ip,InStrRev($ip,'.'))

	$Mac	=WMIQuery("MACAddress","Win32_NetworkAdapterConfiguration",,"Description",$NicDesc)
	$Mac	=Join(Split($mac,':'),'')
	$Mac	=Join(Split($mac,'|'),'')


If FindProc(@wksta,'MSASCui.exe')
	If KeyExists('HKLM\SOFTWARE\Microsoft\Microsoft Forefront\Client Security\1.0\AM\Signature Updates')
		$AVProgram	= 'Microsoft Forefront Client' 
		$AVEngine	= ReadValue('HKLM\SOFTWARE\Microsoft\Microsoft Forefront\Client Security\1.0\AM\Signature Updates','EngineVersion')
		$AVSignature	= ReadValue('HKLM\SOFTWARE\Microsoft\Microsoft Forefront\Client Security\1.0\AM\Signature Updates','AVSignatureVersion')
	EndIf
EndIf

	$MSOdir	=ReadValue("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\excel.exe","Path")
	$excel	=GetFileVersion("$MSOdir\excel.exe")
	$MSOVer =Split($excel,'.')[0]

	$MSOSPVer = ''

	$assigned = ReadValue("HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters","srvcomment")
	If Left($assigned,2) = '68'
		$assigned = Left(Right(Join(Split(Join(Split($assigned,' '),''),'-'),''),-2),9)
	EndIf

	$ini = 0


$cnstring = "DRIVER={SQL Server};SERVER=SQLServer;UID=Inventory;PWD=password;DATABASE=InvDB"

$cn = CreateObject("ADODB.Connection")
$cmd= CreateObject("ADODB.Command")
$rs = CreateObject("ADODB.RecordSet")

$cn.connectionstring = $cnstring
$cn.open
$cmd.activeconnection = $cn
$rs.cursortype = 3
$rs.locktype = 3
$rs.activecommand = $cmd

$cmdtxt = "select * from dbo._tbl_Main where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt $rs.open ($cmd)			;? 'Error = '+@ERROR+' - '+@SERROR
	If $rs.eof = -1		$rs.addnew	EndIf 

	$rs.fields.item("SerialNumber").value  = $serNo
	$rs.fields.item("ComputerName").value  = @wksta
	$rs.fields.item("AssignedTo").value    = $assigned
	$rs.fields.item("NetworkID").value     = $network
	$rs.fields.item("IPAddress").value     = $ip
	$rs.fields.item("InvDate").value       = @date
	$rs.fields.item("Version").value       = $InvVer
	$rs.fields.item("MacAddr").value       = $Mac
	$rs.fields.item("Uptime").value        = $uptime

$rs.update							;? 'Error = '+@ERROR+' - '+@SERROR
;if not @error
	$nul = WriteValue('HKLM\SOFTWARE\Information Technology\SQLInventory','LastRun',@date,REG_SZ)
;endif
$rs.close

$cmdtxt = "select * from dbo._tbl_OSEnv where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt $rs.open ($cmd)			;? 'Error = '+@ERROR+' - '+@SERROR
	If $rs.eof = -1		$rs.addnew	EndIf 

	$rs.fields.item("SerialNumber").value	= $serNo
	$rs.fields.item("OS").value 		= @ProductType
	$rs.fields.item("OSCSD").value		= @csd
	$rs.fields.item("64bit").value		= @OnWoW64
	$rs.fields.item("AVProgram").value	= $AVProgram
	$rs.fields.item("AVEngine").value	= $AVEngine
	$rs.fields.item("AVSignature").value	= $AVSignature
	$rs.fields.item("MSO").value		= $MSOVer
	$rs.fields.item("MSOSP").value		= $MSOSPVer
$rs.update							? 'Error = '+@ERROR+' - '+@SERROR
$rs.close



$cmdtxt = "select * from dbo._tbl_OrgCodes where OrgCode = '$Asset'"
$cmd.commandtext = $cmdtxt $rs.open ($cmd)			;? 'Error = '+@ERROR+' - '+@SERROR
	$code = IIf($rs.eof = -1,1,0)
$rs.close							;? 'Error = '+@ERROR+' - '+@SERROR



$cmdtxt = "select * from dbo._tbl_Computers where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt $rs.open ($cmd)			;? 'Error = '+@ERROR+' - '+@SERROR
	If $rs.eof = -1
		$rs.addnew 

		$rs.fields.item("SerialNumber").value	= $serNo
		If $code = 1
			$rs.fields.item("Tag").value= $asset	
		Else
			$rs.fields.item("OrgCode").value= $asset
		EndIf
		$rs.fields.item("Make").value		= $Make 	
		$rs.fields.item("Model").value		= $Model	
		$rs.fields.item("CPU").value		= $CPUsp
		$rs.fields.item("FirstInventory").value = @date
		$rs.update					;? 'Error = '+@ERROR+' - '+@SERROR
		;if not @error
			$nul = WriteValue('HKLM\SOFTWARE\Information Technology\SQLInventory','FirstRun',@date,REG_SZ)
		;endif
	Else
		If Val($rs.fields.item("Memory").value) <> $memory
			$rs.fields.item("Memory").value		=  Abs(CDbl(Val($memory)))
			$rs.update				;? 'Error = '+@ERROR+' - '+@SERROR
		EndIf

		If $rs.fields.item("Tag").value < '0' And $code = 1
			$rs.fields.item("Tag").value= $asset	
			$rs.update				;? 'Error = '+@ERROR+' - '+@SERROR
		EndIf

		If $rs.fields.item("OrgCode").value < '0' And $code = 0
			$rs.fields.item("OrgCode").value= $asset
			$rs.update				;? 'Error = '+@ERROR+' - '+@SERROR
		EndIf

		If $rs.fields.item("FirstInventory").value < '0'
			$rs.fields.item("FirstInventory").value = @date
			$rs.update				;? 'Error = '+@ERROR+' - '+@SERROR
		EndIf
	EndIf
$rs.close

; *********************** Monitor Inventory ***************************************
$cmdtxt = "Delete from dbo._tbl_Monitors where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt ? $cmdtxt 
$rs.Open($cmd) 				? 'Mon Del-Open: Error = ' + @ERROR + ' - ' + @SERROR
$rs.close 						? 'Mon Del-Close: Error = ' + @ERROR + ' - ' + @SERROR

$cmdtxt = "select * from dbo._tbl_Monitors where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt $rs.open ($cmd)			;? 'Error = '+@ERROR+' - '+@SERROR
	$wmiColl = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor Where ScreenWidth>'0'")
	For Each $wmiObj in $wmiColl
		$pnpid = $wmiObj.PNPDeviceID
		If $pnpid > 'a'
			If InStr($pnpid,'\')
				$monModel = Split($pnpid,'\')[1]
			Else
				$monModel = 'Unknown'
			EndIf
			$res = CStr($wmiObj.ScreenWidth) + "x" + CStr($wmiObj.ScreenHeight)
			$rs.addnew
			$rs.fields.item("SerialNumber").value		= $Serno 
			$rs.fields.item("MonitorModel").value		= $MonModel 
			$rs.fields.item("Resolution").value		= $res
			$rs.fields.item("InvDate").value		= @date
			$rs.update  ? 'Mon Add-Update: Error = ' + @ERROR + ' - ' + @SERROR
		EndIf
	Next
$rs.close 			? 'Mon Add-Close: Error = ' + @ERROR + ' - ' + @SERROR
$wmiColl=''

; *********************** Memory Inventory ***************************************
; ********  http://msdn.microsoft.com/en-us/library/aa394347(VS.85).aspx  ********
$cmdtxt = "Delete from dbo._tbl_Memory where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt  	? $cmdtxt 
$rs.Open($cmd) 					? 'Mem Del-Open: Error = '+@ERROR+' - '+@SERROR
$rs.close 							? 'Mem Del-Close: Error = '+@ERROR+' - '+@SERROR

$cmdtxt = "select * from dbo._tbl_Memory where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt 	? $cmdtxt 
$rs.open ($cmd)					? 'Mem Add-Open: Error = '+@ERROR+' - '+@SERROR
	$wmiColl = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * FROM Win32_PhysicalMemory")
	For Each $wmiObj in $wmiColl
		$rs.addnew
		$rs.fields.item("SerialNumber").value		= $Serno 
		$rs.fields.item("DeviceLocator").value		= $wmiObj.DeviceLocator 
		$rs.fields.item("Capacity").value		= Abs(CDbl(Val($wmiObj.Capacity))/1024/1024)
		$rs.fields.item("Speed").value			= $wmiObj.Speed
		$rs.fields.item("FormFactor").value		= $wmiObj.FormFactor
		$rs.fields.item("MemoryType").value		= $wmiObj.MemoryType
		$rs.fields.item("InvDate").value		= @date
		$rs.update  ? 'Mem Add-Update: Error = ' + @ERROR + ' - ' + @SERROR
	Next
$rs.close 			? 'Mem Add-Close: Error = '+@ERROR+' - '+@SERROR
$wmiColl=''

; *********************** Disk Drive Inventory ***************************************
; ********  http://msdn.microsoft.com/en-us/library/aa394347(VS.85).aspx  ********
$cmdtxt = "Delete from dbo._tbl_DiskDrive where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt		 ? $cmdtxt
$rs.Open($cmd) 			? 'Disk Del-Open: Error = '+@ERROR+' - '+@SERROR
$rs.close 					? 'Disk Del-Close: Error = '+@ERROR+' - '+@SERROR

$cmdtxt = "select * from dbo._tbl_DiskDrive where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt 	? $cmdtxt
$rs.open ($cmd)					? 'Disk Add-Open: Error = ' + @ERROR + ' - ' + @SERROR
	$wmiColl = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * FROM Win32_DiskDrive where MediaLoaded='-1'")
	For Each $wmiObj in $wmiColl
		$rs.addnew
		$rs.fields.item("SerialNumber").value		= $Serno 
		$rs.fields.item("DriveSize").value		= Round(CDbl($wmiObj.Size)/1000/1000/1000)
		$rs.fields.item("InterfaceType").value		= $wmiObj.InterfaceType
		$rs.fields.item("Model").value			= $wmiObj.Model
		$rs.fields.item("Status").value			= $wmiObj.Status
		$rs.fields.item("InvDate").value		= @date
		$rs.update 			? 'Disk Add-Update: Error = ' + @ERROR + ' - ' + @SERROR
	Next
$rs.close 					? 'Disk Add-Close: Error = ' + @ERROR + ' - ' + @SERROR

; *********************** Software Inventory ***************************************
$cmdtxt = "Delete from dbo._tbl_Software where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt 
$rs.Open($cmd) 			;? 'Error = '+@ERROR+' - '+@SERROR
$rs.close 			;? 'Error = '+@ERROR+' - '+@SERROR

$cmdtxt = "select * from dbo._tbl_Software where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt $rs.open ($cmd)			;? 'Error = '+@ERROR+' - '+@SERROR

$Index = 0	$err = 0	$key = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Do
	$SubKey = EnumKey($Key, $Index)
	If @ERROR = 0
		If Not Left($subkey,'2') = 'KB'
			$DisplayName 	= ReadValue($key+$subKey,'DisplayName')
			$DisplayVersion = ReadValue($key+$subKey,'DisplayVersion')
			$InstallDate 	= ReadValue($key+$subKey,'InstallDate')
			$InstallLocation= ReadValue($key+$subKey,'InstallLocation')
			$Publisher 	= ReadValue($key+$subKey,'Publisher')

			If Not $DisplayName + $DisplayVersion + $InstallDate + $InstallLocation + $Publisher < 'a'	
				$rs.addnew
				$rs.fields.item("SerialNumber").value		= $Serno 
				$rs.fields.item("RegKeyName").value		= $SubKey 
				$rs.fields.item("DisplayName").value		= $DisplayName	
				$rs.fields.item("DisplayVersion").value		= $DisplayVersion	
				$rs.fields.item("InstallDate").value		= $InstallDate
				$rs.fields.item("InstallLocation").value 	= $InstallLocation
				$rs.fields.item("Publisher").value		= $Publisher
				$rs.fields.item("InvDate").value      		= @date
				$rs.update
			EndIf
		EndIf
		$Index = $Index + 1
	Else
		$err = 1
	EndIf
Until $err
$rs.close

; *********************** MSO Sessions Inventory ***************************************
$cmdtxt = "Delete from dbo._tbl_MSOSessions where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt 
$rs.Open($cmd) 			;? 'Error = '+@ERROR+' - '+@SERROR
$rs.close 			;? 'Error = '+@ERROR+' - '+@SERROR

$cmdtxt = "select * from dbo._tbl_MSOSessions where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt $rs.open($cmd) 		;? 'Error = '+@ERROR+' - '+@SERROR

	$getobj = GetObject("winmgmts:{impersonationLevel=impersonate}!//.")
	$backup = $getobj.ExecQuery("Select * From Win32_NTLogEvent Where Logfile='osession' and eventcode='7000'") ;and message like 'id: 2%'
	
	For Each $event in $backup
		$ec = $event.EventIdentifier
		$time = $event.TimeGenerated
		$year = SubStr($time, 1, 4) $Hour = SubStr($time, 9, 2)
		$month = SubStr($time, 5, 2) $min = SubStr($time, 11, 2)
		$day = SubStr($time, 7, 2) $sec = SubStr($time, 13, 2)
		$message = $event.message
		$user= $event.user
		$Msg = Split($message, ",")
	
		$rs.addnew
		$rs.fields.item("SerialNumber").value = $Serno 
		$rs.fields.item("EventID").value = $ec 
		$rs.fields.item("UserID").value = Join(Split($user,'fdhc\'),'')	
		$rs.fields.item("Date").value = $year +'/'+ $month +'/'+ $day	
		$rs.fields.item("Time").value = $hour +':'+ $min +':'+ $sec	
		$rs.fields.item("ID").value = Trim(Split($msg[0], ':')[1])
		$rs.fields.item("AppName").value = Trim(Split($msg[1], ':')[1])
		$rs.fields.item("AppVersion").value = Trim(Split($msg[2], ':')[1])
		$rs.fields.item("InvDate").value = @date
	$rs.update
	Next
	
$rs.close


; *********************** Sprint Card Inventory ***************************************
If Exist('c:\logfiles\sprintcard.txt')
	$SprintData = Readfile('c:\logfiles\sprintcard.txt')
	For Each $line in $SprintData
		Select
			Case InStr($line, 'Manufacturer') 	$man = Trim(SubStr($line, InStr($line, ':') + 1))
			Case InStr($line, 'Model') 			$mod = Trim(SubStr($line, InStr($line, ':') + 1))
			Case InStr($line, 'Revision') 		$rev = Trim(SubStr($line, InStr($line, ':') + 1))
			Case InStr($line, 'ESN') 				$esn = Trim(SubStr($line, InStr($line, ':') + 1))
			Case InStr($line, 'Date') 				$date= Trim(SubStr($line, InStr($line, ':') + 1))
		EndSelect
	Next
	If $esn
		$cmdtxt = "select * from dbo._tbl_SprintCards where SerNo = '$SerNo'"
		$cmd.commandtext = $cmdtxt
		$rs.open($cmd) 		$err = @serror
			If $rs.eof = -1 	$rs.addnew 		EndIf 
			$rs.fields.item("SerNo").value = $serno
			$rs.fields.item("ESN").value = $esn
			$rs.fields.item("Manufacturer").value = $man
			$rs.fields.item("Model").value = $mod
			$rs.fields.item("Revision").value = $rev
			$rs.fields.item("InvDate").value = $date
			$rs.update			$err = @serror	
		$rs.close
	EndIf
EndIf

; *********************** Bitlocker Inventory ***************************************
Shell 'cmd /c echo '+@DATE + '> c:\logfiles\bitlocker.txt'
Shell 'cmd /c manage-bde.exe -status >> c:\logfiles\bitlocker.txt'
Shell 'cmd /c manage-bde.exe -protectors -get c: >> c:\logfiles\bitlocker.txt'
If Exist('c:\logfiles\bitlocker.txt')
	$BitData = Readfile('c:\logfiles\bitlocker.txt')
	For $count = 0 to UBound($bitdata) - 1
		$line = $bitdata[$count]
		Select
			Case InStr($line, '[OS Volume]') $Vol = Trim(SubStr($bitdata[$count - 1], InStr($bitdata[$count - 1], ':') - 1, 2))
			Case InStr($line, 'Bitlocker Version') $Ver = Trim(SubStr($line, InStr($line, ':') + 1))
			Case InStr($line, 'Conversion Status') $Con = Trim(SubStr($line, InStr($line, ':') + 1))
			Case InStr($line, 'Encryption Method') $Enc = Trim(SubStr($line, InStr($line, ':') + 1))
			Case InStr($line, 'Key Protectors:') 	
							Do
								$count = $count +1
								If Trim($bitdata[$count]) <> 'Data Recovery Agent (Certificate Based)' And Not InStr($tpm,Trim($bitdata[$count]))
									$TPM = $TPM + "," + Trim($bitdata[$count])
								EndIf
							Until Trim($bitdata[$count + 1]) = ''
							$TPM = SubStr($TPM,2) 
			Case InStr($line, 'External Key file name') $Key = Trim($bitdata[$count + 1])
		EndSelect
	Next
	$data = $vol +', '+$ver + ', ' +$con + ', ' +$enc + ', ' +$tpm + ', ' +$key + ', ' +@DATE
	Shell 'cmd /c echo "' + $data + '" >> c:\logfiles\bitlocker.txt'
	
	If $vol
		$cmdtxt = "select * from dbo._tbl_bitlocker where SerialNumber = '$SerNo'"
		$cmd.commandtext = $cmdtxt
		$rs.open($cmd) $err = @serror
			Shell 'cmd /c echo open: ' + $err + '>> c:\logfiles\bitlocker.txt'
			If $rs.eof = -1 	$rs.addnew 		EndIf 
			$rs.fields.item("SerialNumber").value = $serno
			$rs.fields.item("Volume").value = $vol
			$rs.fields.item("Version").value = $ver
			$rs.fields.item("Conversion").value = $Con
			$rs.fields.item("Encryption").value = $enc
			$rs.fields.item("Protection").value = $TPM
			$rs.fields.item("Keys").value = $key
			$rs.fields.item("InvDate").value = @date
			$rs.update $err = @serror	
			Shell 'cmd /c echo update: ' + $err + '>> c:\logfiles\bitlocker.txt'
		$rs.close
	EndIf
EndIf

;**************************************************************************************************

Function ReadFile($file)
	Dim $lf, $f, $_, $t
	$lf = Chr(10)
	$f = FreeFileHandle
	$_ = Open($f, $file, 2)
	If @error Exit 1 EndIf
	Do $t = $t + $lf + ReadLine($f) Until @error
	$_ = Close($f)
	$ReadFile = Split(SubStr($t, 2), $lf)
EndFunction

Function WMIQuery($what,$from,optional $computer,optional $where, optional $x)
	Dim $strQuery, $objEnumerator, $value
	If Not $computer	$computer="@WKSTA"	EndIf
	$strQuery = "Select $what From $from"
	If $where And $x	$strQuery = $strQuery + " Where $where = '$x'"		EndIf
	$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//$computer")
	$objEnumerator = $SystemSet.ExecQuery($strQuery)
	For Each $objInstance in $objEnumerator
		If @Error = 0 And $objInstance <> ""
			$=Execute("$$value = $$objInstance.$what")
			$WMIQuery="$value"+"|"+"$WMIQuery"
			EndIf
		Next
	$WMIQuery=Left($WMIQuery,Len($WMIQuery)-1)
	Exit @error
	EndFunction

Function GroupMembers($target, optional $full)
	Dim $group, $member, $name, $temp

	$group = GetObject('WinNT://' + $target)
	If @error 	Exit 1		EndIf
	For Each $member in $group.members
		Select
			Case $member.class = "user"
				$temp = $temp +Chr(13)+ $member.name
			Case $member.class = "group"
				If $full
					For Each $name in $member.members
						$temp = $temp +Chr(13)+ $name.name
					Next
				Else
					$temp = $temp +Chr(13)+ $member.name
				EndIf
		EndSelect
	Next
	$GroupMembers = Split(SubStr($temp,2),Chr(13))
EndFunction

Function FilterArray($arr_Source, $arr_Filter)
	For $item = 0 to UBound($arr_Source)
		If Not AScan($arr_Filter,$arr_Source[$item]) = -1  Or Left($arr_Source[$item],5) = 'S-1-5'
			$arr_Source[$item] = ''
		Else
			$arr_Source[$item] = $arr_Source[$item]+ '||'
		EndIf
	Next
	$filterArray = Split(Join($arr_source,''),'||')
EndFunction

;Function looks for a specific running process and returns the PID of it
Function FindPROC($COMPUTER,$PROC,optional $terminate)
	Dim $GetObject, $Select
	$GetObject="winmgmts:{impersonationLevel=impersonate}!//$COMPUTER"
	$select="select * from Win32_Process where Name='$PROC'"
	For Each $Process in GetObject("$GetObject").ExecQuery("$select")
		If $terminate		$Process.Terminate	EndIf
		$FindPROC=$Process.ProcessId
		Next
	EndFunction


_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 2 of 2 <12


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 191 anonymous users online.
Newest Members
thequeen, ameliaryan, shalomsalami, dkdssdk, Vroon
17639 Registered Users

Generated in 0.04 seconds in which 0.013 seconds were spent on a total of 14 queries. Zlib compression enabled.

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