![]() |
Languages »
VB.NET »
HowTo
Intermediate
License: The Code Project Open License (CPOL)
Running the Microsoft AppLocale Utility in an Automated Batch ScriptBy Austin RappaGetting AppLocale to run in a batch script |
VB (VB 7.x, VB 8.0, VB 9.0, VB 6), .NET (.NET 1.1, .NET 2.0, .NET 3.0, .NET 3.5), Visual Studio (VS.NET2003, VS2005, VS2008), Architect, Dev, Design
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
Run Microsoft AppLocale Utility successfully in a batch script by calling it with a wrapper written in .NET.
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.
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.
See the problem? How can we get around this? Well I am glad you asked.
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]
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:
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
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 30 Oct 2009 Editor: Deeksha Shenoy |
Copyright 2008 by Austin Rappa Everything else Copyright © CodeProject, 1999-2009 Web21 | Advertise on the Code Project |