CreateProcess!!
-
Dear All, Please look at the following code ... --------------------------------------------------------------------------- PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); SetLastError(0); CreateProcess("notepad.exe",NULL,NULL,NULL,FALSE,NULL,NULL,NULL,&si,&pi); --------------------------------------------------------------------------- This code is not able to run the notepad because its not able to find the path of notapd.exe application. But when I use Run option in Windows Start Menu ,type notapad and say OK, its able to find and run the notpad application may be from enviornment variables. Please let me know why My code is not able find the notapd application? PS- It will work if i copy notpad.exe application where my application exists. :) With Regards Manoj
-
Dear All, Please look at the following code ... --------------------------------------------------------------------------- PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); SetLastError(0); CreateProcess("notepad.exe",NULL,NULL,NULL,FALSE,NULL,NULL,NULL,&si,&pi); --------------------------------------------------------------------------- This code is not able to run the notepad because its not able to find the path of notapd.exe application. But when I use Run option in Windows Start Menu ,type notapad and say OK, its able to find and run the notpad application may be from enviornment variables. Please let me know why My code is not able find the notapd application? PS- It will work if i copy notpad.exe application where my application exists. :) With Regards Manoj
Call system("notepad.exe"); and refer MSDN for "system" when u call run from start->run it work as follows ( MSDN) The system function passes command to the command interpreter, which executes the string as an operating-system command. system refers to the COMSPEC and PATH environment variables that locate the command-interpreter file (the file named CMD.EXE in Windows NT). If command is NULL, the function simply checks to see whether the command interpreter exists. Anil
-
Dear All, Please look at the following code ... --------------------------------------------------------------------------- PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); SetLastError(0); CreateProcess("notepad.exe",NULL,NULL,NULL,FALSE,NULL,NULL,NULL,&si,&pi); --------------------------------------------------------------------------- This code is not able to run the notepad because its not able to find the path of notapd.exe application. But when I use Run option in Windows Start Menu ,type notapad and say OK, its able to find and run the notpad application may be from enviornment variables. Please let me know why My code is not able find the notapd application? PS- It will work if i copy notpad.exe application where my application exists. :) With Regards Manoj
Make a call to the windows API command "GetWindowsDirectory" and use strcat to concatenate the notepad string to the end of it. You could just hardcode the string too (eg "C:\\Windows\\notepad.exe"), but if anyone has a custom windows install it may not find the file. example code
char *strbuf[256]; if (GetWindowsDirectory(strbuf, 256)) { strcat(strbuf, "\\notePad.exe"); } else { // An error occurred, perhaps the buffer is too small? } // Now you should have the full path in the strbuf variable CreateProcess(strbuf,NULL,NULL,NULL,FALSE,NULL,NULL,NULL,&si,π);
When I die I'd like to go peacefully in my sleep like my father, not screaming in terror like his passengers!!! -- modified at 1:18 Friday 6th January, 2006 -
Dear All, Please look at the following code ... --------------------------------------------------------------------------- PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); SetLastError(0); CreateProcess("notepad.exe",NULL,NULL,NULL,FALSE,NULL,NULL,NULL,&si,&pi); --------------------------------------------------------------------------- This code is not able to run the notepad because its not able to find the path of notapd.exe application. But when I use Run option in Windows Start Menu ,type notapad and say OK, its able to find and run the notpad application may be from enviornment variables. Please let me know why My code is not able find the notapd application? PS- It will work if i copy notpad.exe application where my application exists. :) With Regards Manoj
manojk_batra wrote:
But when I use Run option in Windows Start Menu ,type notapad and say OK, its able to find and run the notpad application may be from enviornment variables.
HKLM\Software\Microsoft\Windows\CurrentVersion\App paths.
Love Forgives--Love Gives--Jesus is Love :)
--Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord
-
Dear All, Please look at the following code ... --------------------------------------------------------------------------- PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); SetLastError(0); CreateProcess("notepad.exe",NULL,NULL,NULL,FALSE,NULL,NULL,NULL,&si,&pi); --------------------------------------------------------------------------- This code is not able to run the notepad because its not able to find the path of notapd.exe application. But when I use Run option in Windows Start Menu ,type notapad and say OK, its able to find and run the notpad application may be from enviornment variables. Please let me know why My code is not able find the notapd application? PS- It will work if i copy notpad.exe application where my application exists. :) With Regards Manoj
mention the full path and file name of the module which is to be executed ie., ..//notepad.exe in CreateProcess() never say die
-
Call system("notepad.exe"); and refer MSDN for "system" when u call run from start->run it work as follows ( MSDN) The system function passes command to the command interpreter, which executes the string as an operating-system command. system refers to the COMSPEC and PATH environment variables that locate the command-interpreter file (the file named CMD.EXE in Windows NT). If command is NULL, the function simply checks to see whether the command interpreter exists. Anil
Dear Anil, Thanks you a lot for Great Help. :) Thanks & Regards Manoj
-
Make a call to the windows API command "GetWindowsDirectory" and use strcat to concatenate the notepad string to the end of it. You could just hardcode the string too (eg "C:\\Windows\\notepad.exe"), but if anyone has a custom windows install it may not find the file. example code
char *strbuf[256]; if (GetWindowsDirectory(strbuf, 256)) { strcat(strbuf, "\\notePad.exe"); } else { // An error occurred, perhaps the buffer is too small? } // Now you should have the full path in the strbuf variable CreateProcess(strbuf,NULL,NULL,NULL,FALSE,NULL,NULL,NULL,&si,π);
When I die I'd like to go peacefully in my sleep like my father, not screaming in terror like his passengers!!! -- modified at 1:18 Friday 6th January, 2006Dear Lastgen, Thanks you a lot. :) Thanks & Regards Manoj
-
manojk_batra wrote:
But when I use Run option in Windows Start Menu ,type notapad and say OK, its able to find and run the notpad application may be from enviornment variables.
HKLM\Software\Microsoft\Windows\CurrentVersion\App paths.
Love Forgives--Love Gives--Jesus is Love :)
--Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord
Dear Owner drawn, Thanks you a lot. :) Thanks & Regards Manoj
-
mention the full path and file name of the module which is to be executed ie., ..//notepad.exe in CreateProcess() never say die
Dear sunit5, Thanks you a lot. :) Thanks & Regards Manoj
-
Dear Anil, Thanks you a lot for Great Help. :) Thanks & Regards Manoj
manojk_batra wrote:
Thanks you a lot for Great Help.
http://www.codeproject.com/system/newbiespawn.asp[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV