Debug | Conditionally output to the Windows debug output depending on whether the .debug property is set to true or not. |
Unconditionally output a string to the Windows debug output. | |
ErrorTrap | Callback method used to trap errors. |
FormatMessage | Converts an API error code into the associated error message. |
ToCString | Creates a new cstring from the passed string. |
FreeCstring | Safely frees a cstring reference variable. |
Ulong64ToReal | Converts an unsigned 64 bit integer to a Real |
GetReg | Returns the value of the specified registry key. |
PutReg | Sets the value of the specified registry key. |
displayErrors | Sets whether or not the class displays errors using the Message function. |
logErrors | Sets whether or not errors are sent to the Windows Debug Output |
errorCode | The last error code |
errorMessage | The last error message |
debug | Determines whether or not debug output is produced |
debugPrefix | The prefix used for debug output |
Parameter | Description |
---|---|
msg | A string containing the information to be sent to the debug output. The string will be prefixed with the contents of the .debugPrefix property. By default this is set to a string indicating which class output the error. |
Example |
---|
st JobObject code st.debug = glo:EnableDebug ! Example of a global setting to enable or disable debug output st.Debug('Debug output enabled') ! Will only be displayed if debug output is enabled. |
Parameter | Description |
---|---|
msg | The error message. |
err | The error code. If this is a Windows API error code, then the FormatMessage API is called to convert this to the associated error message. |
Parameter | Description |
---|---|
errorCode | The Windows API error code. |
Parameter | Description |
---|---|
s | The contents of this string will be stored in the returned cstring. The returned cstring is the same length as the contents of this string (the clipped length), plus one byte for the null terminator. |
Example |
---|
cs
&cstring s string(255) st ApiBase code s = 'Some String Value' cs &= st.ToCstring(s) ! use cstring here st.FreeCstring(cs) ! Safely free the cstring reference |
Parameter | Description |
---|---|
c | A cstring reference variable. |
Parameter | Description |
---|---|
lpi | A joLARGE_INTEGER group that contains a 64bit integer value to be converted. |
Parameter | Description |
---|---|
hKey | The root registry hive to retrieve the key value from. Can be
one of the following values: jo:HKEY_CLASSES_ROOT jo:HKEY_CURRENT_USER jo:HKEY_LOCAL_MACHINE jo:HKEY_USERS jo:HKEY_PERFORMANCE_DATA jo:HKEY_PERFORMANCE_TEXT jo:HKEY_PERFORMANCE_NLSTEXT jo:HKEY_CURRENT_CONFIG jo:HKEY_DYN_DATA |
sSubKeyPath | The path of the key to retrieve the value for. |
sValue | The name of the value to retrieve. |
Parameter | Description | |||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
hKey | The root registry hive. Can be one of the following values: jo:HKEY_CLASSES_ROOT jo:HKEY_CURRENT_USER jo:HKEY_LOCAL_MACHINE jo:HKEY_USERS jo:HKEY_PERFORMANCE_DATA jo:HKEY_PERFORMANCE_TEXT jo:HKEY_PERFORMANCE_NLSTEXT jo:HKEY_CURRENT_CONFIG jo:HKEY_DYN_DATA |
|||||||||||||||||||||||||||||||||||||||||||||
sSubKeyPath | The path of the key to set the value for. | |||||||||||||||||||||||||||||||||||||||||||||
sValueName | The name of the value to set. | |||||||||||||||||||||||||||||||||||||||||||||
sValue | The actual value to set the entry to | |||||||||||||||||||||||||||||||||||||||||||||
lType | The value type to set. Can be one of the following:
|
displayErrors long | Display errors to the user. Setting this to a non-zero value will cause the ErrorTrap() method to display any errors using the Message() function. |
logErrors long | Log errors to the system debug log. If this is non-zero, then errors are logged to the Windows debug log. See Debug for more information. |
errorCode long | The last error code. |
errorMsg string(512) | The last error message. |
debug long | Set to true to enable debug logging. If this is enabled, then calls to Debug() will output the passed string to the Windows debug output. |
debugPrefix cstring(12) | A prefix for debug output. This is set by each of the classes to a unique value to make reading and filtering the debug output easier. |
AddProcess | Add an existing (running) process to the Job. |
CloseAll | Close all processes associated with the current job. |
CreateJob | Create a new Job. Called automatically by the Init method. |
EndProcess | Terminate a running process. |
ExecuteFile | Run a file using the default application associated with it, or start a program |
GetCurrentUserToken | Gets the current User's token (which stores the users security attributes). |
GetInformation | Get information about the Job. |
GetProcessJobs | Fills the passed queue with all processes related to the current Job. |
GetSessions | Get a list of sessions on the current machine (log in users and system sessions). |
Init | Initialize the object, load the DLLs required, and optionally create a new Job Object. |
Kill | Terminate the Job, release all handles and free all memory allocated. |
KillProcess | Kill one or more processes with the specified name. |
LoadLibs | Load the libraries (DLLs) required for the functionality provided. |
LocateProcedure | Locate a procedure in a dynamically loaded library. |
LogonUser | Retrieves a the token representing the specified user. |
RunAsUser | Run a process as the currently logged in user. |
SetInformation | Set information (such as limits) for the current Job. |
CreateProcess | Start a process (processes are started as a part of the current Job by default). |
StoreProcessInfo | Store information related to a specific process. Called internally to update the Processes queue. |
AddEnv | Add an environment variable to the stored Environment block. |
ClearEnvironment | Clear the stored environment block |
ListProcesses | List all processes running on the system and stores them in a queue (much like the Windows task manager does). |
HandleFromPID | Returns the Process Handle when passed the Process ID (PID) |
GetProcessPath | Returns the full path to the executable for a process |
DeviceNameForDrive | Returns the full device name when passed the drive identifier (for example 'C:' or 'D:') |
GetDrives | Populates a queue with a list of all drives and their full NT Device Names. |
init | Set to 1 when the Init method is called successfully. If init is 0 all other functions will return immediately. |
hJob | Handle to the current API JobObject |
hProcess | Pseudo Handle to the process that create the job (and hence is the first process in the job by default) |
name | Name for the job |
env | String that stores the environment for passing to a new process. Contains null separate environment setting and is terminated by a pair of nulls |
envLen | The current environment length |
securityAttributes | The Security Attributes for the started Job |
basicAccounting | Basic account information for the job (memory usage, processes etc.) |
basicIoAndAccounting | Accounting information and IO (disk read/writes etc.) |
basicLimits | Job limits, including process and time limits, memory limitations, processor affinity, priority etc. |
basicProcessIdList | List of processes in the job |
basicUIRestrictions | Restricts creation of desktops, changing display settings, shutting down windows, clipboard access etc. |
extendedLimits | Memory limits (per process and job, peek memory usage etc.) |
securityLimits | Security limits (prevent admin token access etc.) |
completionPort | Associate a completion port with a job |
endTimeInfo | The action that the system will perform when the end-of-job time limit has been exceeded |
Processes | A queue of processes started in the current Job |
Parameter | Description |
---|---|
unsigned hProcess | A handle to the process to add to the current job. The process must not already be assigned to a job. |
Parameter | Description |
---|---|
pMask | A bit mask of the CPU's to bind the program to. Typically if
this is used it binds the program to a single CPU, however a
program can be bound to a subset of CPU's if you wish. If this value is 0 then the program will be bound to a single CPU, at random, from the CPU's available. If the computer only has a single CPU then this method has no effect. |
Parameter | Description |
---|---|
string JobName | The name of the job to create, or the name of an existing job to open. |
Parameter | Description |
---|---|
long procNum | The position in the Processes queue of the process to terminate. |
Parameter | Description |
---|---|
string fileName | The name of the file to open. |
Parameter | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
long infoClass | The information class for the limits to be queried. This
parameter can be one of the following values:
|
Parameter | Description |
---|---|
*joSessionInfo Sessions | A joSessionsInfo structure which stores the list of returned sessions. |
Parameter | Description |
---|---|
<string jobName> | If this is passed then a Job is created, otherwise the object is initialized, but no job is created. By default the current process is not assigned to the newly created job, unless the associateProcess parameter is set to 1 (true). |
long associateProcess= 0 | If this is set to a non zero value, the process that creates the job is also the first process assigned to the Job. This is limited by the security permissions for the current user. Important: If the current process becomes the first process in the Job, and will be affected by any calls to the methods that interact with the job. For example calling CloseAll or calling the Kill method will end this process, along with all other associated with the job |
Parameter | Description |
---|---|
processName | The handle to the library to load to the function from. |
killAll = true | Optional parameter. If set to False only the first instance found will be terminated. By default set to True and all matching processes are terminated. |
exactMatch = true | Optional parameter. Defaults to True which does a cases sensitive search for processes that match the exact process name passed. If set to False this will perform a case insensitive substring match and all processes whose names contain the passed processName string will be matched. For example passing processName as 'win' with exactMatch set to False would match: wininit.exe, winlogon.exe, winmerge.exe, searchwin.exe etc. For this reason setting exactmatch to False is not recommended unless the passed processName is a substring is specified that has a very low likelihood of terminating processes that are not intended to be terminated. |
Example |
---|
jo Class(JobObject) |
Parameter | Description |
---|---|
hLib | The handle to the library to load to the function from. |
procName | The name of the function to locate. |
Parameter | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
userName | The name of the user. This is the name of the user account to log on to. If you use the user principal name (UPN) format, user@DNS_domain_name, the domain parameter must be omitted. | ||||||||||||||||
domain | Specifies the name of the domain or server whose account database contains the username account. If this parameter is omitted, the user name must be specified in UPN format. If this parameter is ".", the function validates the account by using only the local account database. | ||||||||||||||||
password | Specifies the plaintext password for the user account specified by username. | ||||||||||||||||
phToken | A pointer to a handle which will be set to the token handle
is successful. You can use the returned handle in calls to the ImpersonateLoggedOnUser function. In most cases, the returned handle is a primary token that you can use in calls to the RunAsUser function. However, if you specify the jo:LOGON32_LOGON_NETWORK flag, LogonUser returns an impersonation token that you cannot use in RunAsUser unless you user the DuplicateTokenEx API to convert it to a primary token. When you no longer need this handle, close it by calling the CloseHandle method. |
||||||||||||||||
logonType | The type of logon to perform, defaults to
jo:LOGON32_LOGON_BATCH (4). May be one of the following:
|
||||||||||||||||
longonProvider | The logon provider, defaults to jo:LOGON32_PROVIDER_DEFAULT
(0). May be one of the following values:
|
Example |
---|
Parameter | Description |
---|---|
processPath | The name and path of the executable to run. |
arguments | Command line arguments to pass (can be an empty string). |
breakAwayFromJob | [optional] If a Job has been created, then this starts the process outside of the current Job |
dontStore | [optional] If set the process details won't be stored in the processes queue. |
phToken | [optional] Handle to a specific access token. If this is not specified, then the current user's token is used. Call LogonUser to get a specific user's token by authenticating using the user's name and password. Call GetSessions and GetToken under terminal server to get a token associated with a specific sessions (requires the relevant level of permission). |
Example |
---|
job.RunAsUser('someapp.exe', '') |
Parameter | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
long infoClass | The class of information to be updated. Determines which
properties of the class should be used to update the settings
for the Job. Can be one of the following:
|
Parameter | Description |
---|---|
string app | The name of the application that was started (and optionally the path). Can be empty if cmd contains the application name |
string cmd | The command line used, can be empty, or may contain the command line parameters, or may contain the full path, application name and any parameters passed (in which case app would be empty) |
string env | The environment block for the process. |
string dir | Starting directory |
*joPROCESS_INFORMATION pi | The API process information used in the process creation |
*joSTARTUPINFO si | The startup information returned by the process creation API |
HANDLE hRead = 0 | Optional handle to the standard output of the process for reading data from the process. Passed to WriteData. |
HANDLE hWrite = 0 | Optional handle to the standard input of the process for writing data to the process. Passed to ReadData. |
Parameter | Description |
---|---|
string pAppName | The name and path of the application to run, can include command line parameters and options |
ushort pMode | Allows the initial window mode to be specified. Can be one of: jo:SW_FORCEMINIMIZE Windows 2000/XP: Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when minimizing windows from a different thread. jo:SW_HIDE Hides the window and activates another window. jo:SW_MAXIMIZE Maximizes the specified window. jo:SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the Z order. jo:SW_RESTORE Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window. jo:SW_SHOW Activates the window and displays it in its current size and position. jo:SW_SHOWDEFAULT Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the jo:SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window. jo:SW_SHOWMINIMIZED Activates the window and displays it as a minimized window. jo:SW_SHOWMINNOACTIVE Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated. jo:SW_SHOWNA Displays the window in its current size and position. This value is similar to SW_SHOW, except the window is not activated. jo:SW_SHOWNOACTIVATE Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except the window is not activated. jo:SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time. |
byte pUseCMD=0 | Uses the cmd.exe to execute the passed file (for example if it is a batch file). |
<string pPath> | Optional specify the initial Path for the application (the directory that it should start in). |
<string pMessage> | Optional parameter allows a message window to be displayed while data is being read from the StdOut of the process. If pMessage and pTitle are omitted then no window will be displayed when reading data from the application. |
<string pTitle> | Optional parameter allows the title of the message window to be displayed while data is being read from the StdOut of the process. If pMessage and pTitle are omitted then no window will be displayed when reading data from the application. |
<*long pExitCommand> | Optional parameter. Stores the Exit value of the process. |
<*StringTheory strData> | An optional StringTheory object used for input and output. If this is passed with data then that data is written to the StdIn of the process. If a StringTheory object is passed with no data then nothing is written to the processes StdIn, however the process output will still be returned in the StringTheory object passed. |
long noRead = 0 | Optional parameter. If this is set to 1 then any data passed in the strData parameter will be written to the created process, however no output will be read from the process. This is useful when data only needs to be passed to the newly created process, which may not write anything back that needs to be read. |
long noStore = 0 | Optional parameter. If this is set to 1 then the process is called, and all handles are cleaned up once complete. No entry is added to the Processes queue. This is useful for process that will be called will terminate after the call. For example batch files, script processors, CGI application etc. Any process that will be called to perform a function and will exit on completion can be called with this parameter set to 1. If there is no job then no entries will be added to the queue, and this parameter has no affect (all processes are run without storing information relating to them). |
Parameter | Description |
---|---|
string pAppName | The name of the application to run |
<*StringTheory pOutput> | An optional StringTheory object used for input and output. If this is passed with data then that data is written to the StdIn of the process. If a StringTheory object is passed with no data then nothing is written to the processes StdIn, however the process output will still be returned in the StringTheory object passed. |
long noRead = 0 | Optional parameter. If this is set to 1 then any data passed in the strData parameter will be written to the created process, however no output will be read from the process. This is useful when data only needs to be passed to the newly created process, which may not write anything back that needs to be read. |
long noStore = 0 | Optional parameter. If this is set to 1 then the process is called, and all handles are cleaned up once complete. No entry is added to the Processes queue. This is useful for process that will be called will terminate after the call. For example batch files, script processors, CGI application etc. Any process that will be called to perform a function and will exit on completion can be called with this parameter set to 1. If there is no job then no entries will be added to the queue, and this parameter has no affect (all processes are run without storing information relating to them). |
long mode = 0 | Allows the initial window mode to be specified. Defaults to
SW_SHOW if not set. Can be one of: jo:SW_FORCEMINIMIZE Windows 2000/XP: Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when minimizing windows from a different thread. jo:SW_HIDE Hides the window and activates another window. jo:SW_MAXIMIZE Maximizes the specified window. jo:SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the Z order. jo:SW_RESTORE Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window. jo:SW_SHOW Activates the window and displays it in its current size and position. jo:SW_SHOWDEFAULT Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the jo:SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window. jo:SW_SHOWMINIMIZED Activates the window and displays it as a minimized window. jo:SW_SHOWMINNOACTIVE Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated. jo:SW_SHOWNA Displays the window in its current size and position. This value is similar to SW_SHOW, except the window is not activated. jo:SW_SHOWNOACTIVATE Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except the window is not activated. jo:SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time. |
Parameter | Description |
---|---|
string applicationName | The name of the module to be executed. This module can be a
Windows-based application. It can be some other type of module
(for example, MS-DOS or OS/2) if the appropriate subsystem is
available on the local computer. The string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path. If the file name does not contain an extension, .exe is assumed. Therefore, if the file name extension is .com, this parameter must include the .com extension. The applicationName parameter can be empty. In that case, the module name must be the first white space-delimited token in the commandLine string. If you are using a long file name that contains a space, use quoted strings to indicate where the file name ends and the arguments begin; otherwise, the file name is ambiguous. For example, consider the string "c:\program files\sub dir\program name". This string can be interpreted in a number of ways. The system tries to interpret the possibilities in the following order: c:\program.exe files\sub dir\program name c:\program files\sub.exe dir\program name c:\program files\sub dir\program.exe name c:\program files\sub dir\program name.exe If the executable module is a 16-bit application, applicationName should be empty, and the commandLine should specify the executable module as well as its arguments. To run a batch file, you must start the command interpreter; set applicationName to cmd.exe and set commandLine to the name of the batch file. |
string commandLine | The command line to be executed. The maximum length of this
string is 32K characters. If applicationName is empty, the
module name portion of commandLine is limited to
File:MaxFileName (260) characters. The commandLine parameter can be empty. In that case, the function uses the string pointed to by applicationName as the command line. If both applicationName and commandLine are non-empty, the applicationName specifies the module to execute, and the commandLine specifies the command line. If applicationName is empty, the first white-space – delimited token of the command line specifies the module name. If you are using a long file name that contains a space, use quoted strings to indicate where the file name ends and the arguments begin (see the explanation for the applicationName parameter). If the file name does not contain an extension, .exe is appended. Therefore, if the file name extension is .com, this parameter must include the .com extension. If the file name ends in a period (.) with no extension, or if the file name contains a path, .exe is not appended. If the file name does not contain a directory path, the system searches for the executable file in the following sequence: The directory from which the application loaded.
|
string currentDirectory | The full path to the current directory for the process. The
string can also specify a UNC path. If this parameter is empty, the new process will have the same current drive and directory as the calling process. (This feature is provided primarily for shells that need to start an application and specify its initial drive and working directory.) |
string environment | A pointer to the environment block for the new process. If
this parameter is an empty string, the new process uses the
environment of the calling process. An environment block consists of a null-terminated block of null-terminated strings. Each string is in the following form: 'name=value<0>' Because the equal sign is used as a separator, it must not be used in the name of an environment variable. Note that an environment block is terminated by two zero bytes: one for the last string, one more to terminate the block. |
long mode = 0 | Allows the initial window mode to be specified. Defaults to
SW_SHOW if not set. Can be one of: jo:SW_FORCEMINIMIZE Windows 2000/XP: Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when minimizing windows from a different thread. jo:SW_HIDE Hides the window and activates another window. jo:SW_MAXIMIZE Maximizes the specified window. jo:SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the Z order. jo:SW_RESTORE Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window. jo:SW_SHOW Activates the window and displays it in its current size and position. jo:SW_SHOWDEFAULT Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the jo:SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window. jo:SW_SHOWMINIMIZED Activates the window and displays it as a minimized window. jo:SW_SHOWMINNOACTIVE Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated. jo:SW_SHOWNA Displays the window in its current size and position. This value is similar to SW_SHOW, except the window is not activated. jo:SW_SHOWNOACTIVATE Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except the window is not actived. jo:SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time. |
Parameter | Description |
---|---|
string env | The name of the environment variable. This may NOT contain the equals sign character ('=') |
string val | The value for the variable |
long cgi=0 | If this is set then the function will automatically create this variable in CGI compatible format for use with CGI application. |
Parameter | Description |
---|---|
string sDrive | The drive to retrieve the NT Device Name for. Typically this does not have a trailing backslash, however the method will handle the trailing backslash if it exists. |
Parameter | Description |
---|---|
*joDrivesQType drivesQ | A queue that will be populated with a list of all drives on
the system (including mapped network drives, drives added using
the SUBST command etc.). The queue must match the joDrivesQType
type:
The drive property of the
queue is populated with the DOS drive name such as 'C:\',
while the deviceName property
is populated with the NT Device name such as
'\Device\HarddiskVolume1'. As the fields are Strings they may need clipping before use. |
Parameter | Description |
---|---|
**joProcessQType processList | A queue where the current record contains the process
information to query. Must be identical to the provided joProcessQType.:
|
Parameter | Description |
---|---|
*ulong PID | The PID (Process Identifier) of the process to retrieve a handle for. When ListProcesses is used to retrieve a list of all processes on the system the th32ProcessID property of the queue contains the PID of the process. |
Parameter | Description |
---|---|
*joProcessQType processList | The queue to populate with a list of all running processes. Must be identical to the provided joProcessQType. |
Parameter | Description |
---|---|
*JobProcessQ procq | The queue to populate with a list of all processes in the current Job. |