I’d like to execute a simple command line but without to make a window appear. Therefore I can’t use System and have to use CreateProcess as far as I know.
So I have the following code for example:
//.../
CreateProcess(NULL,input,NULL,NULL,false,NORMAL_PRIORITY_CLASS |
CREATE_NO_WINDOW,NULL,NULL,&startInf,&procInf);//)
//.../
If input is a line like “ping http://www.google.com -n 2” it seems to work.
What I need is the deletion-function though.
Therefore I tried a lot of variations like:
input = "rd /S /Q \"D:\\ALEX_DATEN\\PC\\C++\\bla\"";
and
input = "rd /S /Q \"D:/DATEN/PC/C++/bla\"";
But nothing happens and the function returns failure :/
If I write it as a .bat file (without using the “\” escaping chars) the deleting works perfectly!
Does anyone know what I’m doing wrong?
P.s. no, I’m not writing a destructive virus.. if that would have been my target, I would have definitely have found simpler ways…
Some system command like
rd,deland … are not actual executable Images (e.g. .exe Files), so you can’t execute/run them usingCreateProcessthey are built-in commands that known tocmd(command interpreter of windows) so you should createcmdand pass your command to it:Note: Please see arguments of
cmd, you have to use/Cto pass your command. So your command is as follow: