本文整理汇总了Java中com.sun.jna.platform.win32.WinBase.STARTUPINFO属性的典型用法代码示例。如果您正苦于以下问题:Java WinBase.STARTUPINFO属性的具体用法?Java WinBase.STARTUPINFO怎么用?Java WinBase.STARTUPINFO使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.sun.jna.platform.win32.WinBase
的用法示例。
在下文中一共展示了WinBase.STARTUPINFO属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startWithLogon
public void startWithLogon(final String cmd[] // can be null
) throws IOException {
// Merge the command array into a single string
final String lpCommandLine = this.internalMergeCommand(cmd);
try {
// Fill the security attributes
final WinBase.SECURITY_ATTRIBUTES sa = new WinBase.SECURITY_ATTRIBUTES();
sa.lpSecurityDescriptor = null;
sa.bInheritHandle = true;// true otherwise streams are not piped
sa.write();
// Create pipes
if (!(Kernel32.INSTANCE.CreatePipe(this.inRead, this.inWrite, sa, 0) &&
Kernel32.INSTANCE.CreatePipe(this.outRead, this.outWrite, sa, 0) && Kernel32.INSTANCE
.CreatePipe(this.errRead, this.errWrite, sa, 0))) {
throw win32ErrorIOException("CreatePipe");
}
final WinBase.STARTUPINFO si = new WinBase.STARTUPINFO();
si.dwFlags = WinBase.STARTF_USESHOWWINDOW | WinBase.STARTF_USESTDHANDLES;
si.hStdInput = this.inRead.getValue();
si.hStdOutput = this.outWrite.getValue();
si.hStdError = this.errWrite.getValue();
si.wShowWindow = new WinDef.WORD(0); // SW_HIDE
si.write();
final WinBase.PROCESS_INFORMATION pi = new WinBase.PROCESS_INFORMATION();
/////////////////////////////////////////////////////////////////////////////////////
// CreateProcessWithLogonW cannot be used since its parent process is svchost.exe and
// it breaks away from ProActive Agent job object.
/////////////////////////////////////////////////////////////////////////////////////
boolean result = MyAdvapi.INSTANCE.CreateProcessWithLogonW(
/* String */this.user, this.domain, this.password,
/* int */MyAdvapi.LOGON_WITH_PROFILE, // load user profile
/* String */null, // The name of the module to be executed
/* String */lpCommandLine, // The command line to be executed
/* int */WinBase.CREATE_NO_WINDOW | WinBase.CREATE_UNICODE_ENVIRONMENT, // creation flags
/* String */null, // the new process uses an environment created from the profile of the user
/* String */null, // the new process has the same current drive and directory as the calling process
/* WinBase.STARTUPINFO */si, // pointer to STARTUPINFO or STARTUPINFOEX structure
/* WinBase.PROCESS_INFORMATION */pi); // pointer to PROCESS_FORMATION structure
if (!result) {
throw win32ErrorIOException("CreateProcessWithLogon");
}
Kernel32.INSTANCE.CloseHandle(pi.hThread);
this.pid = pi.dwProcessId.intValue();
this.handle = pi.hProcess;
// Connect java-side streams
this.internalConnectStreams();
} catch (Exception ex) {
// Clean up the parent's side of the pipes in case of failure only
closeSafely(this.inWrite);
closeSafely(this.outRead);
closeSafely(this.errRead);
// If rethrow the internal IOException
if (ex instanceof IOException) {
throw (IOException) ex;
} else {
throw new IOException(ex);
}
} finally {
// Always clean up the child's side of the pipes
closeSafely(this.inRead);
closeSafely(this.outWrite);
closeSafely(this.errWrite);
}
}
示例2: CreateProcessAsUser
/**
* Creates a new process and its primary thread. The new process runs in the
* security context of the user represented by the specified token.
*
* Typically, the process that calls the CreateProcessAsUser function must
* have the SE_INCREASE_QUOTA_NAME privilege and may require the
* SE_ASSIGNPRIMARYTOKEN_NAME privilege if the token is not assignable. If
* this function fails with ERROR_PRIVILEGE_NOT_HELD (1314), use the
* CreateProcessWithLogonW function instead. CreateProcessWithLogonW
* requires no special privileges, but the specified user account must be
* allowed to log on interactively. Generally, it is best to use
* CreateProcessWithLogonW to create a process with alternate credentials.
*
* @param hToken
* A handle to the primary token that represents a user.
* @param lpApplicationName
* The name of the module to be executed.
* @param lpCommandLine
* The command line to be executed.
* @param lpProcessAttributes
* A pointer to a SECURITY_ATTRIBUTES structure that specifies a
* security descriptor for the new process object and determines
* whether child processes can inherit the returned handle to the
* process.
* @param lpThreadAttributes
* A pointer to a SECURITY_ATTRIBUTES structure that specifies a
* security descriptor for the new thread object and determines
* whether child processes can inherit the returned handle to the
* thread.
* @param bInheritHandles
* If this parameter is TRUE, each inheritable handle in the
* calling process is inherited by the new process. If the
* parameter is FALSE, the handles are not inherited. Note that
* inherited handles have the same value and access rights as the
* original handles.
* @param dwCreationFlags
* The flags that control the priority class and the creation of
* the process. For a list of values, see Process Creation Flags.
* @param lpEnvironment
* A pointer to an environment block for the new process. If this
* parameter is NULL, 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
* @param lpCurrentDirectory
* The full path to the current directory for the process. The
* string can also specify a UNC path.
* @param lpStartupInfo
* A pointer to a STARTUPINFO or STARTUPINFOEX structure.
* @param lpProcessInformation
* A pointer to a PROCESS_INFORMATION structure that receives
* identification information about the new process.
* @return If the function succeeds, the return value is nonzero. If the
* function fails, the return value is zero. To get extended error
* information, call GetLastError.
*/
public boolean CreateProcessAsUser(HANDLE hToken, String lpApplicationName,
String lpCommandLine, SECURITY_ATTRIBUTES lpProcessAttributes,
SECURITY_ATTRIBUTES lpThreadAttributes, boolean bInheritHandles,
int dwCreationFlags, String lpEnvironment,
String lpCurrentDirectory, WinBase.STARTUPINFO lpStartupInfo,
WinBase.PROCESS_INFORMATION lpProcessInformation);
示例3: CreateProcessWithLogonW
/**
* BOOL WINAPI CreateProcessWithLogonW( __in LPCWSTR lpUsername,
* __in_opt LPCWSTR lpDomain, __in LPCWSTR lpPassword, __in DWORD
* dwLogonFlags, __in_opt LPCWSTR lpApplicationName, __inout_opt LPWSTR
* lpCommandLine, __in DWORD dwCreationFlags, __in_opt LPVOID
* lpEnvironment, __in_opt LPCWSTR lpCurrentDirectory, __in
* LPSTARTUPINFOW lpStartupInfo, __out LPPROCESS_INFORMATION
* lpProcessInfo );
*/
boolean CreateProcessWithLogonW(String lpUsername, String lpDomain, String lpPassword,
int dwLogonFlags, String lpApplicationName, String lpCommandLine, int dwCreationFlags,
String lpEnvironment, String lpCurrentDirectory, WinBase.STARTUPINFO lpStartupInfo,
WinBase.PROCESS_INFORMATION lpProcessInfo);
示例4: CreateProcess
public boolean CreateProcess(String lpApplicationName, String lpCommandLine, WinBase.SECURITY_ATTRIBUTES lpProcessAttributes, WinBase.SECURITY_ATTRIBUTES lpThreadAttributes, WinDef.BOOL bInheritHandles, WinDef.DWORD dwCreationFlags, Pointer lpEnvironment, String lpCurrentDirectory, WinBase.STARTUPINFO lpStartupInfo, WinBase.PROCESS_INFORMATION lpProcessInformation);