Page 1 of 5 12345>
Topic Options
#129513 - 2004-11-15 01:59 PM Asset Inventory to Access Database
Shaun_Hill Offline
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

Top
#129514 - 2004-11-15 02:10 PM Re: Asset Inventory to Access Database
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Smells like the server isn't available at logon ... maybe there is a mapped drive behind this ??
_________________________



Top
#129515 - 2004-11-15 02:15 PM Re: Asset Inventory to Access Database
Shaun_Hill Offline
Getting the hang of it

Registered: 2004-11-15
Posts: 50
Loc: JHB, South Africa
No. The database and path are accessible! the script runs beutifully if I drag the .kix file on kix32.exe. 100% no problems. Only when I'm logging on to the domain does it not find/hold the path. I dont understand why not.
Top
#129516 - 2004-11-15 02:23 PM Re: Asset Inventory to Access Database
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
What symptoms indicate that the script can not find the DB file? I do not see any logging in your script that would document what exactly the problem is. Please add some additional conditionals as well as check @error and @serror frequently and log a description of the check, the values of variables, and the result to a file. This way you can review all the nasty details of the script execution.

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#129517 - 2004-11-15 02:30 PM Re: Asset Inventory to Access Database
Shaun_Hill Offline
Getting the hang of it

Registered: 2004-11-15
Posts: 50
Loc: JHB, South Africa
mmmm... and im so not in the mood for debugging today. Thanks I will add some error checking. Thought maybe this is a common problem that is well documented.
Top
#129518 - 2004-11-15 02:31 PM Re: Asset Inventory to Access Database
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol.
well documented common problem?
hehee...
_________________________
!

download KiXnet

Top
#129519 - 2004-11-15 02:49 PM Re: Asset Inventory to Access Database
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Are you even sure the script is executing during logon? Is this an XP client? If so, could the XP fast logon optimization be causing you grief?

Windows XP Professional Fast Logon Optimization
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#129520 - 2004-11-15 02:56 PM Re: Asset Inventory to Access Database
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... you say it runs outside of the logon context. when you do run it after logon, are you running all the same scripts that would run at logon, or just this one? This does not look like your entire logon script so you may have some var scope issues if called from another script.

There are a few things that don't sit right.

$DBpath = "\\SERVERNAME\FOLDER\FOLDER\ITAssets.mdb"
is not right.

$DBpath = "\\SERVERNAME\SHARE\FOLDER\ITAssets.mdb"
is more like it.

You should not put vars in quotes!
If Exist("$DBpath") = 0

If Exist($DBpath) = 0

and don't use GOTO!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#129521 - 2004-11-15 02:59 PM Re: Asset Inventory to Access Database
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I think he is CALLing that script and his CALL is assuming the correct folder and is failing to find the script.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#129522 - 2004-11-15 05:47 PM Re: Asset Inventory to Access Database
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
That would go back to the proper logging of script execution. His log should be recording if the script to be called has been found or not.

Code:
Function CallScript($ScriptFile)

dim $ScriptFile
WriteLog("Calling " + $ScriptFile)
If Exist($ScriptFile)
WriteLog("Executing " + $ScriptFile)
Call $ScriptFile
WriteLog ("Returned from " + $ScriptFile)
Else
WriteLog ("File Not Found: " + $ScriptFile )
Endif
Endfunction

Function WriteLog($text)
dim $RC, $text, $LogFile, $Filehandle
$Filehandle = 1
$LogFile = "%temp%\logon.log"
$RC=Writeline ($Filehandle, "@Date @Time - $Text" + Chr(13) + Chr(10))
if $RC<0
$RC=Close ($Filehandle)
$RC=Open ($Filehandle, $LogFile, 5)
Select
Case $RC=-1
$RC=MessageBox ("Invalid file name ($LogFile) specified for log file.","Logon Script Error",48)
Case $RC=0
WriteLog ($Text)
Case $RC=>0
$RC=MessageBox ("Error($RC) while attempting to open log file ($LogFile).","Logon Script Error",48)
Endselect
Endif
EndFunction



And i know that the code has not yet been cleaned up and that some vars are in strings.


