fb:porticula NoPaste
WmGetIDE.Bas
Uploader: | ytwinky |
Datum/Zeit: | 17.03.2011 22:31:29 |
'+------------------------------------------------------------------------------------------+
'| Header: Bestimmen der bergabeparameter' |
'| AnzeigeCheck:|Il1 sind Alt-0124, Groes i, kleines L, Eins ᎙=ܱ|
Const Author="WmGetIDE.Bas v1.0 2011 by ytwinky, MD"' |
'| (Tastenkombination: keine) |
'| |
'| Purpose: Call WMI with different parameters(variable list) |
'+------------------------------------------------------------------------------------------+
'Function to call wmi in 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
'Available
'Antecedent
'Dependent
'NegotiatedDataWidth
'NegotiatedSpeed
#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 &!"\nIDE-Devices on " &strComputer &!"\nChannel Role Type Description\n"
Print s &CallWMI("\root\cimv2", "Cim_DeviceConnection", "Antecedent", "Dependent")
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 As String WmiArgs(), Role(2)={"Master", "Slave "}
Dim devPtr As ZString Ptr
Dim As Any Ptr Arg=va_first() 'Ptr to the first arg(it MUST be there..)
Var s="", d="", 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
If i=1 And InStr(*devPtr, "IDECHANNEL") Then s &="IDE" &Left(Right(*devPtr, 2), 1) &" "
If i=2 And InStr(*devPtr, !"ID=\34IDE") Then
s &=Role(Val(Left(Right(*devPtr, 4), 1))) &" "
d=Mid(*devPtr, InStr(*devPtr, "IDE")+5)
If Left(d, 4)="DISK" Then s &="HD ": d=Mid(d, 5, InStr(20, *devPtr, "\\")-4)
If Left(d, 5)="CDROM" Then s &="OD ": d=Mid(d, 6, InStr(20, *devPtr, "\\")-4)
s &= d &!"\n"'
EndIf
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")