VC 屏蔽双击打开程序,只能被第三方程序调起

实现如下功能

Axx.exe:双击不能运行,只能被Bxx.exe调起

解决方案:通过命令行参数判断,如果等于Bxx.exe设置的参数信息,则运行,否则不运行。

Axx.exe

BOOL CAxxApp::InitInstance()

{

//获取命令行参数 如果不是调用程序特定传入的参数“-XXXX”,则停止运行 2010/1/17
/////////////////////////////////////////////////////////////////////////
int CommandLineCount = 0;
LPWSTR * m_lpCommandLine = ::CommandLineToArgvW(GetCommandLineW(),&CommandLineCount);
BOOL result = false;
CString m_strCommandLine;
//获取参数行命令,并将UNICODE转化成ASCI进行判断
for(int i = CommandLineCount - 1; i >= 0; i --)


{
m_strCommandLine = m_lpCommandLine[i];
if(m_strCommandLine == _T("GuardTool"))
{
result = TRUE;
break;
}
}


//释放内存
GlobalFree(HGLOBAL(m_lpCommandLine));
if(!result)
return FALSE;

}


Bxx.exe


SHELLEXECUTEINFO ShExecInfo;

ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS ;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = _T("open");
//输入要调用的exe文件路径
ShExecInfo.lpFile = name; 
//传入命令行参数数据
ShExecInfo.lpParameters = _T("XXXX"); //若没有命令行参数,可为NULL

ShExecInfo.lpDirectory = NULL;//这里exe的目录可忽略,写为NULL
ShExecInfo.nShow = SW_SHOWDEFAULT;//这里设置为不显示exe界面,若设置为SW_SHOW,则可以显示exe界面
ShExecInfo.hInstApp = NULL;

ShellExecuteEx(&ShExecInfo);

猜你喜欢

转载自blog.csdn.net/xgrdszdx/article/details/80943528
vc