tcarman Posted November 23, 2006 Share Posted November 23, 2006 Is there a way I can check an item based on the result of a WMI query?I want my VMware Tools selection checked if the machine manufacturer is VMware.Any ideas?Cheers. Link to comment Share on other sites More sharing options...
AlBundy33 Posted November 27, 2006 Share Posted November 27, 2006 (edited) I think it's not possible with WPI (for now) but you can start the setup from a vbs-file.Create a vbs-file, make your query and if manufacturer is vmware you can run your setup with these lines of code:Dim shellSet shell = CreateObject("WScript.Shell")'Syntax: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthrun.aspshell.Run "notepad.exe", 1, 1Set shell = NothingI'm also interessted on your script if it works.Al[EDIT]I tried to create my own script and here is the result:strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive",,48) insideVMware = falsepath = WScript.ScriptFullNamepath = Left(path, InstrRev(path, "\") - 1)For Each objItem in colItems If InStr(1, objItem.Model, "VMWare", vbTextCompare) Or InStr(1, objItem.Caption, "VMWare", vbTextCompare) Then insideVMware = trueNextIf insideVMware Then Set objShell = CreateObject("WScript.Shell") objShell.Run "msiexec /i """ & path & "\VMware Tools.msi"" ADDLOCAL=ALL REBOOT=ReallySuppress /passive /norestart /qb", 1, trueEnd IfIt was really hard to find the right query. Just add this command to WPIwscript "path_to_script\install.vbs"If you don't use wscript and start directly "path_to_script\install.vbs" you will be asked if you really want to start this script (for security reasons).Please try it an tell me if it works for you.ThanksAl[/EDIT][EDIT2]The script menitioned above works but VMWare Tools shows an error during install.I created the following script which work without error-message. checkifInsideVMware.vbsstrComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive",,48) insideVMware = falseFor Each objItem in colItems If InStr(1, objItem.Model, "VMWare", vbTextCompare) Or InStr(1, objItem.Caption, "VMWare", vbTextCompare) Then insideVMware = trueNext'set ERRORLEVEL (0 = true, -1 = false)WScript.Quit(insideVMware)setup.cmd@ECHO OFFSETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONPUSHD "%~dp0"CSCRIPT /nologo checkifInsideVMware.vbsIF %ERRORLEVEL% LSS 0 ( ECHO Inside VMware. Starting setup... START "" /wait Setup.exe /S /V"REBOOT=ReallySuppress /passive /norestart /qb /log ""%SYSTEMDRIVE%\VMwareTools.log""") ELSE ( ECHO Not inside VMware.)POPDENDLOCALJust call setup.cmd in WPI to install VMWare Tools.You can set VMWare Tools to your default selection because they where only installed inside VMware.Al[/EDIT2] Edited November 28, 2006 by AlBundy33 Link to comment Share on other sites More sharing options...
tcarman Posted December 1, 2006 Author Share Posted December 1, 2006 (edited) These really need 2 new functions written for WPI, those being System() and Model(). WPI would also need some new functionality for a Install/Check on Condition.Can anyone help out with this? I'm no good with Jscript. Edited December 1, 2006 by tcarman Link to comment Share on other sites More sharing options...
lawrenca Posted December 1, 2006 Share Posted December 1, 2006 Some interesting reading and project on wmi and java(script): WMI Java ProjectYou could easily add a function to wpi to check for a boolean condition or gcondition...see function calls added for RegKey and RegValue access in main.js as great examples...however,WMI query routines are very extensive and not all calls would be easily portable in a single function call, so you would have to pick the ones you are interested in and implement those. You could also call these functions in a .vbs within wpi if you've already put those together...just make sure they resolve to boolean. Another good example is the "ExtractToPath.vbs" for the extraction capability within wpi 5.6 with function call contained within core.js under the ReplacePath function for the vbs call. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now