Shaun_Hill
Getting the hang of it
Registered: 2004-11-15
Posts: 50
Loc: JHB, South Africa
|
Hi Guys,
I wonder if you geniuses can help me. I am having a problem with a script that i've been setting up. I'm capturing information from workstations and then writing it to an access database. The script works brilliantly and is fast accept that when I run it as a logon script it cant find my database path which is in a variable! It works well if i run it straight. I've included the script seeing as i have never contributed anything before I might as well now... But does anybody know what the reason for this is? I'm not exacly a pro but I can usually manage!
Herewith the script, enjoy:
;*** CREATE AN ACCESS DATABASE WITH A TABLE NAMED COMPUTERS**** ;*** CREATE THE FOLLOWING FIELDS: COMPUTERNAME, DOMAIN, SYSNAME ;*** OSNAME, MANUFACTURER, OSVERSION, OSBUILD, OSTYPE, LANGUAGE ;*** SERVICEPACK, BOOTDEVICE, SYSTEMDEVICE, WINDIR, SYSDIR, INSTALLDATE ;*** LASTBOOTTIME, OSSERIAL, SYSMANUFACTURER, SYSMODEL, SYSSERIAL, SYSBIOSVER ;*** SYSBIOSDATE, CPUMANUFACTURER, CPUDESCRIPTION, CPUSPEED, MAXCLOCK, FAMILY ;*** STEPPING, DEVICEID, SYSMEMORY, DISKNAMES, VOLNAMES, DISKNAMES, DISKSIZE ;*** FILESYS, FREESPACE, VIDEOCARD, VIDEORES, PRINTERS, NICCARD, MODIFYDATETIME ;*** APPLICATIONS, SERVICES, USERNAME
DIM $DBpath ;*** CONFIGURE DATABASE PATH*** $DBpath = "\\SERVERNAME\FOLDER\FOLDER\ITAssets.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, $domain, $sysname, $osname DIM $Manufacturer, $OSVersion, $OSBuild, $OSType, $Language, $ServicePack DIM $BootDevice, $SystemDevice, $WinDir, $SysDir, $InstallDate, $LastBoottime DIM $OSSerial, $SysManufacturer, $SysModel, $SysSerial, $SystemBIOSVer, $SysBIOSDate DIM $CPUManufacturer, $CPUDescription, $CPUSpeed, $MaxClock, $Family, $Stepping DIM $DeviceID, $SysMemory, $DiskNames, $VolNames, $DiskSize DIM $FileSys, $FreeSpace, $VideoCard, $VideoRes, $Modem, $Printers, $ptr, $NicCard, $nic
If Exist("$DBpath") = 0 ? "IT Assets Database Not Found. Aborting..." Sleep 3 Goto end EndIf
;*** CONFIGURE DATABASE CONNECTION STRING *** $CNstring = "provider=microsoft.jet.oledb.4.0;data source=$DBpath;persist security info=false" $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
$ModifyDateTime = @DATE + " " + @TIME $computername = @WKSTA $username = @userid $domain = @domain $sysname = WMIQuery("CSName","Win32_OperatingSystem") $osname = WMIQuery("Caption","Win32_OperatingSystem") $Manufacturer = WMIQuery("Manufacturer","Win32_OperatingSystem") $OSVersion = WMIQuery("Version","Win32_OperatingSystem") $OSBuild = WMIQuery("BuildNumber","Win32_OperatingSystem") $OSType = WMIQuery("BuildType","Win32_OperatingSystem") $Language = WMIQuery("OSLanguage","Win32_OperatingSystem") $ServicePack = WMIQuery("CSDVersion","Win32_OperatingSystem") $BootDevice = WMIQuery("BootDevice","Win32_OperatingSystem") $SystemDevice = WMIQuery("SystemDevice","Win32_OperatingSystem") $WinDir = WMIQuery("WindowsDirectory","Win32_OperatingSystem") $SysDir = WMIQuery("SystemDirectory","Win32_OperatingSystem") $InstallDate = WMIQuery("InstallDate","Win32_OperatingSystem") $LastBoottime = WMIQuery("LastBootupTime","Win32_OperatingSystem") $OSSerial = WMIQuery("SerialNumber","Win32_OperatingSystem") $SysManufacturer = WMIQuery("Manufacturer","Win32_ComputerSystem") $SysModel = WMIQuery("Model","Win32_ComputerSystem") $SysSerial = WMIQuery("SerialNumber","Win32_BIOS") $SystemBIOSVer = WMIQuery("SMBIOSBIOSVersion","Win32_BIOS") $SysBIOSDate = WMIQuery("Version","Win32_BIOS") $CPUManufacturer = WMIQuery("manufacturer","Win32_Processor") $CPUDescription = WMIQuery("description","Win32_Processor") $CPUSpeed = WMIQuery("CurrentClockSpeed","Win32_Processor") $MaxClock = WMIQuery("maxclockspeed","Win32_Processor") $Family = WMIQuery("family","Win32_Processor") $Stepping = WMIQuery("stepping","Win32_Processor") $DeviceID = WMIQuery("deviceid","Win32_Processor") $SysMemory = val(WMIQuery("TotalPhysicalMemory","Win32_LogicalMemoryConfiguration"))/1024 $DiskNames = WMIQuery("name","Win32_LogicalDisk") $VolNames = WMIQuery("volumename","Win32_LogicalDisk") $DiskSize = WMIQuery("size","Win32_LogicalDisk") $FileSys = WMIQuery("filesystem","Win32_LogicalDisk") $FreeSpace = WMIQuery("freespace","Win32_LogicalDisk") $VideoCard = WMIQuery("Description","Win32_VideoController") $VideoRes = WMIQuery("VideoModeDescription","Win32_VideoController") $Modem = WMIQuery("Description","Win32_POTSModem") $Printers = WMIQuery("Name","Win32_printer") 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 $Applications = WMIQuery("Caption","Win32_Product") $Services = WMIQuery("Caption","Win32_Service")
endif 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
;*** 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("COMPUTERNAME").value = $computername $rs.fields.item("DOMAIN").value = $domain $rs.fields.item("SYSNAME").value = $Sysname $rs.fields.item("OSNAME").value = $osname $rs.fields.item("MANUFACTURER").value = $Manufacturer $rs.fields.item("OSVERSION").value = $OSVersion $rs.fields.item("OSBUILD").value = $OSBuild $rs.fields.item("OSTYPE").value = $OSType $rs.fields.item("LANGUAGE").value = $Language $rs.fields.item("SERVICEPACK").value = $ServicePack $rs.fields.item("BOOTDEVICE").value = $BootDevice $rs.fields.item("SYSTEMDEVICE").value = $SystemDevice $rs.fields.item("WINDIR").value = $WinDir $rs.fields.item("SYSDIR").value = $SysDir $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("SYSBIOSVER").value = $SystemBIOSVer $rs.fields.item("SYSBIOSDATE").value = $SysBIOSDate $rs.fields.item("CPUMANUFACTURER").value = $CPUManufacturer $rs.fields.item("CPUDESCRIPTION").value = $CPUDescription $rs.fields.item("CPUSPEED").value = $CPUSpeed $rs.fields.item("MAXCLOCK").value = $MaxClock $rs.fields.item("FAMILY").value = $Family $rs.fields.item("STEPPING").value = $Stepping $rs.fields.item("DEVICEID").value = $DeviceID $rs.fields.item("SYSMEMORY").value = $SysMemory $rs.fields.item("DISKNAMES").value = $DiskNames $rs.fields.item("VOLNAMES").value = $VolNames $rs.fields.item("DISKNAMES").value = $DiskNames $rs.fields.item("DISKSIZE").value = $DiskSize $rs.fields.item("FILESYS").value = $FileSys $rs.fields.item("FREESPACE").value = $FreeSpace $rs.fields.item("VIDEOCARD").value = $VideoCard $rs.fields.item("VIDEORES").value = $VideoRes $rs.fields.item("PRINTERS").value = $Printers $rs.fields.item("NICCARD").value = $NicCard $rs.fields.item("MODIFYDATETIME").value = $ModifyDateTime $rs.fields.item("APPLICATIONS").value = $Applications $rs.fields.item("SERVICES").value = $Services $rs.fields.item("USERNAME").value = $Username
$rs.update
$rs.Close
|