Code: Select all
; class Win32_OperatingSystem : CIM_OperatingSystem
; {
; string BootDevice;
; string BuildNumber;
; string BuildType;
; string Caption;
; string CodeSet;
; string CountryCode;
; string CreationClassName;
; string CSCreationClassName;
; string CSDVersion;
; string CSName;
; sint16 CurrentTimeZone;
; boolean DataExecutionPrevention_Available;
; boolean DataExecutionPrevention_32BitApplications;
; boolean DataExecutionPrevention_Drivers;
; uint8 DataExecutionPrevention_SupportPolicy;
; boolean Debug;
; string Description;
; boolean Distributed;
; uint32 EncryptionLevel;
; uint8 ForegroundApplicationBoost;
; uint64 FreePhysicalMemory;
; uint64 FreeSpaceInPagingFiles;
; uint64 FreeVirtualMemory;
; datetime InstallDate;
; uint32 LargeSystemCache;
; datetime LastBootUpTime;
; datetime LocalDateTime;
; string Locale;
; string Manufacturer;
; uint32 MaxNumberOfProcesses;
; uint64 MaxProcessMemorySize;
; string MUILanguages[];
; string Name;
; uint32 NumberOfLicensedUsers;
; uint32 NumberOfProcesses;
; uint32 NumberOfUsers;
; uint32 OperatingSystemSKU;
; string Organization;
; string OSArchitecture;
; uint32 OSLanguage;
; uint32 OSProductSuite;
; uint16 OSType;
; string OtherTypeDescription;
; Boolean PAEEnabled;
; string PlusProductID;
; string PlusVersionNumber;
; boolean PortableOperatingSystem;
; boolean Primary;
; uint32 ProductType;
; string RegisteredUser;
; string SerialNumber;
; uint16 ServicePackMajorVersion;
; uint16 ServicePackMinorVersion;
; uint64 SizeStoredInPagingFiles;
; string Status;
; uint32 SuiteMask;
; string SystemDevice;
; string SystemDirectory;
; string SystemDrive;
; uint64 TotalSwapSpaceSize;
; uint64 TotalVirtualMemorySize;
; uint64 TotalVisibleMemorySize;
; string Version;
; string WindowsDirectory;
; };
#COINIT_MULTITHREAD=0
#RPC_C_AUTHN_LEVEL_CONNECT=2
#RPC_C_IMP_LEVEL_IDENTIFY=2
#EOAC_NONE=0
#RPC_C_AUTHN_WINNT=10
#RPC_C_AUTHZ_NONE=0
#RPC_C_AUTHN_LEVEL_CALL=3
#RPC_C_IMP_LEVEL_IMPERSONATE=3
#CLSCTX_INPROC_SERVER=1
#wbemFlagReturnImmediately=16
#wbemFlagForwardOnly=32
#IFlags = #wbemFlagReturnImmediately + #wbemFlagForwardOnly
#WBEM_INFINITE=$FFFFFFFF
#WMISeparator=","
Procedure.l ansi2uni(ansi.s)
size.l=MultiByteToWideChar_(#CP_ACP,0,ansi,-1,0,0)
Dim unicode.w(size)
MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), size)
ProcedureReturn SysAllocString_(@unicode())
EndProcedure
Procedure uni2ansi(uni)
Shared WMIResult.s
WMIResult.s = ""
mem=uni
While PeekW (mem)
WMIResult=WMIResult+Chr(PeekW(mem))
mem=mem+2
Wend
ProcedureReturn @WMIResult
EndProcedure
ProcedureDLL.s WMI(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: MessageRequester("ERROR", "unable to call CoInitializeSecurity", #MB_OK): Goto cleanup: EndIf
hres=CoCreateInstance_(?CLSID_WbemLocator,0, #CLSCTX_INPROC_SERVER,?IID_IWbemLocator,@loc.IWbemLocator)
If hres <> 0: MessageRequester("ERROR", "unable to call CoCreateInstance", #MB_OK): Goto cleanup: EndIf
CompilerIf #PB_Compiler_Unicode
hres=loc\ConnectServer(SysAllocString_(@"root\cimv2"),0,0,0,0,0,0,@svc.IWbemServices)
CompilerElse
hres=loc\ConnectServer(ansi2uni("root\cimv2"),0,0,0,0,0,0,@svc.IWbemServices)
CompilerEndIf
If hres <> 0: MessageRequester("ERROR", "unable to call IWbemLocator::ConnectServer", #MB_OK): 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: MessageRequester("ERROR", "unable to call CoSetProxyBlanket", #MB_OK): 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: MessageRequester("ERROR", "unable to call CoSetProxyBlanket", #MB_OK): Goto cleanup: EndIf
pUnk\Release()
k=CountString(WMICommand,#WMISeparator)
Dim wmitxt$(k)
For i=0 To k
wmitxt$(i) = StringField(WMICommand,i+1,#WMISeparator)
Next
CompilerIf #PB_Compiler_Unicode
hres=svc\ExecQuery(SysAllocString_(@"WQL"), SysAllocString_(@wmitxt$(0)), #IFlags,0,@pEnumerator.IEnumWbemClassObject)
CompilerElse
hres=svc\ExecQuery(ansi2uni("WQL"),ansi2uni(wmitxt$(0)), #IFlags,0,@pEnumerator.IEnumWbemClassObject)
CompilerEndIf
If hres <> 0: MessageRequester("ERROR", "unable to call IWbemServices::ExecQuery", #MB_OK): Goto cleanup: EndIf
hres=pEnumerator\reset()
Repeat
hres=pEnumerator\Next(#WBEM_INFINITE, 1, @pclsObj.IWbemClassObject, @uReturn)
For i=1 To k
mem=AllocateMemory(1000)
CompilerIf #PB_Compiler_Unicode
hres=pclsObj\get(SysAllocString_(@wmitxt$(i)), 0, mem, 0, 0)
CompilerElse
hres=pclsObj\get(ansi2uni(wmitxt$(i)), 0, mem, 0, 0)
CompilerEndIf
Type=PeekW(mem)
Select Type
Case 8
val.s=PeekS(uni2ansi(PeekL(mem+8)))
Case 3
val.s=Str(PeekL(mem+8))
Default
val.s=""
EndSelect
If uReturn <> 0: wmi$=wmi$+wmitxt$(i)+" = "+val+Chr(10)+Chr(13): EndIf
FreeMemory(mem)
Next
Until uReturn = 0
cleanup:
svc\Release()
loc\Release()
pEnumerator\Release()
pclsObj\Release()
CoUninitialize_()
ProcedureReturn wmi$
EndProcedure
Text$ = WMI("Select * FROM Win32_OperatingSystem,Name")
Debug StringField(Text$,1, "|")
Debug WMI("Select * FROM Win32_OperatingSystem,Version")
Debug WMI("Select * FROM Win32_OperatingSystem,OSArchitecture")
DataSection
CLSID_IEnumWbemClassObject:
Data.l $1B1CAD8C
Data.w $2DAB, $11D2
Data.b $B6, $04, $00, $10, $4B, $70, $3E, $FD
IID_IEnumWbemClassObject:
Data.l $7C857801
Data.w $7381, $11CF
Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24
CLSID_WbemLocator:
Data.l $4590F811
Data.w $1D3A, $11D0
Data.b $89, $1F, $00, $AA, $00, $4B, $2E, $24
IID_IWbemLocator:
Data.l $DC12A687
Data.w $737F, $11CF
Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24
IID_IUnknown:
Data.l $00000000
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
EndDataSection