FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Requirement for how to use <WMI> inside FWH ?
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Requirement for how to use <WMI> inside FWH ?
Posted: Mon Feb 23, 2009 01:32 PM
Hello,

I started using :
W = Windows
M = Management
I = Instrumentation
inside my application with SCRIPTING-HOST.
I don't know, if this special kind of programming could be interesting
for FWH-users.
Remote control of computers, Hardware-Informations and more ....

Just a working test :

Windows-Serial-No.
-----------------------


Code (fw): Select all Collapse
FUNCTION GET_SERIAL()

IF FILE ( "VBFUNC.VBS" )
    DELETE FILE  "VBFUNC.VBS"
ENDIF

oText := TTxtFile():New( "VBFUNC.VBS" )
IF oText:Open()
      oText:Add(' set collection = _')
      oText:Add(' GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem") ')
      oText:Add(' for each os in collection ')
      oText:Add('    MsgBox "Seriennummer: " & os.SerialNumber ')
      oText:Add(' next ')
      oText:Close()
ENDIF
Winexec('WSCRIPT.exe VBFUNC.VBS')

RETURN NIL


Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Requirement for how to use <WMI> inside FWH ?
Posted: Mon Feb 23, 2009 04:29 PM
You don't need VB to use WMI. You can use it directly from [x]Harbour:

Code (fw): Select all Collapse
FUNCTION MAIN()

    LOCAL oLoc := CREATEOBJECT( "wbemScripting.SwbemLocator" )
    LOCAL oSrv := oLoc:ConnectServer()
    LOCAL oJbs := oSrv:ExecQuery( "SELECT * FROM Win32_OperatingSystem" )

    LOCAL oJob

    FOR EACH oJob IN oJbs
        ? oJob:SerialNumber
    NEXT

    RETURN NIL


EMG
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Requirement for how to use <WMI> inside FWH ?
Posted: Mon Feb 23, 2009 05:35 PM

Enrico,

thank You very much for the information, it saves some hour's of work.

Regards
Uwe :lol:

Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: Requirement for how to use <WMI> inside FWH ?
Posted: Tue Feb 24, 2009 08:22 AM
Uwe,

just to avoid runtime errors you should check if WMI is properly installed. Here is an enhanced version of Enrico´s sample

Code (fw): Select all Collapse
FUNCTION MAIN()

    LOCAL oLoc := CheckWMI ()
    LOCAL oSrv 
    LOCAL oJbs 
    LOCAL oJob
   
   IF oLoc = nil
     ? "WMI not installed"
     RETURN (nil)
   ENDIF
 
  oSrv := oLoc:ConnectServer()
  oJbs := oSrv:ExecQuery( "SELECT * FROM Win32_OperatingSystem" )

  FOR EACH oJob IN oJbs
        ? oJob:SerialNumber
    NEXT

 RETURN NIL

//----------------------------------------------------------------------------//
FUNCTION CheckWMI ()

  LOCAL oLoc, oErr

  TRY
    oLoc := CreateObject( "wbemScripting.SwbemLocator" )
  CATCH oErr
    oLoc := nil
  END

RETURN (oLoc)
kind regards

Stefan
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Requirement for how to use <WMI> inside FWH ?
Posted: Tue Feb 24, 2009 10:52 AM

Stefan,

thank You very much for the info.
I'm planning a TOOLBOX for this.
Because of many documentations und samples I own,
it isn't very difficult anymore and I think, it can be useful for the FWH-users.

Regards
Uwe :lol:

Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.

Continue the discussion