createprocess

How to use or expand environment variables in a command instantiated by CreateProcess?

牧云@^-^@ 提交于 2019-12-04 17:40:28
The following code utilizes CreateProcess to run commands with environmental variables. Here, it tries to run notepad %APPDATA%\test.txt . If I run notepad %APPDATA%\test.txt directly within Windows' CMD , %APPDATA% will be expanded. However, the environmental variable can not be expanded when executed by CreateProcess . Could you help to comment on the reason and the workaround? Any comment will be appreciated! program TestConsole2; {$APPTYPE CONSOLE} uses Windows, SysUtils; var I: Integer; ProgramName: String; StartInfo : TStartupInfo; ProcInfo : TProcessInformation; CreateOK : Boolean;

CreateProcess usage for executable wrapper for Windows?

自闭症网瘾萝莉.ら 提交于 2019-12-04 16:47:05
TL;DR : CreateProcess(?, ?, ?, ...) for: Pass current process params (i.e. "batchfile" %* ) correctly connect stdin and stdout creation flags? I have the following problem: I need to launch a given 3rd party executable with a custom environment and custom parameters. (Both semi-fixed) I cannot use a batch file, because the (again, 3rd party) side invoking the module directly calls CreateProcess I need to pass on any additional paramers passed So, what I'd like to do is create a very simple executable launcher that would be the equivalent of a batch file like: set PATH=... set WHATEVER=... ...

Can I access the string returned from a Delphi CreateProcess command?

北城余情 提交于 2019-12-04 15:57:48
问题 I'm using the Win32 CreateProcess function to perform a call to an external executable. The executable returns a string. Is there a way I can capture and interrogate the returned string after calling the executable? Failing that, I might have to write out the string to a file in the executable and read that in the calling program after the call has finished. That seems lame though. 回答1: Jedi Code Library contains function CreateDOSProcessRedirected which runs a process and provides it with

How to launch a GUI program in a Windows service?

折月煮酒 提交于 2019-12-04 10:56:31
问题 When I run a service as LocalSystem account, I can use following codes to launch a GUI program under current login account: WTSGetActiveConsoleSessionId->WTSQueryUserToken->CreateProcessAsUser However, when I run the service as my personal account, the GUI program will NOT show up. I can see it in task manager though. What should I do to launch the GUI program when the service is running under my personal account? 回答1: John and jdigital are both right - from my understanding, services can

CreateProcess succeeds, but GetLastError() returns access denied

淺唱寂寞╮ 提交于 2019-12-04 02:01:40
问题 I'm having a little confusion due to conflicting return values from CreateProcess() and GetLastError() . When I use CreateProcess() in a manner similar to below, it succeeds and appears to accomplish its required tasks. Yet, GetLastError() still returns Access is Denied. If access is denied, why is does it appear to complete the task. In contrast, if CreateProcess() succeeds, why is GetLastError() returning access denied? Or is my use of GetLastError() incorrect? Am I only supposed to use it

system() and CreateProcess() / CreateProcessW()

≯℡__Kan透↙ 提交于 2019-12-03 18:10:05
问题 I want to execute a TEST.exe in a C program. While I use system( "TEST.exe <input-file> output-file" ); I can get what I expected. But CreateProcessW() didn't work properly when I use the following code (see How do I run an external program?): if (CreateProcessW(const_cast<LPCWSTR>(FullPathToExe.c_str()), pwszParam, 0, 0, false, CREATE_DEFAULT_ERROR_MODE, 0, 0, &siStartupInfo, &piProcessInfo) != false) { /* Watch the process. */ dwExitCode = WaitForSingleObject(piProcessInfo.hProcess,

CreateProcess does not create additional console windows under Windows 7?

我怕爱的太早我们不能终老 提交于 2019-12-03 17:31:19
I am trying to run a process using CreateProcess(...) and run it independently in a seperate console window. I can achieve this using the system("...") function, but I prefer CreateProcess since it gives me the possibility to specify environment and working directory, get a handle to the process, as well as piping stdin/out when I need to. All I find on the internet is the inverse problem, which is people having additional console windows and wanting to get rid of them! It appears it was the normal behavior in earlier versions of Windows to open and show a new console window(s)? Right now, I

Using a handle to collect output from CreateProcess()

南笙酒味 提交于 2019-12-03 11:25:40
I am using CreateProcess() to run an external console application in Windows from my GUI application. I would like to somehow gather the output to know whether there were errors. Now I know I have to do something with hStdOutput, but I fail to understand what. I am new to c++ and an inexperienced programmer and I actually don't know what to do with a handle or how to light a pipe. How do I get the output to some kind of variable (or file)? This is what I have a the moment: void email::run(string path,string cmd){ WCHAR * ppath=new(nothrow) WCHAR[path.length()*2]; memset(ppath,' ',path.length()

Can I access the string returned from a Delphi CreateProcess command?

依然范特西╮ 提交于 2019-12-03 09:08:17
I'm using the Win32 CreateProcess function to perform a call to an external executable. The executable returns a string. Is there a way I can capture and interrogate the returned string after calling the executable? Failing that, I might have to write out the string to a file in the executable and read that in the calling program after the call has finished. That seems lame though. Jedi Code Library contains function CreateDOSProcessRedirected which runs a process and provides it with input and output file. You can put required input (if any) into the input file and read process output (if any

CreateProcess error = 2, the system cannot find the file specified error

匿名 (未验证) 提交于 2019-12-03 09:05:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have Android Studio 2.3.3 on Windows and also Git for Windows. I cloned a repository from GitHub ( VCS->Checkout from version control->Git->pasted the link ) and tried to run it. But the gradle sync failed giving this error CreateProcess error=2, the system cannot find the file specified I checked the log and I noticed this java.io.IOException: Cannot run program "git" (in directory "H:\GitClone\apps-android-commons\app"): CreateProcess error=2, The system cannot find the file specified The path given is the location I chose during