- Vytvoril/a D2000 Dev Team, naposledy zmenil/a D2000 Doc Team dňa dec 30, 2021
%StartProcess function
Function
Function creates a new process. The new process then runs the specified executable file in the security context of the specified credentials (user, domain, and password).
Declaration
INT %StartProcess( TEXT in userName, TEXT in domain, TEXT in password, TEXT in applName, TEXT in commandLine, TEXT in currDir, BOOL in bSync, INT in timeout, BOOL in bHide )
Note
userName | String specifying the name of the user. This is the name of the user account to log on to. If you use the UPN format, user@DNS_domain_name, domain parameter must be an empty string. The user account must have the Log On Locally permission on the local computer. This permission is granted to all users on workstations and servers, but only to administrators on domain controllers. It only can be used for the Windows XP, Windows 2000 Professional, Windows Server 2003 or Windows 2000 Server platforms. For other platforms, the function returns an invalid value. If the parameter is an empty string, the process is started in the context of the user, who opens the calling process. Such a call can be also used for another MS Windows platform. |
domain | String specifying the name of the domain or server whose account database contains the userName account. If this parameter is an empty string, the user name must be specified in the UPN format. |
password | String specifying the clear-text password for the userName account. |
applName | String specifying the module to execute. The specified 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. 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 applName parameter can be an empty string. 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:
If the executable module is a 16-bit application, applName should be empty string, and the string commandLine should specify the executable module as well as its arguments. |
commandLine | String specifying the command line to execute. The commandLine parameter can be an empty string. In that case, the function uses the string applName as the command line. If both applName and commandLine are non-empty strings, applName specifies the module to execute, and commandLine specifies the command line. The new process can use GetCommandLine (Win32 API) to retrieve the entire command line. Console processes written in C can use the argc and argv arguments to parse the command line. Because argv[0] is the module name, C programmers generally repeat the module name as the first token in the command line. If applName is an empty string, the first white-space – delimited token of the command line specifies the module name. If you are using a long file name containing a space, use quoted strings to indicate where the file name ends and the arguments begin (see the explanation for the applName 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:
|
currDir | String specifying the current drive and directory for the new process. The string must be a full path which includes a drive letter. If this parameter is an empty string, the new process has the same current drive as the system service that creates the process. (This feature is provided primarily for shells that need to start an application and specify its initial drive and working directory.) |
bSync | The parameter specifies, whether the script waits for termination of the started process.
|
timeout | The maximum runtime of the started process. The parameter can be used only when bSync=@TRUE. |
bHide | Boolean type parameter - possible values:
|
Return value
Return value is Int type and
- is invalid if were unable to run the process
- is equal to the value of _ERR_TIME_OUT, if bSync=@TRUE and the timeout was exceeded
- is equal to 0, if bSync=@FALSE and the process has been started
- otherwise it gets the value of the return code of the process
Note
If unsuccessful, the function writes an error log to the file event.log.
Example
Starting the MS Excel program with opening the file C:\TEMP\WorkBook1.xls.
MS Excel has been installed into C:\Program Files\/Microsoft Office\Office\excel.exe.
Name of the local user is Adm and the password is pwd.
BEGIN TEXT _cmdLine INT _retCode _cmdLine := %Chr(34) + "c:\Program Files\Microsoft Office\Office10\EXCEL.EXE" + %Chr(34) + "c:\temp\Workbook1.xls" _retCode := %StartProcess("Adm", "", "pwd", "", _cmdLine, "c:\temp", @TRUE, 30, @FALSE) IF _retCode\VLD THEN IF _retCode = _ERR_TIME_OUT THEN ; MS Excel was not terminated in the timeout of 30 seconds and was enforced to close ELSE ; MS Excel was terminated in the timeout of 30 seconds and _retCode contains the return code ENDIF ELSE ; cannot to start the program ; the path c:\Program Files\Microsoft Office\Office10\EXCEL.EXE doesn't exist, or cannot log on the user ENDIF END
Related pages:
0 komentárov