ce_cabquiet.cpp
来自「CE下的安装程序的制作」· C++ 代码 · 共 55 行
CPP
55 行
#include <windows.h>
// This is how we run cabwiz completely silently
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPTSTR,int)
{
// first, for convenience, get the current application directory
wchar_t fn[MAX_PATH]; GetModuleFileName(NULL,fn,MAX_PATH);
wchar_t *c=fn, *lastslash=c;
while (*c!=0) {if (*c=='\\') lastslash=c+1; c++;}
wcscpy(lastslash,L"ce_setup.cab");
// First, if cabwiz thinks that the app was already installed,
// then it will complain. Hence we lie to it.
// MUST USE THE CORRECT REGKEY HERE! it is
// Provider <space> AppName
// as defined in ce_setup.inf and used by cabwiz.
HKEY hkey; LONG lres=RegOpenKeyEx(HKEY_LOCAL_MACHINE,L"SOFTWARE\\Apps\\Lu ce_setup",0,0,&hkey);
if (lres==ERROR_SUCCESS)
{ DWORD val=0; RegSetValueEx(hkey,L"Instl",0,REG_DWORD,(LPBYTE)&val,sizeof(val));
RegCloseKey(hkey);
}
// The act of running cabwiz will also delete the cab.
// I think that's horrible. So I make it readonly
DWORD attr = GetFileAttributes(fn);
if (attr==0xFFFFFFFF) return MessageBox(NULL,fn,L"Not found",MB_OK);
SetFileAttributes(fn,attr|FILE_ATTRIBUTE_READONLY);
// Now run the cab using wceload, telling it to be quiet:
const wchar_t *cmd = L"\\windows\\wceload.exe";
wchar_t arg[MAX_PATH+40];
wsprintf(arg,L"/noaskdest /noui \"%s\"",fn);
//
PROCESS_INFORMATION pi;
BOOL res=CreateProcess(cmd,arg,NULL,NULL,NULL,0,NULL,NULL,NULL,&pi);
if (!res) MessageBox(NULL,L"Couldn't...",L"ce_setup",MB_OK);
else
{ WaitForSingleObject(pi.hProcess,50000);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
// Really, we need to wait until the cabwiz has finished before
// restoring its file attributes. I put a timeout of 50s in there just
// in case something went wrong with it. If so, this might be premature.
SetFileAttributes(fn,attr);
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?