Archive: WMI plug-in


WMI plug-in
Attached plugin supports wmi request from MS API call.
I have included script sample.

For now it can retrieve :

* OS Name
* OS Version
* AntiVirus Name
* FireWall Name
* CPU Name
* Desktop resolution
* Any information if you provide correct parameters

Any suggestion are welcomed.

More info could be found at the NSIS Wiki plugin page
http://nsis.sourceforge.net/WmiInspector_plug-in


I've just added

* SQL Version


Forgot to join file :o


Added :

*UserName
*ShortUserName
*UserSID

to retrieve user name and SID from registry.


I'm very much a newbie to NSIS. I have two questions regarding this plugin:-

1
I can't get the examples to work I get an error:-

"WmiInspector::Request"

I am guessing that it is something to do with where I place the plugin files which I assume are WmiInspector.vcproj, WmiInspector.cpp and WmiInspector.sln? Can anyone advise?


2
The WMI call I want to replicate in NSIS is contained in the following:-


Set objWMISvc = GetObject( "winmgmts:\\" & strComputerName & "\root\cimv2" )
Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
strComputerDomain = objItem.Domain
If objItem.PartOfDomain Then
WScript.Echo "Computer Domain: " & strComputerDomain
Else
WScript.Echo "Workgroup: " & strComputerDomain
End If
Next


I am unsure how to go about this and would be grateful for some pointers.

Charlie

Those files you mention are for the source code. You just need to put the DLL file in the NSIS\Plugins folder

Stu


Thanks for the speedy response. I open the zip at http://nsis.sourceforge.net/WmiInspector_plug-in and the only files there are:-

TestWmiInspector.exe
TestWmiInspector..nsi
WmiInspector.cpp
WmiInspector.vcproj
WmiInspector.sln

No DLL. Same for the files attached to this message.

Charlie


Looks like l0k1 forgot to put the actual plugin in the Zip!

Stu


So I'm not going mad after all then :)


Is there a way of tracking it down?


You will need to build the plugin yourself using Visual Studio. If you are using Windows XP or 2000 you can build with Visual Studio Express Editions C++ 2008 and the Windows Server 2003 PSDK.

http://www.microsoft.com/Express/
http://www.microsoft.com/downloads/d...displaylang=en

I cannot build for you as I am running Windows Vista (I can only install the Windows Server 2008 PSDK).

Stu


Hmm uncharted territory for me but I'll give it a go. The blurb on http://www.microsoft.com/Express/ tells me I also need the Microsoft MSDN Express Library. Presumably that's correct. Could you give me pointers what I do when I have these all installed?

Charlie


Hello,
the .zip file CONTAINS the .dll
Please double check that you don't have it.
Regards
Stefano


Nope when I click on any of the zips I just get the five files listed:-

TestWmiInspector.exe
TestWmiInspector..nsi
WmiInspector.cpp
WmiInspector.vcproj
WmiInspector.sln

What URL are you using?


Hang on I have just cleared my cache and the second link on this thread does indeed now show the DLL Grrrrrrrrrrrrrrrrrrrr.


The file on the Wiki does not contain the dll.

Stu


That would fit with the cache problem I hit as it was the first one I opened.


I am trying to capture the domain or the computer using:-

WmiInspector::Request "CIMV2" "Win32_OperatingSystem" "Domain"
gives me an error whereas:-

WmiInspector::Request "CIMV2" "Win32_OperatingSystem" "Caption"
works fine yet both values are stings. Am I missing something here?

Also how do I recover a boolean value - in particular the WMI value "PartOfDomain"

Can anyone give me some pointers?

Charlie

Domain and PartOfDomain are not in Win32_OperatingSystem; they are in Win32_ComputerSystem.

Stu


Aha so often the answer to something that has bugged me for days proves to be frustatingly simple. Thanks for the help on all of this.


wmi calls returning arrays
Hey l0k1, I noticed the plugin doesn't support any WMI calls that return an array of ints...

WmiInspector::Request "CIMV2" "Win32_SystemEnclosure" "ChassisTypes"
; see http://msdn.microsoft.com/en-us/library/aa394474(VS.85).aspx

Internally, I need to handle the case where var.vt is VT_ARRAY|VT_I4, but I haven't figured that out yet. Have you?


how can i read all values (not just one) from request? How can i add loop to walk throw all values?
---
And there is problem with Unicode NSIS. i compiled with ANSI NSIS and its ok, Unicode NSIS gives me request return in chinese ot smth


Wmi
Im not sure if its possible to read through all results using this plug in but i created a macro based on the wmic command that reads through all results.

Download WMI.nsh attached to this post and see the following file as an example:



Name WMI
OutFile WMI.exe
RequestExecutionLevel Admin
OutFile "fileread.exe"

!include WMI.nsh
!include LogicLib.nsh
Section ""

${GetWMI} root\CIMV2 Win32_DiskDrive model callback_Function
${GetWMI} root\CIMV2 Win32_NetworkAdapter name callback_Function
${GetWMI} root\CIMV2 Win32_UserAccount name callback_Function
SectionEnd

Function callback_Function
#$R0 = result number, $R1 = total results, $R2 = result name
detailprint "$R0/$R1=$R2"
FunctionEnd


Usage ${GetWMI} namespace classes property callback_Function

In the callback function results are $R0 = result number, $R1 = total results, $R2 = Result name.

Theres a WMI code creator tool which is useful for finding out the namespaces, classes , and properties which can be downloaded here

http://www.microsoft.com/downloads/e...displaylang=en

Please make a Wiki page. Also I would recommend wrapping your header in:

!ifndef __WMI_Included__
!define __WMI_Included__
...
!endif

Stu


created a wiki page here.