DWORD error;
int pret;
STARTUPINFO theStartupInfo;
PROCESS_INFORMATION theProcessInfo;
memset(&theStartupInfo, 0, sizeof(theStartupInfo));
memset(&theProcessInfo, 0, sizeof(theProcessInfo));
GetStartupInfo( &theStartupInfo );
pret = CreateProcess(
_T("C:\\Windows\\NOTEPAD.EXE"),
_T(" C:\\testfile.txt"),
NULL, // Process Attributes NULL default
NULL, // Thread attributes NULL
FALSE, // Don't Inherit handles
CREATE_NEW_CONSOLE, //Creation flags
NULL, // Environment same as calling process
NULL, // Current directory same as calling process
&theStartupInfo, // lp to startup info
&theProcessInfo
);
error = GetLastError();
So you would have to make the call like this
CreateProcess(NULL,_T("notepad c:\\testfile.txt),.....);
or you can use
ShellExecute(NULL,_T("open"),_T("notepad"),_T("c:\\testfile.txt"),NULL,SW_SHOWNORMAL);
AliR.
"AVee" <AV...@discussions.microsoft.com> wrote in message
news:3ECCEB36-6C67-412F...@microsoft.com...
>Can anyone tell me why this call to CreateProcess() succeeds when the .EXE
>extension is used for the application name (in this case "NOTEPAD.EXE"), but
>fails with Error 2 (file not found) when the .EXE extension is omitted. (The
>docs say that the EXE extension should be appended by CreateProcess() if
>omitted). It also fails if I do not provide the full path to the application,
>though in this case the path to NOTEPAD is included in the Environment.
>
>DWORD error;
>int pret;
>STARTUPINFO theStartupInfo;
>PROCESS_INFORMATION theProcessInfo;
>memset(&theStartupInfo, 0, sizeof(theStartupInfo));
>memset(&theProcessInfo, 0, sizeof(theProcessInfo));
****
You should learn to write ::ZeroMemory instead of using memset. It is easier to write and
more obvious what your intention is. Also, since ProcessInfo is output only, there is no
reason to prezero it (if you don't prezero startupinfo, your call will fail)
****
>GetStartupInfo( &theStartupInfo );
****
Why did you zero it and then load it? In fact, why do you want to GetStartupInfo?
****
>pret = CreateProcess(
> _T("C:\\Windows\\NOTEPAD.EXE"),
****
This must be the name of a program, but why do you assume that it is in C:\? This is not
a fair assumption, and in multiboot environments it will definitely be wrong. You need to
find out what the current directory is, by using something like GetWindowsDirectory, or
SHGetFolder.
If this is not working correctly, then the documentation may be in error. That's the best
I can say. I'll check this out and may add something to my errors-and-omissions document
if I find what the problem is.
****
> _T(" C:\\testfile.txt"),
****
Note that you cannot assume the root directory is accessible or writeable. And there is
no reason to expect the C: drive really exists.
****
> NULL, // Process Attributes NULL default
> NULL, // Thread attributes NULL
> FALSE, // Don't Inherit handles
> CREATE_NEW_CONSOLE, //Creation flags
> NULL, // Environment same as calling process
> NULL, // Current directory same as calling process
> &theStartupInfo, // lp to startup info
> &theProcessInfo
> );
>error = GetLastError();
****
Note that GetLastError() has no meaning unless you check the return value pret; it is
valid ONLY if the value is FALSE. So this should never be unconditionally retrieved.
joe
****
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
>It also fails if I do not provide the full path to the application,
>though in this case the path to NOTEPAD is included in the Environment.
http://bobmoore.mvps.org/Win32/w32tip46.htm
Bob Moore
http://bobmoore.mvps.org/
Please tell me if this is not the right place to ask this question.
Regards,
Arun
A service is running on a different desktop than what the logged in user is
seeing, so any process started by the service will have it's UI being put
onto a different desktop. One way around this is to run another process on
the user's desktop which communicates with the service. If the service
needs to run an app, it sends this process a message and the process
launches the app on the user's desktop, on behalf of the server.
-- David
Thanks David,
But, What if I dont want to see any UI, or should following call generate
the file "macaddr.txt" or not.
CreateProcess(NULL,"cmd.exe /C getmac /FO LIST >
macaddr.txt",NULL,NULL,TRUE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi);
P.S. I am new guy to IPC's and threading.
Yes, I believe the file should be generated. Try it and see?
-- David