Click here to Skip to main content
Click here to Skip to main content

Running the Microsoft AppLocale Utility in an Automated Batch Script

, 30 Oct 2009
Rate this:
Please Sign up or sign in to vote.
Getting AppLocale to run in a batch script

Introduction

Run Microsoft AppLocale Utility successfully in a batch script by calling it with a wrapper written in .NET.

Background

The Microsoft AppLocale is a nifty utility that allows a program to run under a different system locale without having to reset the region settings and reboot the PC. This is ideal for applications, such as HTML Help Workshop, that require to be run under a target locale code. You can find more info about the utility here.

However there are two drawbacks to this utility if you want to use it in an automated batch script.

  • A nag screen appears when calling AppLocale from the command line.
  • AppLocale runs, spawns the called application in a child process, then quits while the child process is still active.

Luckily there is a patch/hack for AppLocale to remove the nag screen that can be found here.

The second issue is a bit more tricky because you want the spawned application to complete before continuing to the next batch command. For example, let's say we want a batch file to compile a Japanese language CHM file, then move it to a location on another computer.

  1. AppLocale will call HTML Help Workshop under the Japanese code page, and as soon as the application is launched, AppLocale will quit.
  2. HTML Help Workshop will begin to compile the CHM file.
  3. The batch file goes to its next command which is to move (a currently non-existent) CHM file... and we get file not found errors.
  4. Finally the CHM file is finished compiling and ready to be moved.

See the problem? How can we get around this? Well I am glad you asked.

Using the Code

What this code will do is launch AppLocale and grab its Windows Process ID, search for the running processes whose Parent Process ID is equal to AppLocale's Process ID, then wait for that process to end.

For our purposes, we want to create a command-line project in Visual Studio .NET. First we need to create a Process object to call AppLocale, then grab its Process ID which we can use to search for the child process that it launches. For StartInfo.Arguments we want to pass in the program we are calling, its arguments and local ID in the same style noted in the AppLocale documentation.

Dim procAppLoc As Process
Dim intAppLocID as Integer

'Create the AppLocale process object.
procAppLoc = New Process

'Set up the process
procAppLoc.StartInfo.FileName = "C:\Windows\AppPatch\AppLoc.exe"
procAppLoc.StartInfo.Arguments = Program we are calling, its arguments & local ID
procAppLoc.StartInfo.ErrorDialog = True
procAppLoc.EnableRaisingEvents = True

'Start the process
procAppLoc.Start()

'Get the AppLocale process ID
intAppLocID = procAppLoc.Id

'Wait for AppLocale to spawn the child process and exit
procAppLoc.WaitForExit()
procAppLoc.Dispose()

Next we use a Win32_Process object which gathers more information than the regular Process object, to search for the process that has a Parent Process ID equal to our AppLocale Process ID.

Dim objWMI As Object
Dim colItems As Object
Dim objItem As Object
Dim intChildProcessID As Integer

'Set up Win32_Process object
objWMI = GetObject("winmgmts:\\.\root\CIMV2")
colItems = objWMI.ExecQuery("SELECT * FROM Win32_Process", "WQL")

'Find the child process and retrieve its ID value
intChildProcessID = -1
For Each objItem In colItems
   If objItem.ParentProcessId = intAppLocID Then
      intChildProcessID = objItem.ProcessId
   End If
Next

So now that we found the Process ID of the application that AppLocale launched, we can place this into a Process object and wait for it to exit before continuing.

Dim procChild As Process

If intChildProcessID > -1 Then
   'Get the child process object
   procChild = Process.GetProcessById(intChildProcessID)

   'Wait for the child process to exit
   procChild.WaitForExit()
   procChild.Dispose()
End If

Now the program we have created will wait for the spawned child process to end before it ends itself and the batch script can move to the next command.

Once AppLocale is installed, the AppLocale executable file is patched and this code is compiled. You can now call this program instead of calling AppLocale with the same set of arguments.

MyAppLocWrapper.exe program [arguments] /L[local id]

Points of Interest

There is another alternative to AppLocale, and that is SBAppLocale. It did not work for our needs but that doesn't mean it won't work for you and I would suggest considering it as an option. You can find information about SBAppLocale here.

One thing I noticed is that AppLocale can be very finicky when being called from the command line. Here are a few points to note:

  • AppLocale can only call executables and not batch files.
  • Pass in all of the program arguments surrounded by quotes.
  • Always use absolute paths.
  • If you see the GUI window appear, it probably means it didn't like what was input.
  • Always delete the C:\Windows\AppPatch\AppLoc.tmp file to ensure a clean run.
  • In Control Panel > Regional and Language Options > Language tab, check all boxes in the "Supplemental language support" section.

A trick to get around not being able to launch a batch file is to run AppLocale with cmd.exe as the called program like this:

C:\Windows\AppPatch\AppLoc.exe C:\WINDOWS\system32\cmd.exe "/c
C:\Scripts\MyBatchFile.bat FakeParameter1" /L1041

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Austin Rappa
Software Developer (Senior) Symantec Corp.
United States United States
Austin likes to play football, go surfing, bar hopping, sing karaoke, and play Guitar Hero and Wii.

Comments and Discussions

 
QuestionAppLocale wrapper for SendTo links? PinmemberAlexander Firestone8-May-08 2:22 
AnswerRe: AppLocale wrapper for SendTo links? PinmemberAustin Rappa14-May-08 8:53 
GeneralRe: AppLocale wrapper for SendTo links? PinmemberAlexander Firestone14-May-08 10:37 
GeneralRe: AppLocale wrapper for SendTo links? PinmemberAustin Rappa14-May-08 11:06 
AnswerRe: AppLocale wrapper for SendTo links? PinmemberAustin Rappa22-May-08 12:19 
GeneralRe: AppLocale wrapper for SendTo links? PinmemberAlexander Firestone22-May-08 12:55 
I always install East Asian Languages because I deal a lot with Japanese. I have no problems displaying Japanese on my system and using AppLocale directly works fine.
GeneralRe: AppLocale wrapper for SendTo links? PinmemberMirko Plitt1-Dec-08 22:35 
AnswerRe: AppLocale wrapper for SendTo links? PinmemberMirko Plitt3-Dec-08 22:11 
GeneralRe: AppLocale wrapper for SendTo links? Pinmemberspamfighter21-Jun-10 11:06 
GeneralWhy not... PinmemberSlimFast200025-Apr-08 1:41 
GeneralRe: Why not... [modified] PinmemberAustin Rappa29-Apr-08 9:29 
GeneralSBAppLocale PinmemberSteveKing24-Apr-08 19:23 
GeneralRe: SBAppLocale PinmemberAustin Rappa24-Apr-08 20:28 
GeneralRe: SBAppLocale PinmemberSteveKing25-Apr-08 4:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 30 Oct 2009
Article Copyright 2008 by Austin Rappa
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid