Page 1 of 1

Requirement for how to use <WMI> inside FWH ?

PostPosted: Mon Feb 23, 2009 1:32 pm
by ukoenig
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:

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

PostPosted: Mon Feb 23, 2009 4:29 pm
by Enrico Maria Giordano
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

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

PostPosted: Mon Feb 23, 2009 5:35 pm
by ukoenig
Enrico,

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

Regards
Uwe :lol:

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

PostPosted: Tue Feb 24, 2009 8:22 am
by StefanHaupt
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)


 

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

PostPosted: Tue Feb 24, 2009 10:52 am
by ukoenig
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: