How do i get SerialNumber of BaseBoard with WMI?

560 Views Asked by At

A nice example is there to use WMI in Powerbuilder that terminates a running process.

The same technique can be used to get SerialNumber of BaseBoard. I need to extend the same code to handle return values of the WQL query.

The WQL query i want to execute is:

SELECT Product, SerialNumber FROM Win32_BaseBoard

I can execute the query above but dont know how to save the SerialNumber in a variable after the ExecuteStatement() function is called.

Please take a look at the link for complete PowerBuilder code. How to terminate a process if it has specific folder name in its path?

Following is a portion of a sample code taken from the link above to show the function.

wsh = CREATE OleObject
wsh.ConnectToNewObject("MSScriptControl.ScriptControl")
wsh.Language = "VBScript"
wsh.AddCode(TheCode)
TRY
    wsh.ExecuteStatement(FunctionName)
CATCH (RunTimeError Re01)
    MessageBox("Query Error", "Following code has some problems.~r~n~r~n" +                 TheCode, StopSign!)
END TRY
wsh.DisconnectObject()

DESTROY wsh

The important function call wsh.ExecuteStatement(FunctionName)

What to do after that function call to set my PowerBuilder local variables with the returned SerialNumber of BaseBoard?

1

There are 1 best solutions below

2
On BEST ANSWER
OLEObject ole_wsh
Any la_baseboard[]
string ls_message

 ole_wsh = CREATE OLEObject
 ole_wsh.ConnectToNewObject("MSScriptControl.ScriptControl")
 ole_wsh.Language = "vbscript"
 ole_wsh.AddCode('Function rtnBaseBoard()~r~n' &
 + 'DIM objBaseBoard(2)~r~n'  &
 + 'strComputer = "."~r~n'  &
 + 'Set objWMIService ='  &
 + '   GetObject("winmgmts:\\" & strComputer & "\root\cimv2")~r~n' &
 + 'Set colItems =' &
 + '    objWMIService.ExecQuery("SELECT Product, SerialNumber FROM Win32_BaseBoard")~r~n' &
 + 'For Each objItem in colItems~r~n' &
 + 'objBaseBoard(0) = objItem.Product~r~n' &
 + 'objBaseBoard(1) = objItem.SerialNumber~r~n' &
 + 'Next~r~n' &
 + 'rtnBaseBoard = objBaseBoard~r~n' &
 + 'End Function')
 la_baseboard[] = ole_wsh.Eval("rtnBaseBoard")
 ole_wsh.DisconnectObject()
 DESTROY ole_wsh

ls_message = "Product: " + string(la_baseboard[1]) + "~r~n" + &
+ "SerialNumber: " + string(la_baseboard[2]) + "~r~n" 
MessageBox("Win32 BaseBoard",ls_message)