Jump to content

Check box on WMI query result


Recommended Posts


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 shell
Set shell = CreateObject("WScript.Shell")
'Syntax: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthrun.asp
shell.Run "notepad.exe", 1, 1
Set shell = Nothing

I'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 = false
path = WScript.ScriptFullName
path = 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 = true
Next

If insideVMware Then
Set objShell = CreateObject("WScript.Shell")
objShell.Run "msiexec /i """ & path & "\VMware Tools.msi"" ADDLOCAL=ALL REBOOT=ReallySuppress /passive /norestart /qb", 1, true
End If

It was really hard to find the right query. :)

Just add this command to WPI

wscript "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.

Thanks

Al

[/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.vbs

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive",,48)

insideVMware = false
For Each objItem in colItems
If InStr(1, objItem.Model, "VMWare", vbTextCompare) Or InStr(1, objItem.Caption, "VMWare", vbTextCompare) Then insideVMware = true
Next

'set ERRORLEVEL (0 = true, -1 = false)
WScript.Quit(insideVMware)

setup.cmd

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

PUSHD "%~dp0"

CSCRIPT /nologo checkifInsideVMware.vbs

IF %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.
)

POPD

ENDLOCAL

Just 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 by AlBundy33
Link to comment
Share on other sites

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 by tcarman
Link to comment
Share on other sites

Some interesting reading and project on wmi and java(script): WMI Java Project

You 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...