Win32进程参数处理
2024-09-11
0
0
参数的内存申请
HANDLE handle = GetProcessHeap();//获取默认的堆
LPVOID pMem = HeapAlloc(handle, 0, 0x1400ui64);
if(pMem)
{
memset_0(pMem, 0, 0x1400ui64);
}
//代码处理
if(pMem)
{
handle = GetProcessHeap();
HeapFree(handle, 0, pMem);
}
命令行解析
#include <windows.h>
#include <stdio.h>
#include <shellapi.h>
int __cdecl main()
{
LPWSTR *szArglist;
int nArgs;
int i;
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
if( NULL == szArglist )
{
wprintf(L"CommandLineToArgvW failed\n");
return 0;
}
else
{
for( i=0; i<nArgs; i++)
printf("%d: %ws\n", i, szArglist[i]);
}
// Free memory allocated for CommandLineToArgvW arguments.
LocalFree(szArglist);
return(1);
}
另外附加的参数可选项有:
- 通过注册表引入,其注册表路径为:
项名为CmdLine计算机\HKEY_LOCAL_MACHINE\SYSTEM\Setup\MoSetup
- 通过配置文件引入,其路径为:
%systemdrive%\\Users\\Default\\AppData\\Local\\Microsoft\\Windows\\WSUS\\SetupConfig.ini