隐藏打开程序或文档

// eHideBat.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include 
#include 

#ifdef _UNICODE
	#pragma comment( linker, "/subsystem:\"windows\" /entry:\"wmainCRTStartup\"" ) 
#else
	#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) 
#endif // _UNICODE

using namespace std;

#define E_MAX_PATH 1024



int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;
	if (argc>1)
	{
		TCHAR szPath[E_MAX_PATH]={0};
		_stprintf_s(szPath,E_MAX_PATH,_T("\"%s\""),argv[1]);
		
		TCHAR* lpszParam=NULL;
		if (argc>2)
		{
			lpszParam=new TCHAR[E_MAX_PATH];
			_stprintf_s(lpszParam,E_MAX_PATH,_T("\"%s\""),argv[2]);
		}
		
		DWORD	dwResult=(DWORD)::ShellExecute(NULL,_T("open"),szPath,lpszParam,NULL,SW_HIDE);
		
		if (dwResult<32)
		{
			TCHAR *lpErrMsg=new TCHAR[8192];
			if (lpszParam)
			{
				_stprintf_s(lpErrMsg,8192,_T("执行程序失败:%s %s\r\n\r\n错误描述:(%d)"),argv[1],argv[2],dwResult);
			}else{
				_stprintf_s(lpErrMsg,8192,_T("执行程序失败:%s\r\n\r\n错误描述:(%d)"),argv[1],dwResult);
			}
			
			TCHAR* lpBuffer=NULL;
			::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,NULL,dwResult,0,( LPTSTR )&lpBuffer,0,NULL);
			_tcscat(lpErrMsg,lpBuffer);
			if(lpBuffer)LocalFree( lpBuffer );
			
			::MessageBox(NULL,lpErrMsg,_T("Error"),MB_OK|MB_ICONWARNING);
			
			delete lpErrMsg;
		}
		
		if(lpszParam) delete lpszParam;
	}else{
		::MessageBox(NULL,_T("缺少参数\r\n参数1:程序或文档路径\r\n参数2[可选]:命令行参数"),_T("eATM.App - eHideExec")
			,MB_OK|MB_ICONWARNING);
	}
	
	return nRetCode;
}


eHideExec.exe “c:\xxx.bat”

eHideExec.exe “c:\xxxx.exe”

eHideExec.exe “c:\xxxx.exe” “-param”

发表评论

电子邮件地址不会被公开。