If you use scripts for all kind of automation purposes, you definately have stumbled upon the issue that when you run the script, which in turn calls an executable file from somewhere on a network share, you get prompted with a Open File Dialog. Very annoying when you just want your script to run silently.
Fortunately there’s a workaround for this:
Change the SEE_MASK_NOZONECHECKS environment variable
Within your script, temporarily change the SEE_MASK_NOZONECHECKS environment variable to 1.
Note Do not use this as a permanent system environment variable because it will disable all Zone Checking.
set oShell= CreateObject('Wscript.Shell') set oEnv = oShell.Environment('PROCESS') oEnv('SEE_MASK_NOZONECHECKS') = 1 oShell.Run 'somecommand',0,True oEnv.Remove('SEE_MASK_NOZONECHECKS')
Note: I replaced all double quotes with single quotes in this example because of the syntax highlighting, if you want to use this example, find and replace all single quotes ( ' ) with double quotes ( " )
$env:SEE_MASK_NOZONECHECKS = 1 somecommand.exe Remove-Item env:\SEE_MASK_NOZONECHECKS
When you are working with deployments, whether it is SCCM, MDT, Altiris, LanDesk or whatever tool you are using, or you’re building a script which uses WMI queries, there’s always some actions you only want to perform on certain computers. In SCCM and MDT there’s builtin support for WMI queries. For instance, you want to apply a mass storage driver only to a computer that has that controller present.
To build these WMI Queries, in the past I always used the WMIC commandline tool. A very handy tool, but the syntax for this tool is a bit different then your average:
SELECT * FROM Win32_ComputerSystem WHERE model LIKE ‘%DC7900%’
In WMIC this query would be translated to:
WMIC PATH Win32_ComputerSystem WHERE “model LIKE ‘%DC7900%’
For this particular query it’s not that different, but what if you only want to get certain values?
SELECT Model FROM Win32_ComputerSystem WHERE model LIKE ‘%DC7900%’
Would be translated to:
WMIC PATH WIN32_ComputerSystem WHERE “model LIKE ‘%DC7900%’ GET model
As you see, it’s not really hard translating the commands, but there’s an even easier way to get your WMI Queries
Use the builtin Windows Management Instrumentation Tester: wbemtest.exe
Click on connect and type the namespace you want to connect to: (Default for WMI is root\cimv2)
Now we have all sorts of buttons available… we can easily open and explore a class and see it’s methods and properties… we can create a query in the syntax of:
SELECT * FROM Win32_ComputerSystem
Happy exploring and testing with WMI
As part of Microsofts Windows Management Framework, Powershell 2.0 is now available for the various Windows OSes. Download it from http://go.microsoft.com/fwlink/?LinkID=151321