Aide sur WMI

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
LOULOU25
Messages : 150
Inscription : mer. 19/mai/2004 20:40

Aide sur WMI

Message par LOULOU25 »

qui peut m'aider à traduire en PureBasic ce bout de programme en Autolit3

Code : Tout sélectionner

$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2\Applications\MicrosoftIE")

$colIESettings = $objWMIService.ExecQuery ("Select * from MicrosoftIE_Summary")

For $strIESetting in $colIESettings
 ;   ConsoleWrite( "Version: " & $strIESetting.Version & @CR)
  ;  ConsoleWrite( "Product ID: " & $strIESetting.ProductID & @CR)
   ; ConsoleWrite( "Cipher strength: " & $strIESetting.CipherStrength & @CR)
Next

$file =FileOpen(@desktopDir & "\cripte.txt",2)
FileWrite($file, $strIESetting.CipherStrength)
FileClose($file) 
Merci par avance
brossden
Messages : 819
Inscription : lun. 26/janv./2004 14:37

Message par brossden »

C'est pour de l'UNIX non ?
Denis

Bonne Jounée à tous
LOULOU25
Messages : 150
Inscription : mer. 19/mai/2004 20:40

Message par LOULOU25 »

Non c'est du windows
Gillou
Messages : 373
Inscription : sam. 28/août/2004 17:35
Localisation : Bretagne, 22
Contact :

Message par Gillou »

un début de code, en ce moment j'ai pas trop le temps de coder, donc j'espère que ça pourra te filer un coup de pouce

Code : Tout sélectionner

Procedure.l ansi2bstr(ansi.s)
    size.l = MultiByteToWideChar_(#CP_ACP, 0, ansi, -1, 0, 0)
    Global Dim unicode.w(size)
    MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), size)
    ProcedureReturn SysAllocString_( @unicode())
EndProcedure

Procedure bstr2string (bstr)
    Shared WMIResult.s
    WMIResult.s = ""
    pos = bstr
    While PeekW (pos)
        WMIResult = WMIResult + Chr(PeekW(pos))
        pos = pos + 2
    Wend
    ProcedureReturn @WMIResult
EndProcedure

