;*** CREATE AN ACCESS DATABASE WITH A TABLE NAMED COMPUTERS****
;*** CREATE THE FOLLOWING FIELDS: COMPUTERNAME, ... etc
DIM $DBpath
;******************************** CONFIGURE DATABASE PATH********************************************************************************************
$DBpath = "\\server\...\IT-Inventar.mdb"
CLS
AT (1,1) "Asset Audit Script Processing..."
SLEEP 2
CLS
BREAK ON CLS
;********************************* DECLARE VARIABLES ************************************************************************************************
DIM $CNstring, $CMDtxt, $cn, $cmd, $rs
DIM $ModifyDateTime, $computername, $username, $osname
DIM $OSType, $ServicePack
DIM $InstallDate, $LastBoottime
DIM $OSSerial, $SysManufacturer, $SysModel, $SysSerial
DIM $CPUDescription, $CPUSpeed
DIM $SysMemory
DIM $VideoCard, $VideoRes, $ptr, $NicCard, $nic, $CDKey
DIM $Privilegien, $IP, $MAC, $Uhrzeit, $MonitorDescription, $MonHersteller, $CDKey
If Exist("$DBpath") = 0
? "IT Assets Database Not Found. Aborting..."
Sleep 1
Goto end
EndIf
;***************************** CONFIGURE DATABASE CONNECTION STRING *********************************************************************************
$CNstring="Driver={Microsoft Access Driver (*.mdb)}; DBQ=$DBpath"
$CMDtxt = "select * from COMPUTERS where computername = '@WKSTA'"
$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
$cmd.commandtext = $CMDtxt $rs.Open ($cmd)
;**************************** COLLECT WORKSTAION ASSET INFORMATION **********************************************************************************
$MAC = @ADDRESS
$Uhrzeit = @time
$Privilegien = @PRIV
$IP = @IPADDRESS0
$ModifyDateTime = @DATE + " " + @TIME
$computername = @WKSTA
$username = @userid
$osname = WMIQuery("Caption","Win32_OperatingSystem")
$OSType = WMIQuery("BuildType","Win32_OperatingSystem")
$ServicePack = WMIQuery("CSDVersion","Win32_OperatingSystem")
$InstallDate = WMIQuery("InstallDate","Win32_OperatingSystem")
$LastBoottime = @date
$OSSerial = WMIQuery("SerialNumber","Win32_OperatingSystem")
$SysManufacturer = WMIQuery("Manufacturer","Win32_ComputerSystem")
$SysModel = WMIQuery("Model","Win32_ComputerSystem")
$SysSerial = WMIQuery("SerialNumber","Win32_BIOS")
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_Processor ")
For Each $wmiObj in $wmiColl
$CPUDescription = $wmiObj.Name
Next
Sleep 5
$CPUSpeed = WMIQuery("CurrentClockSpeed","Win32_Processor")
;********************************* SYSMemory UDF - Glen Barnas ******************************************************************************************
;;FUNCTION Memory()
;;
;;AUTHOR Glenn Barnas
;;
;;ACTION Returns the amount of Available Physical RAM in a local or remote system
;;
;;SYNTAX Memory([system])
;;
;;VERSION 4.0
;;
;
Function Memory(Optional $_System, Optional $_fGB)
Dim $_MemMap ; Physical Memory Map
Dim $_Start, $_End, $_Step ; for/next start & step increment
Dim $_Sum ; running sum of memory from map
Dim $_Idx ; temporary index var
Dim $_iMem ; Memory region size index
Dim $_Error ; Error placeholder
; Insure $_System has "\\System\" format if it is specified
If $_System <> ''
$_System = '\\' + Join(Split($_System, '\'), '', 3) + '\'
EndIf
; Get the memory value from the registry
$_Idx = $_System + 'HKLM\hardware\resourcemap\system resources\physical memory'
$_MemMap = ReadValue($_Idx, '.Translated')
; Check for invalid read and Return
If Len($_MemMap) = 0 Or @ERROR
$Memory = 0 ; return 0 Mbytes
$_Error = IIf(@ERROR, @ERROR, 13) ; Return "Data is Invalid" if no error but data is blank
Exit $_Error
EndIf
; determine system's O/S type based on architecture
$_Idx = $_System + 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
If ReadValue($_Idx, 'PROCESSOR_ARCHITECTURE') = 'AMD64'
$_Step = 40 ; Define the step size based on the O/S Architecture
$_Start = 33 ; Offset where memory descriptor blocks start
$_Sum = 0.0 ; no unreported base memory to account for
$_iMem = 10 ; Memory size index
Else
$_Step = 32 ; Define the step size based on the O/S Architecture
$_Start = 41 ; Offset where memory descriptor blocks start
$_Sum = 737280.0 ; account for base memory not identified in memory map - x86 only
$_iMem = 2 ; Memory size index
EndIf
$_End = Len($_MemMap) - 8
For $_Idx = $_Start to $_End Step $_Step
$_Block = SubStr($_MemMap, $_Idx, $_Step)
If SubStr($_Block, $_iMem, 1) > 3
$_Sum = $_Sum + CDbl(Val('&' + SubStr($_Block, $_Step - 1, 2))) * 4294967296.0
+ CDbl(Val('&' + SubStr($_Block, $_Step - 3, 2))) * 16777216.0
+ CDbl(Val('&' + SubStr($_Block, $_Step - 5, 2))) * 65536.0
+ CDbl(Val('&' + SubStr($_Block, $_Step - 7, 2))) * 256.0
+ CDbl(Val('&' + SubStr($_Block, $_Step - 9, 2)))
Else
$_Sum = $_Sum + CDbl(Val('&' + SubStr($_Block, $_Step - 1, 2))) * 16777216.0
+ CDbl(Val('&' + SubStr($_Block, $_Step - 3, 2))) * 65536.0
+ CDbl(Val('&' + SubStr($_Block, $_Step - 5, 2))) * 256.0
+ CDbl(Val('&' + SubStr($_Block, $_Step - 7, 2)))
EndIf
Next
; Sum is in Bytes - return the total as megabytes
$Memory = CInt($_Sum / 1048576)
Exit 0
EndFunction
;*******************Continue COLLECT WORKSTAION ASSET INFORMATION************************************************************************************
$SysMemory = val(WMIQuery("TotalPhysicalMemory","Win32_LogicalMemoryConfiguration"))/1024
If $SysMemory = 0
$SysMemory = Memory()
EndIf
$VideoCard = WMIQuery("Description","Win32_VideoController")
$VideoRes = WMIQuery("VideoModeDescription","Win32_VideoController")
for each $nic in Split(WMIQuery("ProductName","Win32_NetworkAdapter"),"|")
if instr($nic,"miniport")=0 and instr($nic,"RAS")=0 and instr($nic,"Parallel")=0
$NicCard = $nic
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")
For Each $wmiObj in $wmiColl
$MonitorDescription = $wmiObj.Name
$MonHersteller = $wmiObj.MonitorManufacturer
next
FUNCTION WMIQuery($what,$where,)
dim $strQuery, $objEnumerator, $value
$strQuery = "Select $what From $where"
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//@WKSTA")
$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
;************************************Get CD Key *****************************************************************************************************
Function GetCDKey($sDigitalProductID)
Dim $aiKeyChars[24],$bProductKey[15],$ilByte,$i,$sCDKey,$nCur
$aiKeyChars = Split('B,C,D,F,G,H,J,K,M,P,Q,R,T,V,W,X,Y,2,3,4,6,7,8,9',',')
For $i = 0 To 14
$bProductKey[$i] = Val("&"+SubStr($sDigitalProductID,$i*2+105,2))
Next
$sCDKey = ""
For $ilByte = 24 To 0 Step -1
$nCur = 0
For $i=14 To 0 Step -1
$nCur = $nCur * 256 | $bProductKey[$i]
$bProductKey[$i] = Int($nCur / 24)
$nCur = $nCur Mod 24
Next
$sCDKey = $aiKeyChars[$nCur] + $sCDKey
If $ilByte Mod 5 = 0 And $ilByte <> 0 $sCDKey = "-" + $sCDKey EndIf
Next
$GetCDKey = $sCDKey
EndFunction
$CDKey = GetCDKey(1)
;********************************* ADD RECORDS TO THE DATABASE **************************************************************************************
If $rs.eof = -1 ; addnew is only needed if a record for this workstation was not found.
$rs.addnew
EndIf
$rs.fields.item("MonHersteller").value = $MonHersteller
$rs.fields.item("MonitorDescription").value = $MonitorDescription
$rs.fields.item("IP").value = $IP
$rs.fields.item("Uhrzeit").value = $Uhrzeit
$rs.fields.item("MAC").value = $MAC
$rs.fields.item("PRIVILEGIEN").value = $Privilegien
$rs.fields.item("COMPUTERNAME").value = $computername
$rs.fields.item("OSNAME").value = $osname
$rs.fields.item("OSTYPE").value = $OSType
$rs.fields.item("SERVICEPACK").value = $ServicePack
$rs.fields.item("INSTALLDATE").value = $InstallDate
$rs.fields.item("LASTBOOTTIME").value = $LastBoottime
$rs.fields.item("OSSERIAL").value = $OSSerial
$rs.fields.item("SYSMANUFACTURER").value = $SysManufacturer
$rs.fields.item("SYSMODEL").value = $SysModel
$rs.fields.item("SYSSERIAL").value = $SysSerial
$rs.fields.item("CPUDESCRIPTION").value = $CPUDescription
$rs.fields.item("CPUSPEED").value = $CPUSpeed
$rs.fields.item("SYSMEMORY").value = $SysMemory
$rs.fields.item("VIDEOCARD").value = $VideoCard
$rs.fields.item("VIDEORES").value = $VideoRes
$rs.fields.item("NICCARD").value = $NicCard
$rs.fields.item("MODIFYDATETIME").value = $ModifyDateTime
$rs.fields.item("USERNAME").value = $Username
$rs.fields.item("CDKey").value = $CDKey
$rs.update
$rs.Close