Edited by Howard Bullock (2004-11-15 05:50 PM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#129523 - 2004-11-16 06:37 AM Re: Asset Inventory to Access Database
Shaun_Hill Offline
Getting the hang of it

Registered: 2004-11-15
Posts: 50
Loc: JHB, South Africa
Morning Gentlmen,

Well I've resolved the problem! Script is executing properly now and I never changed a thing in the script.
I had a primary script which contains a number of calls to various scripts. ie
if ingroup("screensaver")
blahblah
call wadawada.kix
endif
if ingroup("othergroups")
blahblah
etc etc
endif

There must have been about 10 different ones and the Asset script was the last in the list to be called if member of that group. All i did was make it the first called script!
How on earth does that make a difference???? Im bedazzled and confused! Maybe you could shed some light on this matter! as i said in the beggining, the script always worked as is. just had the problem when it was called from the during logon process. It definately was calling the script! Thanks for all your help. Later ill post my Symantec Corporate edition scriot for you all! its very powerful and is an awesome compliment to SAV

Top
#129524 - 2004-11-16 07:10 AM Re: Asset Inventory to Access Database
Shaun_Hill Offline
Getting the hang of it

Registered: 2004-11-15
Posts: 50
Loc: JHB, South Africa
I think Les was correct. It has something to do with global variables! only thing that makes sense to me... Could probably have also got it to work if I had shell that particular script
Top
#129525 - 2004-11-17 03:36 AM Re: Asset Inventory to Access Database
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
You might want to consider converting the sub-scripts to UDFs that are getting CALLed as this will make it easier to pass parameters. You might also want to take a look at the DB...() UDFs, which offer a couple of canned database functions.
_________________________
There are two types of vessels, submarines and targets.

Top
#129526 - 2004-11-17 02:40 PM Re: Asset Inventory to Access Database
geemeetheway Offline
Lurker

Registered: 2004-11-16
Posts: 1
it is possible to post the last version of that script. Please
Top
#129527 - 2004-11-24 09:28 AM Re: Asset Inventory to Access Database
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Looking at your script, there needs to be some logic for say more than one printer..

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

Top
#129528 - 2004-12-01 08:36 AM Re: Asset Inventory to Access Database
Shaun_Hill Offline
Getting the hang of it

Registered: 2004-11-15
Posts: 50
Loc: JHB, South Africa
I have about 20 printers installed and it gets them all!
I've noticed that the software is not 100%
Actually it only records software that was installed via windows installer... eg SQL server is not listed even though I have it installed. Probably have to get the software list from registry

Top
#129529 - 2004-12-02 10:27 AM Re: Asset Inventory to Access Database
Shaun_Hill Offline
Getting the hang of it

Registered: 2004-11-15
Posts: 50
Loc: JHB, South Africa
Just to inform you all that may be using this script. The software section has a small little problem in that the software i.e. WMI32_Product only returns software that was installed using windows installer! Thus it is not 100% accurate. I suggest on the software section to pull the data from the registry! maybe sombody has a neat script to do this already and it can be incorporated into this existing script.

Also, to write the data to SQL database just change the connection string and wambam thank you mam!

$CNstring = "DRIVER={SQL Server};SERVER=MTCDEV1;UID=assetsdb;PWD=assetsdb;DATABASE=Assets"



Top
#129530 - 2004-12-02 07:00 PM Re: Asset Inventory to Access Database
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
I have a fairly extensive script here that you could modify or review the code to grab what you want from it.

My Computer Info - for Help Desk use PART 3
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=116475

Top
#129531 - 2004-12-04 02:08 PM Re: Asset Inventory to Access Database
Shaun_Hill Offline
Getting the hang of it

Registered: 2004-11-15
Posts: 50
Loc: JHB, South Africa
Updated Script: Writes to SQL DB, GET ALL SOFTWARE BUT IN TWO DB.FIELDS

;*** CREATE A SQL 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, APPLICATIONS2, SERVICES, USERNAME,

CLS
AT (1,1) "Your IT Department is conducting an Asset Audit of this Workstation."
AT (2,1) "Please wait while the information is collected."

;**** 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
DIM $Applications, $Services, $Applications2, $InstalledSoftwareArray
DIM $element, $Software



function ASort($array, OPTIONAL $order)
; sort order: 0 = ascending, 1 = decending
dim $index, $x, $y, $tmp, $changed
$Asort=$array
$order=0+$order
do
$changed=0
for $index = 0 to ubound($asort)-1
$x=$asort[$index]
$y=$asort[$index+1]
if ($x > $y and 1-$order) or ($x < $y and $order)
$tmp=$x
$asort[$index]=$y
$asort[$index+1]=$tmp
$changed=1
endif
next
until $changed=0
endfunction

FUNCTION GetSoftwareList (OPTIONAL $sort)
DIM $arrayindex, $enumindex, $component, $dn, $regkey, $swarray[200]
$regkey='HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall'
$enumindex=0
$arrayindex=0
:gisloop
$component=EnumKey($regkey, $enumindex)
IF NOT @error
IF NOT (Len($component)=7 AND Left($component,1)='Q')
; above line excludes hotfixes from listing
IF NOT (0+ReadValue($regkey+'\'+$component,'SystemComponent'))
$dn=ReadValue($regkey+'\'+$component,'DisplayName')
IF $dn
$swarray[$arrayindex]=$dn
$arrayindex=$arrayindex+1
ENDIF
ENDIF
$enumindex=$enumindex+1
GOTO gisloop
ENDIF
ENDIF
REDIM PRESERVE $swarray[$arrayindex]
IF $sort
$getsoftwarelist=asort($swarray)
ELSE
$getsoftwarelist=$swarray
ENDIF
ENDFUNCTION ; - GetSoftwareList -


;*** CONFIGURE DATABASE CONNECTION STRING ***
$CNstring = "DRIVER={SQL Server};SERVER=MTCDEV1;UID=assetsdb;PWD=assetsdb;DATABASE=Assets"
$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")
$Applications = WMIQuery("Caption","Win32_Product")
$InstalledSoftwareArray=GetSoftwareList(1)
$Software = Join($InstalledSoftwareArray,"|")
$Services = WMIQuery("Caption","Win32_Service")
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

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("APPLICATIONS2").value = $Software
$rs.fields.item("SERVICES").value = $Services
$rs.fields.item("USERNAME").value = $Username

$rs.update

$rs.Close


Top
#129532 - 2004-12-04 02:39 PM Re: Asset Inventory to Access Database
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Please post code within CODE tags.

You should separate out functions and regular code from each other and not intermingle it.

It's also very bad programing preactices to use GOTO at all, you might want to gt rid of it.

Finally, the inventory will not detect if hardware changes on an already inventoried system.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 5 12345>


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

Who's Online
0 registered and 327 anonymous users online.
Newest Members
Jojo67, MaikSimon, kvn317, kixtarts2025, SERoyalty
17873 Registered Users

Generated in 0.07 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

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