Requirement for how to use <WMI> inside FWH ?

Requirement for how to use <WMI> inside FWH ?

Postby ukoenig » Mon Feb 23, 2009 1: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.
-----------------------
Image

Code: Select all  Expand view


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 :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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Requirement for how to use <WMI> inside FWH ?

Postby Enrico Maria Giordano » Mon Feb 23, 2009 4:29 pm

You don't need VB to use WMI. You can use it directly from [x]Harbour:

Code: Select all  Expand view
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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Requirement for how to use <WMI> inside FWH ?

Postby ukoenig » Mon Feb 23, 2009 5: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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Requirement for how to use <WMI> inside FWH ?

Postby StefanHaupt » Tue Feb 24, 2009 8: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: Select all  Expand view
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
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Requirement for how to use <WMI> inside FWH ?

Postby ukoenig » 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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 81 guests