Joe*_*dan 8 c++ windows winapi command-line command-line-arguments
我想从内部清除我的进程的命令行.例如,在任务管理器/进程资源管理器中查看我的进程时,命令行条目将为空.
我想在当前运行的进程中执行此操作,而不是在可能的情况下重新启动进程.
Ole*_*leg 11
我想你必须修改你的进程的PEB的RTL_USER_PROCESS_PARAMETERS部分(例如,参见http://en.wikipedia.org/wiki/Process_Environment_Block和http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT %20Objects/Process/PEB.html).您可以尝试使用NtQueryInformationProcess来获取PEB.然后你可以修改.我希望它能奏效.ProcessParameters.CommandLine
更新:我验证了我的建议.有用.以下测试程序证明了这一点:
#include <Windows.h>
#include <Winternl.h> // for PROCESS_BASIC_INFORMATION and ProcessBasicInformation
#include <stdio.h>
#include <tchar.h>
typedef NTSTATUS (NTAPI *PFN_NT_QUERY_INFORMATION_PROCESS) (
IN HANDLE ProcessHandle,
IN PROCESSINFOCLASS ProcessInformationClass,
OUT PVOID ProcessInformation,
IN ULONG ProcessInformationLength,
OUT PULONG ReturnLength OPTIONAL);
int main()
{
HANDLE hProcess = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE, GetCurrentProcessId());
PROCESS_BASIC_INFORMATION pbi;
ULONG ReturnLength;
PFN_NT_QUERY_INFORMATION_PROCESS pfnNtQueryInformationProcess =
(PFN_NT_QUERY_INFORMATION_PROCESS) GetProcAddress (
GetModuleHandle(TEXT("ntdll.dll")), "NtQueryInformationProcess");
NTSTATUS status = pfnNtQueryInformationProcess (
hProcess, ProcessBasicInformation,
(PVOID)&pbi, sizeof(pbi), &ReturnLength);
// remove full information about my command line
pbi.PebBaseAddress->ProcessParameters->CommandLine.Length = 0;
getchar(); // wait till we can verify the results
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我们用一些参数启动程序,我们将看到

而不是以前见过的

您可以尝试调用GetCommandLineAPI函数,然后将第一个字节设置为0。即:
LPTSTR cmdline = GetCommandLine();
*cmdline = '\0';
Run Code Online (Sandbox Code Playgroud)
老实说,我不知道这是否有效或可能产生什么后果,但可能值得一试。