#106554 - 2003-11-03 05:26 PM
Inventory Management
|
Bob Deerinwater
Starting to like KiXtart
Registered: 2002-05-05
Posts: 101
Loc: Covina California
|
[Moderator (Sealeopard): Moved thread form 'Scripts' to 'General' forum due to lack of script in body]
I am trying to set up a real time inventory of all of my workstations. I have currently installed wmi on nt and 9x machines. My question is what would be the easiest way to havethis happen. My thought was to have the logon script e-mail a txt or csv file to our sql server and have sql create the data base and then have it accessibly via our intranet site. Does not seem that difficult but my sql guy keeps giving me the run around. Has any one else done this or have suggestions. [ 03. November 2003, 22:24: Message edited by: sealeopard ]
|
|
Top
|
|
|
|
#106555 - 2003-11-03 05:42 PM
Re: Inventory Management
|
Breaker
Hey THIS is FUN
   
Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
|
Bob,
I have my logon script write a hardware inventory gleaned from WMI to an Access db, but have as yet never bothered with creating any kind of interface, web-based or otherwise, with which to query this info. I just look at the tables.
Here's the script - if you're interested I'll mail you a blank copy of the DB.
[Edit] Sorry about the long lines!! [/Edit]
code:
;Script to write info to database at logon - uses WMI and ADO for connection and collection ;Created Feb 2002 by Neil Moran
;First, set variables for the connection to the database and other general options $x=SetOption("WrapAtEOL","On") $DATABASE = "\\server\share\logon.mdb" $DSN = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=$DATABASE" $WMI = "WINMGMTS:{IMPERSONATIONLEVEL=IMPERSONATE}!//@WKSTA" $WMI_Test = GetObject($WMI) If @ERROR <> 0 Goto WMI_Error Endif $WMI_Test = 0
;Create SQL statements to check/write/update database $SQL_USERS = "SELECT * FROM TBL_USERS WHERE USERNAME='@USERID';" $SQL_COMPUTERS = "SELECT * FROM TBL_COMPUTERS WHERE WORKSTATION='@WKSTA';"
;Create database objects $Connection = CreateObject("ADODB.Connection") ;? "Create Connection object " + @ERROR + ": " + @SERROR Get $x $Command = CreateObject("ADODB.Command") ;? "Create Command object " + @ERROR + ": " + @SERROR Get $x $Recordset = CreateObject("ADODB.Recordset") ;? "Create recordset object " + @ERROR + ": " + @SERROR Get $x ;Set properties of DB objects and open connection to database $Connection.ConnectionString = $DSN $Connection.Open() ;? "Open connection " + @ERROR + ": " + @SERROR Get $x If @ERROR <> 0 Goto ADO_Error Endif $Command.ActiveConnection = $Connection $Recordset.CursorType = 3 $Recordset.LockType = 3 $Recordset.ActiveCommand = $Command
;Check for User details first $Command.CommandText = $SQL_USERS $Recordset.Open($Command) ;? "Open user recordset " + @ERROR + ": " + @SERROR Get $x ;Create new record if none exists to update If $Recordset.RecordCount < 1 $Recordset.AddNew ;? "Add new user record " + @ERROR + ": " + @SERROR Get $x Endif
If InGroup("\\" + @WKSTA + "\Administrators") $IsLocalAdmin = "True" Else $IsLocalAdmin = "False" Endif
;Write user values into database field by field $Recordset.Fields("UserName").Value = @USERID $Recordset.Fields("FullName").Value = @FULLNAME $Recordset.Fields("Workstation").Value = @WKSTA $Recordset.Fields("IsLocalAdmin").Value = $IsLocalAdmin $Recordset.Fields("PrivilegeLevel").Value = @PRIV $Recordset.Fields("HomeDrive").Value = @HOMESHR $Recordset.Fields("LastUpdate").Value = @DATE + " " + @TIME $Recordset.Fields("Description").Value = @COMMENT
;Update the new record and close the recordset object $Recordset.Update ;? "Update users " + @ERROR + ": " + @SERROR Get $x $UserIdentifier = $Recordset.Fields("UserID").Value $Recordset.Close() ;? "Close user recordset " + @ERROR + ": " + @SERROR Get $x
;Check Computer details next - refresh $Recordset object with new query $Command.CommandText = $SQL_COMPUTERS $Recordset.Open($Command) ;? "Open computer recordset " + @ERROR + ": " + @SERROR Get $x
;Check for existing record to update If $Recordset.RecordCount < 1 $Recordset.AddNew ;? "Add new computer record " + @ERROR + ": " + @SERROR Get $x Endif
$SystemManufacturer = WMIQuery("Manufacturer","Win32_ComputerSystem") $SystemModel = WMIQuery("Model","Win32_ComputerSystem") $SerialNo = WMIQuery("SerialNumber","Win32_BIOS") $PhysicalMemory = val(WMIQuery("TotalPhysicalMemory","Win32_LogicalMemoryConfiguration"))/1024 $ProcessorSpeed = WMIQuery("CurrentClockSpeed","Win32_Processor") $PagefileSpace = val(WMIQuery("TotalPageFileSpace","Win32_LogicalMemoryConfiguration"))/1024 $VidMode = WMIQuery("VideoModeDescription","Win32_VideoController") $VidCard = WMIQuery("VideoProcessor","Win32_VideoController") If Len($VidCard) = 0 $VidCard = WMIQuery("Description","Win32_VideoController") Endif $DiskController = WMIQuery("InterfaceType","Win32_DiskDrive") $Modem = WMIQuery("Description","Win32_POTSModem")
;Write values into table $Recordset.Fields("Workstation").Value = @WKSTA $Recordset.Fields("NTDomain").Value = @DOMAIN $Recordset.Fields("SystemManufacturer").Value = $SystemManufacturer $Recordset.Fields("SystemModel").Value = $SystemModel $Recordset.Fields("SerialNo").Value = $SerialNo $Recordset.Fields("OS").Value = @PRODUCTTYPE $Recordset.Fields("ServicePack").Value = @CSD $Recordset.Fields("PhysicalMemory").Value = $PhysicalMemory $Recordset.Fields("ProcessorSpeed").Value = $ProcessorSpeed $Recordset.Fields("PagefileSpace").Value = $PagefileSpace $Recordset.Fields("VidMode").Value = $VidMode $Recordset.Fields("VidCard").Value = $VidCard $Recordset.Fields("Modem").Value = $Modem $Recordset.Fields("LoggedOnUser").Value = @USERID $Recordset.Fields("LastUpdate").Value = @DATE + " " + @TIME
;Update and close recordset object $Recordset.Update ;? "Update computer record " + @ERROR + ": " + @SERROR Get $x $PCIdentifier = $Recordset.Fields("PCID").Value ;? "PC ID number is " + $PCIdentifier $Recordset.Close() ;? "Close computer recordset " + @ERROR + ": " + @SERROR Get $x
;Slightly different process for update of Disks table $DiskSet = GetObject($WMI).ExecQuery("SELECT * FROM WIN32_LOGICALDISK WHERE DRIVETYPE=3") ;? "Get DiskSet info from WMI " + @ERROR + ": " + @SERROR Get $x For Each $Disk In $DiskSet $Name = $Disk.Name ; ? "Disk name is " + $Name $FreeSpace = $Disk.FreeSpace ; ? "Free space is " + $FreeSpace $TotalSpace = $Disk.Size ; ? "Total size is " + $TotalSpace $Format = $Disk.FileSystem ; ? "Disk format is " + $Format $SQL_DISKS = "SELECT * FROM TBL_DISKS WHERE COMPID=" + $PCIDENTIFIER + " AND DRIVENAME='" + $NAME + "';" $Command.CommandText = $SQL_DISKS $Recordset.Open($Command) ; ? "Open disks recordset " + @ERROR + ": " + @SERROR Get $x If $Recordset.RecordCount < 1 $Recordset.AddNew ; ? "Add new disk record " + @ERROR + ": " + @SERROR Get $x Endif $Recordset.Fields("compID").Value = $PCIdentifier $Recordset.Fields("DriveName").Value = $Name $Recordset.Fields("FreeSpace").Value = $FreeSpace $Recordset.Fields("TotalSpace").Value = $TotalSpace $Recordset.Fields("Format").Value = $Format $Recordset.Update ; ? "Update disk record " + @ERROR + ": " + @SERROR Get $x $Recordset.Close() ; ? "Close disk recordset " + @ERROR + ": " + @SERROR Get $x Next
;Collect share info on the local machine $WMI_SHARE = "SELECT * FROM WIN32_SHARE" $Shares = GetObject($WMI).ExecQuery($WMI_SHARE) ;? "Get share info from WMI " + @ERROR + ": " + @SERROR Get $x For Each $Share In $Shares $Name = $Share.Name $Path = $Share.Path $Desc = $Share.Description $Type = $Share.Type Select Case $Type = 0 $Type = "Disk Drive" Case $Type = 1 $Type = "Print Queue" Case $Type = 2 $Type = "Device" Case $Type = 3 $Type = "IPC" Case $Type = 2147483648 $Type = "Disk Drive Admin" Case $Type = 2147483649 $Type = "Print Queue Admin" Case $Type = 2147483650 $Type = "Device Admin" Case $Type = 2147483651 $Type = "IPC Admin" Endselect ;Type uint32 Read-only ;Type of resource being shared. Types include disk drives, print queues, interprocess communications (IPC), and general devices. ;Values are: ;0 = Disk Drive ;1 = Print Queue ;2 = Device ;3 = IPC ;2147483648 = Disk Drive Admin ;2147483649 = Print Queue Admin ;2147483650 = Device Admin ;2147483651 = IPC Admin $Hyperlink = "\\" + @WKSTA + "\" + $Name $SQL_SHARES = "SELECT * FROM TBL_SHARES WHERE COMPID=" + $PCIDENTIFIER + " AND SHARENAME='" + $NAME + "'" $Command.CommandText = $SQL_SHARES $Recordset.Open($Command) ; ? "Open Share recordset " + @ERROR + ": " + @SERROR Get $x If $Recordset.RecordCount < 1 $Recordset.AddNew ; ? "Add new share record " + @ERROR + ": " + @SERROR Get $x Endif $Recordset.Fields("compID").Value = $PCIdentifier $Recordset.Fields("ShareName").Value = $Name $Recordset.Fields("SharePath").Value = $Path $Recordset.Fields("Description").Value = $Desc $Recordset.Fields("ShareType").Value = $Type $Recordset.Fields("Hyperlink").Value = $Hyperlink $Recordset.Update ; ? "Update share record " + @ERROR + ": " + @SERROR Get $x $Recordset.Close() ; ? "Close share recordset " + @ERROR + ": " + @SERROR Get $x Next ;And now grab Network Adapter info and update specific table $WMI_NETWORK_1 = "SELECT * FROM WIN32_NETWORKADAPTERCONFIGURATION WHERE IPENABLED='TRUE'" $NetCards = GetObject($WMI).ExecQuery($WMI_NETWORK_1) ;? "Get simple adapter info from WMI " + @ERROR + ": " + @SERROR Get $x For Each $Card In $NetCards $DeviceID = $Card.Index ; ? "Device ID is " + $DeviceID $MACAddress = $Card.MACAddress ; ? "MAC Address is " + $MACAddress $NetCard = $Card.Description ; ? "Net card description is " + $NetCard $IPAddress = $Card.IPAddress ; ? "IP Address is " + $IPAddress[0] $DHCP = $Card.DHCPEnabled If $DHCP $DHCP = "DHCP Enabled" Else $DHCP = "Static address" Endif ; ? "DHCP state is " + $DHCP $SQL_NETWORK = "SELECT * FROM TBL_NETWORKADAPTERS WHERE COMPID=" + $PCIDENTIFIER + " AND DEVICEID=" + $DeviceID + ";" $Command.CommandText = $SQL_NETWORK $Recordset.Open($Command) ; ? "Open Adapters recordset " + @ERROR + ": " + @SERROR Get $x If $Recordset.RecordCount < 1 $Recordset.AddNew ; ? "Add new adapters record " + @ERROR + ": " + @SERROR Get $x Endif $Recordset.Fields("compID").Value = $PCIdentifier $Recordset.Fields("DeviceID").Value = $DeviceID $Recordset.Fields("NetCard").Value = $NetCard $Recordset.Fields("IPAddress").Value = $IPAddress[0] $Recordset.Fields("MACAddress").Value = $MACAddress $Recordset.Fields("DHCP").Value = $DHCP $Recordset.Update ; ? "Update net card record " + @ERROR + ": " + @SERROR Get $x $Recordset.Close() ; ? "Close net card recordset " + @ERROR + ": " + @SERROR Get $x Next
;Collect Printer Connection info - should grab local as well $WMI_PRINTERS = "SELECT * FROM WIN32_PRINTER" $Printers = GetObject($WMI).ExecQuery($WMI_PRINTERS) ; ? "Get printers from WMI " + @ERROR + ": " + @SERROR Get $x For Each $Printer In $Printers $PrinterID = $Printer.DeviceID $DriverName = $Printer.DriverName $PortName = $Printer.PortName $Description = $Printer.Description $SQL_PRINTERS = "SELECT * FROM TBL_PRINTERCONNECTIONS WHERE COMPID=" + $PCIdentifier + " AND PRINTERID='" + $PrinterID + "'" $Command.CommandText = $SQL_PRINTERS $Recordset.Open($Command) ; ? "Open printer recordset " + @ERROR + ": " + @SERROR Get $x If $Recordset.RecordCount < 1 $Recordset.AddNew ; ? "Add new printer record " + @ERROR + ": " + @SERROR Get $x Endif $Recordset.Fields("compID").Value = $PCIdentifier $Recordset.Fields("PrinterID").Value = $PrinterID $Recordset.Fields("DriverName").Value = $DriverName $Recordset.Fields("PortName").Value = $PortName $Recordset.Fields("Description").Value = $Description $Recordset.Update ; ? "Update new printer record " + @ERROR + ": " + @SERROR Get $x $Recordset.Close() ; ? "Close printer recordset " + @ERROR + ": " + @SERROR Get $x Next
;Collect info on user's network drives $WMI_MAPPEDDRIVES = "SELECT * FROM WIN32_LOGICALDISK WHERE DRIVETYPE=4" $MappedDrives = GetObject($WMI).ExecQuery($WMI_MAPPEDDRIVES) For Each $Drive in $MappedDrives $Letter = $Drive.Name $Path = $Drive.ProviderName $SQL_MAPPEDDRIVES = "SELECT * FROM TBL_MAPPEDDRIVES WHERE USERID=" + $UserIdentifier + " AND LETTER='" + $Letter + "'" $Command.CommandText = $SQL_MAPPEDDRIVES $Recordset.Open($Command) If $Recordset.RecordCount < 1 $Recordset.AddNew Endif $Recordset.Fields("UserID").Value = $UserIdentifier $Recordset.Fields("Letter").Value = $Letter $Recordset.Fields("Path").Value = $Path $Recordset.Update $Recordset.Close() Next
;Close connection to database $Connection.Close() ;? "Close database connection " + @ERROR + ": " + @SERROR Get $x
;Tidy up by releasing COM objects from memory $Connection = 0 $Recordset = 0 $Command = 0
Hope this helps
Breaker [ 03. November 2003, 17:48: Message edited by: Breaker ]
_________________________
================================================ Breaker
|
|
Top
|
|
|
|
#106556 - 2003-11-03 05:58 PM
Re: Inventory Management
|
Bob Deerinwater
Starting to like KiXtart
Registered: 2002-05-05
Posts: 101
Loc: Covina California
|
Breaker, if you could send me the blank data base that would be great. that would svae alot of time. I spoke to my data base guy and seems to think that he can get the web interface working off of the data base. Thanks
|
|
Top
|
|
|
|
#106557 - 2003-11-03 06:16 PM
Re: Inventory Management
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
go look at the kix section of my website
|
|
Top
|
|
|
|
#106558 - 2003-11-03 06:17 PM
Re: Inventory Management
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Breaker,
Can you send me a copy too?
Kent
|
|
Top
|
|
|
|
#106559 - 2003-11-03 06:21 PM
Re: Inventory Management
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
sorry... I thought I had a link to the mdb there
my MDB is at: www.wheelerfam.com/Documents/Inventory.mdb
|
|
Top
|
|
|
|
#106560 - 2003-11-03 07:26 PM
Re: Inventory Management
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Did some conversion for SQL Server..
code:
;http://www.able-consulting.com/MDAC/ADO/Connection/ODBC_DSNLess.htm#ODBCDriverForSQLServer $DSN="Driver={SQL Server};" $DSN=$DSN+"Server=SQLSERVER;" $DSN=$DSN+"Database=Logins;" $DSN=$DSN+"Uid=;" $DSN=$DSN+"Pwd="
Cannot find :ADO_Error.
code:
If @ERROR <> 0 Goto ADO_Error Endif
Also, you need to add in WMIQUERY() UDF.
Run the code and get the following: quote:
Create Connection object 0: The operation completed successfully. Create Command object 0: The operation completed successfully. Create recordset object 0: The operation completed successfully. Open connection 0: The operation completed successfully. Open user recordset 0: The operation completed successfully. Update users -2147352567: COM exception error "Value" (Microsoft OLE DB Provider for ODBC Drivers - Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.) [-2147352567/80020009]
It is working as I am getting a record created in TBL_USERS.
For the SQL Server folks (may need some tweaking with the DataTypes) pardon the long lines-
code:
CREATE TABLE [dbo].[tbl_Computers] ( [PCID] [int] IDENTITY (1, 1) NOT NULL , [Workstation] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [NTDomain] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [SystemManufacturer] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [SystemModel] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [SerialNo] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [OS] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [ServicePack] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [PhysicalMemory] [int] NULL , [ProcessorSpeed] [int] NULL , [PagefileSpace] [float] NULL , [DiskController] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [VidMode] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [VidCard] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Modem] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [LoggedOnUser] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [LastUpdate] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY] GO
CREATE TABLE [dbo].[tbl_Disks] ( [compID] [int] IDENTITY (1, 1) NOT NULL , [DriveName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [FreeSpace] [float] NULL , [TotalSpace] [float] NULL , [Format] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY] GO
CREATE TABLE [dbo].[tbl_MappedDrives] ( [UserID] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [Letter] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Path] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY] GO
CREATE TABLE [dbo].[tbl_NetworkAdapters] ( [compID] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [DeviceID] [int] NULL , [NetCard] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [IPAddress] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [MACAddress] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [DHCP] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO
CREATE TABLE [dbo].[tbl_PrinterConnections] ( [compID] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [PrinterID] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [DriverName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [PortName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Description] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY] GO
CREATE TABLE [dbo].[tbl_Printers] ( [ID] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [PRINTER NAME] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [DESCRIPTION] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [SERIAL NUMBER] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [IP ADDRESS] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [PORT] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [TAG NO] [int] NULL , [STATUS] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY] GO
CREATE TABLE [dbo].[tbl_Shares] ( [compID] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [ShareName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [SharePath] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Description] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [ShareType] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Hyperlink] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO
CREATE TABLE [dbo].[tbl_Users] ( [UserID] [int] IDENTITY (1, 1) NOT NULL , [UserName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [FullName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Workstation] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [IsLocalAdmin] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [PrivilegeLevel] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [HomeDrive] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [LastUpdate] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Description] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY] GO
HTH,
Kent [ 03. November 2003, 20:03: Message edited by: kdyer ]
|
|
Top
|
|
|
|
#106562 - 2003-11-03 07:33 PM
Re: Inventory Management
|
Breaker
Hey THIS is FUN
   
Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
|
Whoops! Yeah, I pulled out the Subs for ADO_Error and WMI_Error as well as the source for WMIQuery.
The two subs only call a SendMail routine I use to inform me that someone's PC has a problem with running the logon script - they're not hugely informative, its really just flags them up as needing a look at.
Sorry! Obviously WMIQuery is a dependency - but I wouldn't want to post it in case it looks like I'm trying to claim credit for it!
I rolled this out so long ago now I can't remember if there were any other things that I had to do to get it working. I don't "think" so!
In fact, I think that the earlier version of this script was about my only contribution of note to the board - and it followed on from the question "How do I write to an Access DB?"
How time flies - and how little I've had to offer in between...
I had originally hoped to take my antiquated Access-based Helpdesk DB, convert it to an ASP-based solution and enable it to read from this DB as well to create a more useful tool - you know, someone logs a call with the Helpdesk, and while the 1st liner is taking the details, the ASP is returning data about the users PC, and the user themselves - justs speeds up the gathering of that data by other means. Could put in hyperlinks to the PCs admin shares, etc - lots of stuff that is available in the DB now, just not very easily accessible, or friendly looking.
Shame my boss doesn't want to pay me to sit on my fat a**e and play with code all day... [ 03. November 2003, 19:42: Message edited by: Breaker ]
_________________________
================================================ Breaker
|
|
Top
|
|
|
|
#106563 - 2003-11-03 07:39 PM
Re: Inventory Management
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Can you post your version of WMIQUERY() as I get an error on the line -
code:
Exit VAL("&"+Right(DecToHex(@ERROR),4))
Thanks,
Kent
|
|
Top
|
|
|
|
#106565 - 2003-11-03 07:59 PM
Re: Inventory Management
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Cool!
I think we can use this in a couple of different ways..
Notice the SQL Server Update above - removed the drop table procedures.. It now works like a champ! You should be chuffed!
Kent [ 03. November 2003, 20:05: Message edited by: kdyer ]
|
|
Top
|
|
|
|
#106566 - 2003-11-03 08:30 PM
Re: Inventory Management
|
Bob Deerinwater
Starting to like KiXtart
Registered: 2002-05-05
Posts: 101
Loc: Covina California
|
I am have troubles with this! Guess i am not quite getting it. This is what i have manageg to put together from the postings above. The script runs but nothing happens in the table. Is there any other dependencies. here is the code code:
$objWMIService = GetObject( "winmgmts://./root/cimv2" ) If @ERROR GoTo ShowError EndIf $colItem1 = $objWMIService.ExecQuery( "Select * from Win32_Processor", , 48 ) $colItem2 = $objWMIService.ExecQuery( "Select * from Win32_LogicalMemoryConfiguration", , 48 ) $colItem3 = $objWMIService.ExecQuery( "Select * from Win32_DiskDrive", , 48 )
For Each $objItem In $colItem1 $clockspeed = $objItem.CurrentClockSpeed Next For Each $objItem In $colItem2 $memory=( ( $objItem.TotalPhysicalMemory + 1023 ) / 1024 ) Next For Each $objItem In $colItem3 $hd = $objItem.Size $hdgb = Left($hd,Len($hd)-9) Next $IEVersion = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer","Version") $Freespace = GetDiskSpace("C:\") /1024
; Checking for Office Version
CD "c:\program files\microsoft office\office" $ver = GetFileVersion("excel.exe","fileversion") If @error = 0 Select Case SubStr("$ver",1,1) = 8 $officever = "Office 97" Case SubStr("$ver",1,1) = 9 $Officever = "Office 2000 Professional" EndSelect EndIf
$DATABASE = "x:\cvhp.mdb" $DSN = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=$DATABASE" $Connection = CreateObject("ADODB.Connection") $Command = CreateObject("ADODB.Command") $Recordset = CreateObject("ADODB.Recordset")
;Check for connection object $Connection.ConnectionString = $DSN $Connection.Open() ;Open connection to database $Command.ActiveConnection = $Connection $Recordset.CursorType = 3 $Recordset.LockType = 3 $Recordset.ActiveCommand = $Command
$Command.CommandText = "SELECT * FROM tbl_Inventory WHERE Mac_Address='@ADDRESS';" $Recordset.Open($Command) If $Recordset.RecordCount < 1 $Recordset.AddNew EndIf $Recordset.Fields("Mac_Address").Value = @ADDRESS $Recordset.Fields("Date").Value = @Date $Recordset.Fields("Campus").Value = $Campus $Recordset.Fields("IP_Address").Value = @IPADDRESS0 $Recordset.Fields("User_Name").Value = @WUSERID $Recordset.Fields("Workstation").Value = @WKSTA $Recordset.Fields("Processor").Value = $clockspeed+" MHZ" $Recordset.Fields("Memory").Value = $Memory+" MB" $Recordset.Fields("Hard_Drive").Value = $hdgb+" GB" $Recordset.Fields("Free_Space").Value = $FREESPACE $Recordset.Fields("Operating_System").Value = @PRODUCTTYPE $Recordset.Fields("Service_Pack").Value = @CSD $Recordset.Fields("Internet _Explorer").Value= $IEVERSION $Recordset.Fields("Office_Version").Value = $OFFICEVER $Recordset.Update $Recordset.Close()
|
|
Top
|
|
|
|
#106567 - 2003-11-03 08:38 PM
Re: Inventory Management
|
Bob Deerinwater
Starting to like KiXtart
Registered: 2002-05-05
Posts: 101
Loc: Covina California
|
Had the wrong table name works fine
|
|
Top
|
|
|
|
#106568 - 2003-11-03 09:16 PM
Re: Inventory Management
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Get the following error when trying to run for the first time.. quote:
PC ID number is Close database connection -2147352567: COM exception error "Close" (ADODB.Record set - Operation is not allowed when the object is closed.) [-2147352567/80020009 ]
Once run, all is good.
Kent
|
|
Top
|
|
|
|
#106570 - 2003-11-03 11:28 PM
Re: Inventory Management
|
Bob Deerinwater
Starting to like KiXtart
Registered: 2002-05-05
Posts: 101
Loc: Covina California
|
I run theis script out of my logon script. The mac address is the primary key in the access database so any modification other that changing the nic to the workstation should be entered as an edit. Now what happens when multiple clients log on at the same time. If the database is opened another user should not be able to write to it ( I Suspect). Any one have suggestions.
|
|
Top
|
|
|
|
#106572 - 2003-11-04 06:45 AM
Re: Inventory Management
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
10? It should be 255. Hang on.. Over to http://www.utteraccess.com
Kent
|
|
Top
|
|
|
|
#106573 - 2003-11-04 06:52 AM
Re: Inventory Management
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Microsoft Knowledge Base Article - 208778
quote:
The .ldb File Contents For each person who opens a shared database, the Jet database engine writes an entry in the database's .ldb file. The size of each .ldb entry is 64 bytes. The first 32 bytes contain the computer name (such as JohnDoe). The second 32 bytes contain the security name (such as Admin). The maximum number of concurrent users that the Jet database engine supports is 255; therefore, the .ldb file size is never larger than 16 kilobytes.
When a user closes a shared database, the user's entry is not removed from the .ldb file. However, it may be overwritten when another user opens the database. This means that you cannot use the .ldb file alone to determine who is currently using the database.
General- Some common Access specifications
HTH,
Kent
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 657 anonymous users online.
|
|
|