I would like to clear the command line of my process from within. For example, when viewing my process in Task Manager/Process Explorer, the command line entry would be empty.
I would like to do this within the currently running process rather than restarting the process if possible.
I suppose you have to modify the RTL_USER_PROCESS_PARAMETERS part of the PEB of your process (see http://en.wikipedia.org/wiki/Process_Environment_Block for example and http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT%20Objects/Process/PEB.html). You can try to use NtQueryInformationProcess to get PEB. Then you can modify
ProcessParameters.CommandLine
. I hope it will work.UPDATED: I verified my suggestion. It works. The following test program demonstrate this:
If we start the program with some parameters we will see
instead of the following seen before
You might try calling the
GetCommandLine
API function and then setting the first byte to 0. That is:I honestly don't know if that'll work or what the possible ramifications are, but it might be worth a shot.
Based on your comment above, you may wish to consider passing the secret key via an environment variable. If you set the key in the parent process environment, it will be inherited by the child process and won't be visible to outsiders quite as easily as the command line.