问题
My goal is to change the path the application restarts from. I don't have access to main
, but I am free to run C code via ctypes.
I was able to change argv[0] in Solarios with getexecname()
, that gave me a pointer to it, to which I did memcpy
.
I was wondering if there is a method in winapi that allows me to either find argv[0]
pointer, or an API function that changed it?
Thanks
回答1:
on Windows, your command line is in the PEB (Process Environment Block). You probably should not modify it, but you can find it and act upon it.
you can find it using GetCommandLine(): https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156(v=vs.85).aspx
and parse it either yourself, or using CommandLineToArgvW https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx -- then launch a new instance of yourself (using CreateProcess or ShellExecute, whatever is applicable), and terminate. New instance of you will have the right params.
来源:https://stackoverflow.com/questions/29158052/changing-argv0-with-winapi