I've a problem with my following code:
int main(int argc, char **argv) {
PROCESS_INFORMATION pi;
STARTUPINFO si;
printf("Process %d reporting for duty\n",GetCurrentProcessId());
GetStartupInfo(&si);
CreateProcess(NULL,"notepad.exe", NULL,NULL,FALSE,DETACHED_PROCESS, NULL,NULL, &si, &pi);
printf("New Process ID: %d\n",pi.dwProcessId);
return(0);
}
And on the runing time,I ran this while debuggin and it crashes on the CreateProcess method,with this error message:" Unhandled exception at 0x7c82f29c in Tests.exe: 0xC0000005: Access violation writing location 0x00415760." What does it means???
32 bit executables invariably have a base address of 0x00400000
. The address that cannot be written to, according to the exception is 0x00415760
. Which means that your code is almost certainly trying to write to a read-only part of the executable image. That happens, for example, when you try to write to string literals.
Now, the second parameter to CreateProcess
must be modifiable memory (it is declared as LPTSTR
). But you are passing a string literal. Put "notepad.exe"
in a modifiable buffer to solve your problem.
char CommandLine[] = "notepad.exe";
CreateProcess(NULL, CommandLine, ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With