19 June, 2012

WMI Filtering, Targeting, Usage & Utilities

WMI filtering is a very neat tool. I personally find its syntax a little complicated. Recently I came across with this 2 line article. How to WMI Filter with computer name. Here is an example.

select * from Win32_ComputerSystem where Name = ‘Computer Name’

If you are looking for more WMI Filter examples, this article has it all…


Here is another example of how to target Windows 7 by its architecture type (X86 or X64). This is great while deploying applications through Group Policy. Not all the applications are compatible both 32 and 64 bit, so you can target only 32bit or only 64bit computers with the help of this WMI query.

Here is how it looks like to target only Windows 7 X86 Systems

select * from Win32_OperatingSystem WHERE Version like "6.1%" AND ProductType="1" AND NOT OSArchitecture = "64-bit"

Targeting Windows 7 X64 Systems

select * from Win32_OperatingSystem WHERE Version like "6.1%" AND ProductType="1" AND OSArchitecture = "64-bit"

But, how do you make sure that these WMI queries are actually working? Of course, you can go ahead and try to apply it to a GPO and try on with a couple of machines… Or you can download this little utility from the www.gpoguy.com website written by Darren Mar-Elia. This tool is handy when it comes to try out your WMI filters in your GPO. The tool can pull all configured queries from your Active Directory and validate them. If you are working a lot with GPO’s and WMI’s, this tool is a must have. Here is the link to the download page;

I thought, while we are in the subject, why don’t I give away all my secret weapons in terms of WMI coding…
Here is a little list of tools that might save you hours of work and make you look like a decent programmer J

PowerGUI A Graphical User Interface and script editor for Microsoft Windows PowerShell
WMICode Creator Generates code in VBScript, C#, and Visual Basic® .NET; you can run the code directly from the tool. You can generate code to query for management information, execute a management task, or receive event notifications.
Scriptomatic 2.0
This utility that writes WMI scripts for you. (And, in the process, teaches you the fundamental concepts behind writing WMI scripts for yourself.)

Deploy Java 7 with GPO

Deploying Java 7 Update 5 through your Organization with GPO and Scripts…

Java is a critical component for your computer. A lot of software and web sites rely on the existing of Java on your computer. Probably, without even noticing, you are using Java either for playing Online games, or printing a document or using an application on a smartphone… While Java is a great technology and widely used, it can be harmful for your computer if you don’t keep it up to date. Because Java is an environment where it can execute commands, Oracle is working on the software in order to correct all the security issues. If you are responsible for your workstations on your company, than you are directly responsible to deploy and keep up to date Java. I consider Java as it’s a part of the OS.

Speaking of the devil, Oracle has just updated Java to version 7 Update 5. Here, I’ll explain how to deploy this version to all of your computers at your company whether an older version is already installed or not…

Of course, there is more than 1 way to deploy an application… I’m more a script guy and really lazy… So my method works and easy to implement. Here we go,

First of all, determine if you want to uninstall older versions that are already installed on your computers. It’s highly recommended to do so. In order to uninstall Java silently and centrally, you need to know the “GUID” of the versions that are installed. I covered this part on my last post. Once you have this information, we can start to write our little script that will do all the magic for you. But one more thing, I assume that you already have a shared folder where you can put you setup files and scripts that is accessible from all the computers in your company. For example purposes only, let’s say your file server name is “FILE” and your shared folder is called “Shared” and everything you need to deploy about Java is inside a folder called “Java”. For this type of scenario, here is the code.

@echo off
REM next line uninstalls Java 6u31 X86
msiexec /X{26A24AE4-039D-4CA4-87B4-2F83216031FF} /qn REBOOT=ReallySuppress

REM next line uninstalls Java 6u31 X64
msiexec /X{26A24AE4-039D-4CA4-87B4-2F86416031FF} /qn REBOOT=ReallySuppress

REM next line uninstalls Java 7u4 X86
msiexec /X{26A24AE4-039D-4CA4-87B4-2F83217004FF} /qn REBOOT=ReallySuppress

REM next line uninstalls Java 7u4 X64
msiexec /X{26A24AE4-039D-4CA4-87B4-2F86417004FF} /qn REBOOT=ReallySuppress

