本文整理汇总了C++中CreateProcessW函数的典型用法代码示例。如果您正苦于以下问题:C++ CreateProcessW函数的具体用法?C++ CreateProcessW怎么用?C++ CreateProcessW使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CreateProcessW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: procRun
enum procerr
procRun(unsigned xnargs, char * const xargs[], int * rc)
{
STARTUPINFOW si;
PROCESS_INFORMATION pi;
enum procerr err = ERR_PROC_OK;
DWORD drc = 0;
WCHAR args[MAXCMD];
LPWSTR cl = GetCommandLineW();
int argc;
LPWSTR * wargv = CommandLineToArgvW(cl, &argc);
argvToCommandLine(args, argc-4, wargv+4);
LocalFree(wargv);
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
CHK(ERR_PROC_FORK, !CreateProcessW(0, args, 0, 0, 0, CREATE_SUSPENDED, 0, 0, &si, &pi));
if (err == ERR_PROC_OK)
injectProcess(pi.hProcess);
CHK(ERR_PROC_EXEC, -1 == ResumeThread(pi.hThread));
CHK(ERR_PROC_WAIT, WAIT_OBJECT_0 != WaitForSingleObject(pi.hThread, INFINITE));
CHK(ERR_PROC_WAIT, WAIT_OBJECT_0 != WaitForSingleObject(pi.hProcess, INFINITE));
CHK(ERR_PROC_WAIT, !GetExitCodeProcess(pi.hProcess, &drc));
CHK(ERR_PROC_FORK, !CloseHandle(pi.hThread));
CHK(ERR_PROC_FORK, !CloseHandle(pi.hProcess));
if (err == ERR_PROC_OK)
*rc = drc;
return err;
}
示例2: __declspec
//Called before StarCraft is completely loaded
extern "C" __declspec(dllexport) bool ApplyPatchSuspended(HANDLE, DWORD)
{
if (GetFileAttributesW(WLAUNCHER) == 0xFFFFFFFF)
{
MessageBoxW(NULL, L"wLauncher.exe not found!", L"wDetector Plugin", MB_OK | MB_ICONERROR);
return false;
}
if (GetFileAttributesW(WDETECTOR) == 0xFFFFFFFF)
{
MessageBoxW(NULL, L"wDetector.w not found!", L"wDetector Plugin", MB_OK | MB_ICONERROR);
return false;
}
if (wcscmp(FileVersion(WDETECTOR), L"3.37") != 0)
{
MessageBoxW(NULL, L"wDetector's version is incorrect!", L"wDetector Plugin", MB_OK | MB_ICONERROR);
return false;
}
STARTUPINFOW info = { sizeof(info) };
if (!CreateProcessW(WLAUNCHER, NULL, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))
{
MessageBoxW(NULL, L"Failed to start wLauncher.exe!", L"wDetector Plugin", MB_OK | MB_ICONERROR);
return false;
}
return true;
}
示例3: runCmd
/**
* This function runs the specified command in the specified dir.
* [in,out] cmdline - the command line to run. The function may change the passed buffer.
* [in] dir - the dir to run the command in. If it is NULL, then the current dir is used.
* [in] wait - whether to wait for the run program to finish before returning.
* [in] minimized - Whether to ask the program to run minimized.
*
* Returns:
* If running the process failed, returns INVALID_RUNCMD_RETURN. Use GetLastError to get the error code.
* If wait is FALSE - returns 0 if successful.
* If wait is TRUE - returns the program's return value.
*/
static int runCmd(LPWSTR cmdline, LPCWSTR dir, BOOL wait, BOOL minimized)
{
STARTUPINFOW si;
PROCESS_INFORMATION info;
DWORD exit_code=0;
memset(&si, 0, sizeof(si));
si.cb=sizeof(si);
if (minimized)
{
si.dwFlags=STARTF_USESHOWWINDOW;
si.wShowWindow=SW_MINIMIZE;
}
memset(&info, 0, sizeof(info));
if (!CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, dir, &si, &info))
{
printf("Failed to run command (%ld)\n", GetLastError());
return INVALID_RUNCMD_RETURN;
}
printf("Successfully ran command\n"); //%s - Created process handle %p\n",
//wine_dbgstr_w(cmdline), info.hProcess);
if (wait)
{ /* wait for the process to exit */
WaitForSingleObject(info.hProcess, INFINITE);
GetExitCodeProcess(info.hProcess, &exit_code);
}
CloseHandle(info.hProcess);
return exit_code;
}
示例4: start_rpcss
static BOOL start_rpcss(void)
{
PROCESS_INFORMATION pi;
STARTUPINFOW si;
WCHAR cmd[MAX_PATH];
static const WCHAR rpcss[] = {'\\','r','p','c','s','s','.','e','x','e',0};
BOOL rslt;
void *redir;
TRACE("\n");
ZeroMemory(&si, sizeof(STARTUPINFOA));
si.cb = sizeof(STARTUPINFOA);
GetSystemDirectoryW( cmd, MAX_PATH - sizeof(rpcss)/sizeof(WCHAR) );
strcatW( cmd, rpcss );
Wow64DisableWow64FsRedirection( &redir );
rslt = CreateProcessW( cmd, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi );
Wow64RevertWow64FsRedirection( redir );
if (rslt)
{
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
Sleep(100);
}
return rslt;
}
示例5: openvpn_execve
/*
* Attempt to simulate fork/execve on Windows
*/
int
openvpn_execve (const struct argv *a, const struct env_set *es, const unsigned int flags)
{
int ret = -1;
static bool exec_warn = false;
if (a && a->argv[0])
{
if (openvpn_execve_allowed (flags))
{
struct gc_arena gc = gc_new ();
STARTUPINFOW start_info;
PROCESS_INFORMATION proc_info;
char *env = env_block (es);
WCHAR *cl = wide_cmd_line (a, &gc);
WCHAR *cmd = wide_string (a->argv[0], &gc);
CLEAR (start_info);
CLEAR (proc_info);
/* fill in STARTUPINFO struct */
GetStartupInfoW(&start_info);
start_info.cb = sizeof(start_info);
start_info.dwFlags = STARTF_USESHOWWINDOW;
start_info.wShowWindow = SW_HIDE;
/* this allows console programs to run, and is ignored otherwise */
DWORD proc_flags = CREATE_NO_WINDOW;
if (CreateProcessW (cmd, cl, NULL, NULL, FALSE, proc_flags, env, NULL, &start_info, &proc_info))
{
DWORD exit_status = 0;
CloseHandle (proc_info.hThread);
WaitForSingleObject (proc_info.hProcess, INFINITE);
if (GetExitCodeProcess (proc_info.hProcess, &exit_status))
ret = (int)exit_status;
else
msg (M_WARN|M_ERRNO, "openvpn_execve: GetExitCodeProcess %S failed", cmd);
CloseHandle (proc_info.hProcess);
}
else
{
msg (M_WARN|M_ERRNO, "openvpn_execve: CreateProcess %S failed", cmd);
}
free (env);
gc_free (&gc);
}
else if (!exec_warn && (script_security < SSEC_SCRIPTS))
{
msg (M_WARN, SCRIPT_SECURITY_WARNING);
exec_warn = true;
}
}
else
{
msg (M_WARN, "openvpn_execve: called with empty argv");
}
return ret;
}
示例6: MyCreateProcessW
static BOOL WINAPI
MyCreateProcessW(LPCWSTR lpApplicationName,
LPWSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCWSTR lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation)
{
if (VERBOSITY >= 2) {
debugPrintf("inject: intercepting %s(\"%S\", \"%S\", ...)\n",
__FUNCTION__,
lpApplicationName,
lpCommandLine);
}
BOOL bRet;
bRet = CreateProcessW(lpApplicationName,
lpCommandLine,
lpProcessAttributes,
lpThreadAttributes,
bInheritHandles,
dwCreationFlags | CREATE_SUSPENDED,
lpEnvironment,
lpCurrentDirectory,
lpStartupInfo,
lpProcessInformation);
MyCreateProcessCommon(bRet, dwCreationFlags, lpProcessInformation);
return bRet;
}
示例7: MakeUpdaterCommandLine
void AutoUpdateChecker::TriggerUpdate(const AutoUpdateChecker::NewVersionInformation& info)
{
#ifdef _WIN32
std::map<std::string, std::string> updater_flags;
updater_flags["this-manifest-url"] = info.this_manifest_url;
updater_flags["next-manifest-url"] = info.next_manifest_url;
updater_flags["content-store-url"] = info.content_store_url;
updater_flags["parent-pid"] = std::to_string(GetCurrentProcessId());
updater_flags["install-base-path"] = File::GetExeDirectory();
updater_flags["log-file"] = File::GetExeDirectory() + DIR_SEP + UPDATER_LOG_FILE;
// Copy the updater so it can update itself if needed.
std::string updater_path = File::GetExeDirectory() + DIR_SEP + UPDATER_FILENAME;
std::string reloc_updater_path = File::GetExeDirectory() + DIR_SEP + UPDATER_RELOC_FILENAME;
File::Copy(updater_path, reloc_updater_path);
// Run the updater!
std::wstring command_line = MakeUpdaterCommandLine(updater_flags);
STARTUPINFO sinfo = {sizeof(info)};
PROCESS_INFORMATION pinfo;
INFO_LOG(COMMON, "Updater command line: %s", UTF16ToUTF8(command_line).c_str());
if (!CreateProcessW(UTF8ToUTF16(reloc_updater_path).c_str(),
const_cast<wchar_t*>(command_line.c_str()), nullptr, nullptr, FALSE, 0,
nullptr, nullptr, &sinfo, &pinfo))
{
ERROR_LOG(COMMON, "Could not start updater process: error=%d", GetLastError());
}
#endif
}
示例8: MyCreateProcessW
BOOL WINAPI MyCreateProcessW( LPCWSTR lpApplicationName,
LPWSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCWSTR lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation )
{
PROCESS_INFORMATION pi;
if (!CreateProcessW( lpApplicationName,
lpCommandLine,
lpThreadAttributes,
lpProcessAttributes,
bInheritHandles,
dwCreationFlags | CREATE_SUSPENDED,
lpEnvironment,
lpCurrentDirectory,
lpStartupInfo,
&pi ))
return FALSE;
DEBUGSTR( L"CreateProcessW: \"%s\", \"%s\"",
(lpApplicationName == NULL) ? L"" : lpApplicationName,
(lpCommandLine == NULL) ? L"" : lpCommandLine );
Inject( &pi, lpProcessInformation, dwCreationFlags );
return TRUE;
}
示例9: Exec
DWORD Exec(MSIHANDLE hModule,
const WCHAR *pwszAppName, WCHAR *pwszCmdLine, const WCHAR *pwszWorkDir,
DWORD *pdwExitCode)
{
STARTUPINFOW si;
PROCESS_INFORMATION pi;
DWORD rc = ERROR_SUCCESS;
ZeroMemory(&si, sizeof(si));
si.dwFlags = STARTF_USESHOWWINDOW;
#ifdef UNICODE
si.dwFlags |= CREATE_UNICODE_ENVIRONMENT;
#endif
si.wShowWindow = SW_HIDE; /* For debugging: SW_SHOW; */
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
logStringW(hModule, L"Executing command line: %s %s (Working Dir: %s)",
pwszAppName, pwszCmdLine, pwszWorkDir == NULL ? L"Current" : pwszWorkDir);
SetLastError(0);
if (!CreateProcessW(pwszAppName, /* Module name. */
pwszCmdLine, /* Command line. */
NULL, /* Process handle not inheritable. */
NULL, /* Thread handle not inheritable. */
FALSE, /* Set handle inheritance to FALSE .*/
0, /* No creation flags. */
NULL, /* Use parent's environment block. */
pwszWorkDir, /* Use parent's starting directory. */
&si, /* Pointer to STARTUPINFO structure. */
&pi)) /* Pointer to PROCESS_INFORMATION structure. */
{
rc = GetLastError();
logStringW(hModule, L"Executing command line: CreateProcess() failed! Error: %ld", rc);
return rc;
}
/* Wait until child process exits. */
if (WAIT_FAILED == WaitForSingleObject(pi.hProcess, 30 * 1000 /* Wait 30 secs max. */))
{
rc = GetLastError();
logStringW(hModule, L"Executing command line: WaitForSingleObject() failed! Error: %u", rc);
}
else
{
if (!GetExitCodeProcess(pi.hProcess, pdwExitCode))
{
rc = GetLastError();
logStringW(hModule, L"Executing command line: GetExitCodeProcess() failed! Error: %u", rc);
}
}
/* Close process and thread handles. */
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
logStringW(hModule, L"Executing command returned: %u (exit code %u)", rc, *pdwExitCode);
return rc;
}
示例10: system
/*
** Implementation of system() - requires wide char conversion
*/
RTEXP int system( const char *command ) {
wchar_t wcmdline[BUFSIZ];
BOOL ret;
PROCESS_INFORMATION pi;
MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, command, -1, wcmdline, BUFSIZ);
ret = CreateProcessW(wcmdline, NULL, NULL, NULL, (BOOL)NULL, CREATE_NEW_CONSOLE, NULL, NULL, NULL, &pi);
return(0);
}
示例11: fork
void SessionProcess::exec(const Configuration& config,
boost::function<void (bool)> onReady)
{
#ifndef WT_WIN32
std::string parentPortOption = std::string("--parent-port=")
+ boost::lexical_cast<std::string>(acceptor_->local_endpoint().port());
const std::vector<std::string> &options = config.options();
const char **c_options = new const char*[options.size() + 2];
std::size_t i = 0;
for (; i < options.size(); ++i) {
c_options[i] = options[i].c_str();
}
c_options[i] = parentPortOption.c_str();
++i;
c_options[i] = 0;
pid_ = fork();
if (pid_ < 0) {
LOG_ERROR("failed to fork dedicated session process, error code: " << errno);
stop();
if (!onReady.empty()) {
onReady(false);
}
return;
} else if (pid_ == 0) {
#ifdef WT_THREADED
sigset_t mask;
sigfillset(&mask);
pthread_sigmask(SIG_UNBLOCK, &mask, 0);
#endif // WT_THREADED
execv(c_options[0], const_cast<char *const *>(c_options));
// An error occurred, this should not be reached
exit(1);
}
delete[] c_options;
#else // WT_WIN32
STARTUPINFOW startupInfo;
ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
std::wstring commandLine = GetCommandLineW();
commandLine += L" --parent-port=" + boost::lexical_cast<std::wstring>(acceptor_->local_endpoint().port());
LPWSTR c_commandLine = new wchar_t[commandLine.size() + 1];
wcscpy(c_commandLine, commandLine.c_str());
if(!CreateProcessW(0, c_commandLine, 0, 0, true,
0, 0, 0, &startupInfo, &processInfo_)) {
LOG_ERROR("failed to start dedicated session process, error code: " << GetLastError());
stop();
if (!onReady.empty()) {
onReady(false);
}
}
delete c_commandLine;
#endif // WT_WIN32
}
示例12: service_start_process
static DWORD service_start_process(struct service_entry *service_entry, HANDLE *process)
{
PROCESS_INFORMATION pi;
STARTUPINFOW si;
LPWSTR path = NULL;
DWORD size;
BOOL r;
service_lock_exclusive(service_entry);
if (service_entry->config.dwServiceType == SERVICE_KERNEL_DRIVER)
{
static const WCHAR winedeviceW[] = {'\\','w','i','n','e','d','e','v','i','c','e','.','e','x','e',' ',0};
DWORD len = GetSystemDirectoryW( NULL, 0 ) + sizeof(winedeviceW)/sizeof(WCHAR) + strlenW(service_entry->name);
if (!(path = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
return ERROR_NOT_ENOUGH_SERVER_MEMORY;
GetSystemDirectoryW( path, len );
lstrcatW( path, winedeviceW );
lstrcatW( path, service_entry->name );
}
else
{
size = ExpandEnvironmentStringsW(service_entry->config.lpBinaryPathName,NULL,0);
path = HeapAlloc(GetProcessHeap(),0,size*sizeof(WCHAR));
if (!path)
return ERROR_NOT_ENOUGH_SERVER_MEMORY;
ExpandEnvironmentStringsW(service_entry->config.lpBinaryPathName,path,size);
}
ZeroMemory(&si, sizeof(STARTUPINFOW));
si.cb = sizeof(STARTUPINFOW);
if (!(service_entry->config.dwServiceType & SERVICE_INTERACTIVE_PROCESS))
{
static WCHAR desktopW[] = {'_','_','w','i','n','e','s','e','r','v','i','c','e','_','w','i','n','s','t','a','t','i','o','n','\\','D','e','f','a','u','l','t',0};
si.lpDesktop = desktopW;
}
service_entry->status.dwCurrentState = SERVICE_START_PENDING;
service_unlock(service_entry);
r = CreateProcessW(NULL, path, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
HeapFree(GetProcessHeap(),0,path);
if (!r)
{
service_lock_exclusive(service_entry);
service_entry->status.dwCurrentState = SERVICE_STOPPED;
service_unlock(service_entry);
return GetLastError();
}
service_entry->status.dwProcessId = pi.dwProcessId;
*process = pi.hProcess;
CloseHandle( pi.hThread );
return ERROR_SUCCESS;
}
示例13: ZeroMemory
DWORD KCallInfocSend::_LaunchAppEx(LPCWSTR lpczApp, LPWSTR lpszCmdLine, BOOL bWait, PDWORD pdwExitCode/*=NULL*/, BOOL bShowWnd/*=TRUE*/)
{
DWORD dwResult = -1;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
si.dwFlags = STARTF_USESHOWWINDOW;
if (bShowWnd == FALSE)
si.wShowWindow = SW_HIDE;
else
si.wShowWindow = SW_SHOW;
// Start the child process.
if ( !CreateProcessW(
lpczApp,
lpszCmdLine,
NULL,
NULL,
TRUE,
0,
NULL,
NULL,
&si,
&pi)
)
{
dwResult = GetLastError();
OutputDebugString(L"_LaunchAppEx:error");
goto Exit0;
}
if (bWait)
{
if (WaitForSingleObject(pi.hProcess, defMAXWAITPROCESSTIME) == WAIT_OBJECT_0)
if (pdwExitCode)
GetExitCodeProcess(pi.hProcess, pdwExitCode);
}
dwResult = 0;
Exit0:
if (pi.hProcess != NULL)
{
CloseHandle(pi.hProcess);
pi.hProcess = NULL;
}
if (pi.hThread != NULL)
{
CloseHandle(pi.hThread);
pi.hThread = NULL;
}
return dwResult;
}
示例14: GetCurrentDirectoryW
bool CResourceCompilerHelper::InvokeResourceCompiler( const char *szSrcFile, const bool bWindow ) const
{
bool bRet = true;
// make command for execution
wchar_t wMasterCDDir[512];
GetCurrentDirectoryW(512,wMasterCDDir);
SettingsManagerHelpers::CFixedString<wchar_t, 512> wRemoteCmdLine;
SettingsManagerHelpers::CFixedString<wchar_t, 512> wDir;
wRemoteCmdLine.appendAscii("Bin32/rc/");
wRemoteCmdLine.appendAscii(RC_EXECUTABLE);
wRemoteCmdLine.appendAscii(" \"");
wRemoteCmdLine.append(wMasterCDDir);
wRemoteCmdLine.appendAscii("\\");
wRemoteCmdLine.appendAscii(szSrcFile);
wRemoteCmdLine.appendAscii("\" /userdialog=0");
wDir.append(wMasterCDDir);
wDir.appendAscii("\\Bin32\\rc");
STARTUPINFOW si;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
si.dwX = 100;
si.dwY = 100;
si.dwFlags = STARTF_USEPOSITION;
PROCESS_INFORMATION pi;
ZeroMemory( &pi, sizeof(pi) );
if (!CreateProcessW(
NULL, // No module name (use command line).
const_cast<wchar_t*>(wRemoteCmdLine.c_str()), // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
bWindow?0:CREATE_NO_WINDOW, // creation flags.
NULL, // Use parent's environment block.
wDir.c_str(), // Set starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi)) // Pointer to PROCESS_INFORMATION structure.
{
bRet = false;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return bRet;
}
示例15: CommandLinePtr
/**
* Constructs a CProcess object and uses the CreateProcessW function to start the process immediately.
*
* @param CommandLine
* A std::wstring containing the command line to run
*
* @param StartupInfo
* Pointer to a STARTUPINFOW structure containing process startup information
*/
CProcess::CProcess(const wstring& CommandLine, LPSTARTUPINFOW StartupInfo)
{
auto_array_ptr<WCHAR> CommandLinePtr(new WCHAR[CommandLine.size() + 1]);
wcscpy(CommandLinePtr, CommandLine.c_str());
if(!CreateProcessW(NULL, CommandLinePtr, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, StartupInfo, &m_ProcessInfo))
TESTEXCEPTION("CreateProcessW failed\n");
}