Code-Beispiel
Wmi mit Parametern aufrufen
Lizenz: | Erster Autor: | Letzte Bearbeitung: |
k. A. | ytwinky | 24.02.2011 |
Endlich habe ich mal eine Möglichkeit gefunden, die variable Parameter-Übergabe von FreeBasic zu testen. Natürlich mit der WMI(deshalb können linux-user nur das Prinzip sehen..)^^
Aber es funktioniert(auch wenn es auf englisch ist) und zwar so:
'+------------------------------------------------------------------------------------------+
'| Header: Bestimmen der Übergabeparameter' |
'| AnzeigeCheck:|Il1 sind Alt-0124, Großes i, kleines L, Eins „”᎙šñ¸=äöüßÄÖܱ©|
Const Author="WmFBFun.Bas v1.0 ¸2011 by ytwinky, MD"' |
'| (Tastenkombination: keine) |
'| |
'| Purpose: Call WMI with different parameters(variable list) |
'+------------------------------------------------------------------------------------------+
'Function to call wmi in a flexible way, but only to GET results..
'Caller MUST provide Wmi-Namespace(eg. \root\cimv2) and Wmi-Class(eg. Win32_Bios)
'other args as needed, but at least one, if not the program will crash..
'if there are dates to be transformed(eg. for german users^^) do it manually
'Win32_BIOS
'\root\cimv2
'BiosCharacteristics
'BuildNumber
'CodeSet
'CurrentLanguage
'Description
'IdentificationCode
'InstallDate
'InstallableLanguages
'LanguageEdition
'ListOfLanguages
'Manufacturer
'Name
'OtherTargetOS
'PrimaryBIOS
'ReleaseDate
'SMBIOSBIOSVersion
'SMBIOSMajorVersion
'SMBIOSMinorVersion
'SMBIOSPresent
'SerialNumber
'SoftwareElementID
'SoftwareElementState
'Status
'TargetOperatingSystem
'Version
#include once "windows.bi" 'in
#define UNICODE 'this
#include once "disphelper/disphelper.bi" 'order
Declare Function strComputer(SetNew As Integer=False, c As String=".") As String
Declare Function CallWMI Cdecl (WmiNameSpace As String, ...) As String
Var s=Author &!"\nCalling Wmi on "
Print s &strComputer &!"\n" &CallWMI("\root\cimv2", "Win32_BIOS", "ReleaseDate", "Description", "Manufacturer", "Name")
Print "Eniki..";
GetKey
End
Function strComputer(setNew As Integer=False, c As String=".") As String
Static As String s
If InStr(c, "\\") Then c=Mid(c, 3)
If setNew Then s=*IIf(c="", @".", SAdd(c))
If s="" Then s=Environ("ComputerName")
Return s
End Function
Function CallWMI Cdecl(WmiNameSpace As String, ...) As String
Dim hres As HRESULT
Dim WmiArgs() As String
Dim devPtr As ZString Ptr
Dim As Any Ptr Arg=va_first() 'Ptr to the first arg(it MUST be there..)
Var s="", i=0, impersonate="winmgmts:{impersonationLevel=impersonate}!\\" &strComputer &WmiNameSpace
Do
ReDim Preserve WmiArgs(i) As String
WmiArgs(i)=*va_arg(Arg, ZString Ptr)
If InStr(WmiArgs(i), ".") Then WmiArgs(i)=Mid(WmiArgs(i), 2)
Arg=va_next(Arg, ZString Ptr)
If (*va_arg(Arg, ZString Ptr)<>"") Then i+=1
Loop Until *va_arg(Arg, ZString Ptr)=""
s="WMI-Class:" &WmiArgs(0) &!"\n"
DISPATCH_OBJ(WmiSvc)
DISPATCH_OBJ(Items)
dhInitialize(True)
'this reports errors whether you want to see them or not:
'dhToggleExceptions(TRUE)
hres=dhGetObject(impersonate, Null, @WmiSvc)
hres=dhGetValue("%o", @Items, WmiSvc, ".ExecQuery(%s)", "Select * From " &WmiArgs(0))
FOR_EACH0(Item, Items, Null)
For i=1 To UBound(WMIArgs) 'beware:0 is the namespace (of the wmi object)
hres=dhGetValue("%s", @devPtr, Item, "." &WMiArgs(i))
If hres Then *devPtr="error in " &WMiArgs(i) &" " & hres
s &= WMiArgs(i) &":" &*devPtr &!"\n"
Next
NEXT_(Item)
SAFE_RELEASE(WmiSvc)
SAFE_RELEASE(Items)
dhUninitialize(True)
Return Left(s, Len(s)-1) 'remove last LF
End Function 'split the string As needed in your program(separator is obviously !"\n")
Viel Spaß beim Ausprobieren
Gruß
ytwinky
Zusätzliche Informationen und Funktionen |
- Das Code-Beispiel wurde am 24.02.2011 von ytwinky angelegt.
- Die aktuellste Version wurde am 24.02.2011 von ytwinky gespeichert.
|
|