Monthly Archives: August 2007

  • 0

How To Wait As Long As A Program (And Its Sub Processes) Are Running? #Batch

Category : Scripting Technique

Recently, some talented colleagues of Login Consultants and I worked out a robust batch subroutine that waits for the termination of a setup (or whatever) program including those processes that have been started by that program.

In most cases the START /WAIT command meets the requirement that is to stop batch processing as long as the (setup) program is running. For example, this works fine for MSI based installations. All you have to do is START /WAIT msiexec.exe … and you’re done. The same applies to other installer types like Inno, Wise, or NSIS.

But many InstallShield setups and proprietary setups (like the Oracle installer) do actually nothing more than to call a second process (javaw.exe in case of Oracle) and terminate immediately afterwards. Since START /WAIT does only watch over the specified program it would pass back script control to cmd.exe although the actual setup isn’t yet finished.

TASKLIST.EXE is an external command of Windows XP Professional, Windows Server 2003, and newer. It displays a list of processes and services with their Process ID (PID) for all tasks. Using filters you can query for a specific process.

The batch file below, Start-Wait.cmd, uses TASKLIST.EXE. Before actually starting the specified program Start-Wait.cmd gets the PIDs of all processes that have the same name like the specified sub process (for example javaw.exe). This step is important in order to make sure that the script later checks the correct sub process. Let’s say that you want the script to check javaw.exe as a sub process of the Oracle installer on a Citrix terminal server. Maybe at the same time you have started the Management Console (which is based on javaw.exe)… Got it? Talking of terminal servers: Start-Wait.cmd cuts TASKLIST.EXE‘s output down to the processes owned by the user who is executing the script. When done with making out the ignorable PIDs the script start the specified program. Afterwards it uses TASKLIST.EXE again in order to identify the PID of the specified sub process. Finally, the Start-Wait.cmd checks each 5 seconds if the process with that PID is still running.


  • 0

Active Directory Login Script Template #VBScript

The login script template provided in this article maps network drives and printers based on the user’s membership in so-called “map groups”. Since a map group delivers the information which resource should be mapped for its members, you hardly ever need to modify this script due to changes in the drive or printer mappings.

For each drive and printer mapping you need to create an according AD group that follows an naming convention. By default, a map group for a network drive begins with “MAP-DRV-“, and the prefix for a network printer map group is “MAP-PRN-“. (Both prefixes can be customized by changing the constants MAP_DRIVE_GROUP_PREFIX and MAP_PRINTER_GROUP_PREFIX in this script.)

In addition to follow the naming convention you have to specify the network resources that should be mapped in the description field of a map group. In case of the map group for a network drive you must specify the drive letter followed by the unc path (seperated by a space character). In case of the printer map group you must specify the network printer’s unc path.

Since the script recognized indirect or nested group memberships you are able to add users as well as groups to the map groups. The LoadGroups function contains slightly modified code that I found on Richard L. Mueller’s website (http://www.rlmueller.net), Thanks.