Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
The Win32_Process Create method enables you to configure startup options for any new process running on a computer. For example, you can configure a process so that it starts in a "hidden" window, which prevents a user from seeing, and possibly interrupting, it. If the process runs in a command window, you can configure the size, title, and foreground and background colors of the window.
Startup options are configured using the Win32_ProcessStartup class. Win32_ProcessStartup is a Method Type class; the Method Type class exists solely to pass information to a method. In this case, all the properties of an instance of Win32_ProcessStartup are passed to an instance of Win32_Process.
To configure a startup option by using Win32_ProcessStartup:
For example, if you have created a Win32_ProcessStartup instance named objConfig, you would pass the object name in the Create method as follows:
errReturn = objProcess.Create(
"Database.exe
", null, objConfig, intProcessID)
A partial list of startup options that can be configured using the Win32_ProcessStartup class is shown in Table 14.3.
Table 14.3 Process Startup Properties Available Through the Win32_ProcessStartup Class
Startup Option | Description |
---|---|
FillAtrribute | Initial text and background colors if the process runs in a command window. These values are ignored in graphical user interface (GUI) applications. Valid values are: 1 Foreground blue 2 Foreground green 4 Foreground red 8 Foreground intensity 16 Background blue 32 Background green 64 Background red 128 Background intensity To specify both foreground and background colors, add the values together. For example, to have red type (4) on a blue background (16), set the FillAttribute to 20. |
PriorityClass | Priority class of the new process (used to determine the scheduling priorities of the threads in the process). Values are: 32 Normal 64 Low 128 High 16384 Below Normal 32768 Above Normal |
ShowWindow | State of the window as it appears to the user. Valid values are: 1 Window is shown minimized 3 Window is shown maximized 5 Window is shown in normal view 12 Window is hidden and not displayed to the user |
Title | Text to be displayed in the title bar of a command window where the process runs. If not specified, the name of the executable file is used as the window title instead. This property is ignored by processes that do not create a new command window. |
XCountChars | Screen buffer width in character columns. This property is used for processes that create a command window but is ignored in GUI processes. |
XSize | Width, in pixels, of the window, if a new window is created. |
YCountChars | Screen buffer height in character rows. This property is used for processes that create a command window but is ignored in GUI processes. |
YSize | Height, in pixels, of the window if a new window is created. |
You can use the Win32_ProcessStartup class to configure various startup options for a process. These options include, but are not limited to, such things as creating a process in a hidden window and creating a higher-priority process.
Listing 14.11 contains a script that creates a process in a hidden window. To carry out this task, the script must perform the following steps:
The first three parameters in the method specify the name of the executable file (such as Database.exe), the name of the startup folder (specifying Null gives the new process the same startup folder as the script that called the process), and the startup properties previously stored in objConfig.
The fourth parameter (intProcessID) is a variable that represents the Process ID assigned to the new process. You can use this ID to monitor and, if necessary, terminate the process programmatically. This is especially useful for a process that runs in a hidden window and thus provides no visual cue to indicate that it is still running.
Listing 14.11 Creating a Process in a Hidden Window
|
|
Listing 14.12 contains a script that creates a higher-priority process. To carry out this task, the script must perform the following steps:
The first three parameters in the method specify the name of the executable file (Database.exe), the name of the startup folder (specifying Null gives the new process the same startup folder as the script that called the process), and the startup properties previously stored in objConfig.
The fourth parameter (intProcessID) is a variable that represents the Process ID assigned to the new process. You can use this ID to monitor and, if necessary, terminate the process programmatically.
Listing 14.12 Creating a Higher-Priority Process
|
|
Send us your feedback | « Previous | Next » |