REM next line Installs Java 7u5 X86 and creates a LOG file.
"\\FILE\SHARED\JAVA\jre-7u5-windows-i586.exe" /s IEXPLORER=1 MOZILLA=1 /L C:\javaupdate7u5.log REBOOT=ReallySuppress JAVAUPDATE=0

REM next line Installs Java 7u5 X64 and creates a LOG file.
"\\FILE\SHARED\JAVA\jre-7u5-windows-x64.exe" /s IEXPLORER=1 MOZILLA=1 /L C:\javaupdate7u5-X64.log REBOOT=ReallySuppress JAVAUPDATE=0

1- Create a batch file with this code.

2- Download and place your offline installers from http://java.com/en/download/manual.jsp

3- Create a GPO and link it to the OU that has all your computer accounts.

4- Edit the GPO. Browse to “Computer Configuration\Policies\Windows Settings\Scripts (Startup/Shutdown)”. On the right pane, double click on “Startup”. This will bring up the “Startup Properties” window. Click on “Show Files”, this will open the folder where you need to put your Batch file. Copy your script in this folder and close explorer.

5- Now, click on “Add” and “Browse” to choose your script. Click “Open” and “OK

6- Finally click on “Apply

7- You can disable “User Configuration Settings” from this GPO because it does not contain anything in “User Configuration”. This will speed up the processing operation of this GPO. To do that, right click on your GPO and choose “GPO Status” and click on “User Configuration Settings Disabled

With this method, the installation will occur during start up. End user won’t see any activity while this is processed. The only problem with this script, it will run every time you start your computer even if it’s already installed. But when the same version is already installed, it won’t reinstall everything; it will just ignore and not proceed with the setup. The good thing with this method is when folks at Oracle decide to deploy a new version; all you need to do to deploy the latest version is add 2 more lines in your script.
The first lines of this batch file will uninstall the version 6u31 and 7u4 if they are resident, if these version are not installed, you can still leave these lines. Last two lines start the installation from your shared network folder with the necessary switches in order to install JAVA silently and deactivate the auto update feature. You don’t want every computer to download and install Java seperatly by users. So deactivating the AutoUpdate is a must.

15 June, 2012

Find GUID (Globally Unique Identifier) of installed programs

After a long time, I finally motivated myself and wrote this article. As I spent a couple of hours trying to figure out how to find GUID of Java environment for a little deployment project, I realized that it’s not an easy task if you don’t know where to look. You can probably find a couple of third party applications which can do the job for you. But if you are like me and you don’t want another piece of software sitting on your computer for a one time shot then this article is for you… keep reading…

Get your keyboards ready, we are going to use “PowerShell” or “Command Prompt”. We are going to use WMIC for this task. For more information about WMIC, click on the following link.

By using this command here in “CMD” or “PowerShell” you will get a list of all programs on your computer with their “Globally Unique Identifiers”.

wmic product list

After running this command, it can take a couple of seconds before you see the results so just be patient. Through my tests, the output format of PowerShell is way better than “CMD”. So if you can, stick with “PowerShell”. While this command gives you a summary with enough information on installed programs, you can use the following command to get even more information…

wmic product get

Now, what if you need to print this list? You can print this list into a text file by using the following command.

wmic product get > C:\InstalledPrograms.txt

What can I do with GUID?

GUID is very useful information if you are doing a lot of deployment tasks. Every MSI file has a GUID that we can use in order to reinstall or uninstall these programs. It’s a unique number for a software. This number is the same on every computer in the world. Let’s look at my case to give you an example. I needed to deploy the newest version of Java (Java 7u4). While it’s an easy task to deploy the new version, I had no clue how to uninstall the old version (Java 6u34) which was present on each computer in our network. So I came across with a couple of links that were explaining how to uninstall a program silently from computers with msiexec but it requires you to know and use the GUID of the application that you want to uninstall. I’ll be writing about how to deploy Java through your organization…

How to create a list of all installed programs?

This document was meant to explain issues with GUIDs but you can also use this information in order to create a list of all the installed programs without installing any 3rd party programs.