×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Read machine name and bios version and write to MSSQL database

Read machine name and bios version and write to MSSQL database

Read machine name and bios version and write to MSSQL database

(OP)
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

RE: Read machine name and bios version and write to MSSQL database

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.

RE: Read machine name and bios version and write to MSSQL database

(OP)
That's just what I needed, many thanks.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close