ProcedureDLL.s WMIC(root.s, WMICommand.s)
    CoInitializeEx_(0, #COINIT_MULTITHREAD)
    hres = CoInitializeSecurity_(0, -1, 0, 0, #RPC_C_AUTHN_LEVEL_CONNECT, #RPC_C_IMP_LEVEL_IDENTIFY, 0, #EOAC_NONE, 0)
    If hres <> 0 : e$ = "unable to call CoInitializeSecurity" : Goto cleanup : EndIf
    hres = CoCreateInstance_(?CLSID_WbemLocator, 0, #CLSCTX_INPROC_SERVER, ?IID_IWbemLocator, @loc.IWbemLocator)
    If hres <> 0 : e$ = "unable to call CoCreateInstance" : Goto cleanup : EndIf
    hres = loc\ConnectServer(ansi2bstr(root), 0, 0, 0, 0, 0, 0, @svc.IWbemServices)
    If hres <> 0 : e$ = "unable to call IWbemLocator::ConnectServer" : loc\Release() : Goto cleanup : EndIf
    hres = svc\QueryInterface(?IID_IUnknown, @pUnk.IUnknown)
    hres = CoSetProxyBlanket_(svc, #RPC_C_AUTHN_WINNT, #RPC_C_AUTHZ_NONE, 0, #RPC_C_AUTHN_LEVEL_CALL, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, #EOAC_NONE)
    If hres <> 0 : e$ = "unable to call CoSetProxyBlanket" : svc\Release() : loc\Release() : Goto cleanup : EndIf
    hres = CoSetProxyBlanket_(pUnk, #RPC_C_AUTHN_WINNT, #RPC_C_AUTHZ_NONE, 0, #RPC_C_AUTHN_LEVEL_CALL, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, #EOAC_NONE)
    If hres <> 0 : e$ = "unable to call CoSetProxyBlanket" : svc\Release() : loc\Release() : pUnk\Release() : Goto cleanup : EndIf
    pUnk\Release()
    
    hres=CoCreateInstance_(?CLSID_WbemRefresher,0,#CLSCTX_INPROC_SERVER,?IID_IWbemRefresher,@pRefresher.IWbemRefresher)
    If hres <> 0 : e$ = "unable to call CoCreateInstance" : svc\Release() : loc\Release() : Goto cleanup : EndIf
    hres=pRefresher\queryinterface(?IID_IWbemConfigureRefresher,@pConfig.IWbemConfigureRefresher)
    If hres <> 0 : e$ = "unable to QueryInterface" : svc\Release() : loc\Release() : pRefresher\release() : Goto cleanup : EndIf
    pRefresher\refresh(0)
    
    k = CountString(WMICommand, #WMISeparator)
    Global Dim wmitxt$(k)
    For i = 0 To k
        wmitxt$(i) = StringField(WMICommand, i + 1, #WMISeparator)
    Next
    
    hres = svc\ExecQuery(ansi2bstr("WQL"), ansi2bstr(wmitxt$(0)), #IFlags, 0, @pEnumerator.IEnumWbemClassObject)
    If hres <> 0 : e$ = "unable to call IWbemServices::ExecQuery" : svc\Release() : loc\Release() : pRefresher\release() : Goto cleanup : EndIf
    hres = pEnumerator\reset()
    Repeat
        hres = pEnumerator\Next(#WBEM_INFINITE, 1, @pclsObj.IWbemClassObject, @uReturn)
        If hres = 0
            For i = 1 To k
                mem = AllocateMemory(1000)
                hres = pclsObj\get(ansi2bstr(wmitxt$(i)), 0, mem, 0, 0)
                Type = PeekW(mem)
                Select Type
                    Case 8
                        val.s = PeekS(bstr2string(PeekL(mem + 8)))
                    Case 3
                        val.s = Str(PeekL(mem + 8))
                    Default
                        val.s = ""
                EndSelect
                If uReturn <> 0 : If wmi$ : wmi$ = wmi$ + "|" + wmitxt$(i) + "=" + val : Else : wmi$ = wmitxt$(i) + "=" + val : EndIf : EndIf
                FreeMemory(mem)
            Next
            pclsObj\Release()
        EndIf
    Until uReturn = 0
    svc\Release() : loc\Release() : pEnumerator\Release() : pRefresher\release()
    cleanup :
    CoUninitialize_()
    If e$
        ProcedureReturn "ERROR : " + e$
    EndIf
    ProcedureReturn wmi$
EndProcedure

DataSection
    CLSID_IEnumWbemClassObject :
    ; 1B1CAD8C-2DAB-11D2-B604-00104B703EFD
        Data.l $1B1CAD8C
        Data.w $2DAB, $11D2
        Data.b $B6, $04, $00, $10, $4B, $70, $3E, $FD
    IID_IEnumWbemClassObject :
    ; 7C857801-7381-11CF-884D-00AA004B2E24
        Data.l $7C857801
        Data.w $7381, $11CF
        Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24
    CLSID_WbemLocator :
    ; 4590f811-1d3a-11d0-891f-00aa004b2e24
        Data.l $4590F811
        Data.w $1D3A, $11D0
        Data.b $89, $1F, $00, $AA, $00, $4B, $2E, $24
    IID_IWbemLocator :
    ; dc12a687-737f-11cf-884d-00aa004b2e24
        Data.l $DC12A687
        Data.w $737F, $11CF
        Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24
    IID_IUnknown :
    ; 00000000-0000-0000-C000-000000000046
        Data.l $00000000
        Data.w $0000, $0000
        Data.b $C0, $00, $00, $00, $00, $00, $00, $46
    IID_IWbemRefresher:
    ;49353c99-516b-11d1-aea6-00c04fb68820
        Data.l $49353C99
        Data.w $516B, $11D1
        Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20
    CLSID_WbemRefresher:
    ;c71566f2-561E-11D1-AD87-00C04FD8FDFF
        Data.l $C71566F2
        Data.w $561E, $11D1
        Data.b $AD,$87,$00,$C0,$4F,$D8,$FD,$FF
    IID_IWbemConfigureRefresher:
    ;49353c92-516b-11d1-aea6-00c04fb68820
        Data.l $49353C92
        Data.w $516B, $11D1
        Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20
EndDataSection

Debug WMIC("root\cimv2\Applications\MicrosoftIE", "select * from MicrosoftIE_Summary,Version,Product ID,Cipher strength")
Répondre