Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read machine name and bios version and write to MSSQL database

Status
Not open for further replies.

SW2004

Technical User
Jul 13, 2004
24
GB
Hi

I have the following script which reads the machine name and then looks up the BIOS version on the PC, currently it only echo the results. I have a SQL server available to me, how would I connect to the server and write the results to the database? I've looked hi and low on MSDN and can't find an example of how to do this using VBscript/WSH. if someone can give me an example I'd be very grateful. Thanks, Steven

Here is the code:

'Read Machine Name
Set objComputer = CreateObject("Shell.LocalMachine")
Wscript.Echo "Computer name: " & objComputer.MachineName

'Read BIOS details
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colBIOS = objWMIService.ExecQuery _
("Select * from Win32_BIOS")

For each objBIOS in colBIOS
Wscript.Echo objBIOS.Manufacturer
Wscript.Echo objBIOS.Name
Wscript.Echo objBIOS.SerialNumber
Next
 
Something like this:

Set objConn = CreateObject("ADODB.Connection")
objConn.Open "Driver={SQL Server};" & _
"Server=Your Server;" & _
"Database=Your Database;" & _
"user id=sa;" & _
"password=Your SA Password;"
Set objRSSQL = CreateObject("ADODB.Recordset")

'Read Machine Name
Set objComputer = CreateObject("Shell.LocalMachine")
Wscript.Echo "Computer name: " & objComputer.MachineName

'Read BIOS details
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colBIOS = objWMIService.ExecQuery _
("Select * from Win32_BIOS")

For each objBIOS in colBIOS
SQLQuery = "insert into tblbios (manufacture, Name, SerialNum)" & _
" values ('" & objBIOS.Manufacturer & "','" & objBIOS.Name & "','" & objBIOS.SerialNumber & "')"
objRSSQL.Open SQLQuery, objConn
Next


NOTE: You will need to enter your own information in the "objConn.Open" area. Also on the "SQLQuery =" area you will need to change the table name "tblbios" to whatever your table name is and the field names as well. Keep in mind that this will insert a new record each time it is ran even if an entry already exist. You may want to include the machine name and then check to see if the record for the machine already exist and if so update it and if not then insert it.

Good luck and I hope this helps.
 
That's just what I needed, many thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top