113 lines
2.4 KiB
C++
113 lines
2.4 KiB
C++
//---------------------------------------------------------------------------
|
|
#include <vcl.h>
|
|
#include <tchar.h>
|
|
|
|
#include "UpgradeThread.h"
|
|
#include "UpgradeUnit.h"
|
|
#pragma hdrstop
|
|
|
|
//---------------------------------------------------------------------------
|
|
USEFORM("UpgradeUnit.cpp", UpgradeForm);
|
|
//---------------------------------------------------------------------------
|
|
|
|
String MAIN_APP_NAME;
|
|
|
|
BOOL ImprovePrivilege()
|
|
{
|
|
HANDLE token;
|
|
//ÌáÉýȨÏÞ
|
|
if(!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&token)){
|
|
MessageBox(NULL,L"´ò¿ª½ø³ÌÁîÅÆÊ§°Ü...",L"´íÎó",MB_ICONSTOP);
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL bRet = true;
|
|
TOKEN_PRIVILEGES tkp;
|
|
tkp.PrivilegeCount = 1;
|
|
LookupPrivilegeValue(NULL,SE_DEBUG_NAME,&tkp.Privileges[0].Luid);
|
|
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
|
|
|
if(!AdjustTokenPrivileges(token,FALSE,&tkp,sizeof(tkp),NULL,NULL)){
|
|
MessageBox(NULL,L"µ÷ÕûÁîÅÆÈ¨ÏÞʧ°Ü...",L"´íÎó",MB_ICONSTOP);
|
|
bRet = FALSE;
|
|
}
|
|
|
|
CloseHandle(token);
|
|
|
|
return bRet;
|
|
}
|
|
|
|
int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
|
|
{
|
|
int mode = 0, sid = 0;
|
|
String sVar;
|
|
if( ParamStr(1).IsEmpty() ){
|
|
return 0;
|
|
}
|
|
else{
|
|
String param = ParamStr(1).UpperCase();
|
|
|
|
if( param=="MD5" ){
|
|
mode = 1;
|
|
}
|
|
else if( ParamStr(2).IsEmpty() ){
|
|
return 0;
|
|
}
|
|
else{
|
|
if( param=="SHOW" )
|
|
mode = 0;
|
|
else if( param=="HIDE" )
|
|
mode = 2;
|
|
else if( param=="MOVE" )
|
|
mode = 3;
|
|
|
|
MAIN_APP_NAME = ParamStr(2);
|
|
sid = ParamStr(3).ToInt();
|
|
sVar = ParamStr(4);
|
|
#ifdef _DEBUG
|
|
// String msg = ParamStr(0) + " ";
|
|
// msg += ParamStr(1) + " ";
|
|
// msg += ParamStr(2) + " ";
|
|
// msg += ParamStr(3);
|
|
// ShowMessage( msg );
|
|
#endif
|
|
}
|
|
}
|
|
|
|
try{
|
|
Application->Initialize();
|
|
Application->Title = APPNAME;
|
|
|
|
ImprovePrivilege();
|
|
|
|
if( mode < 2 ){
|
|
Application->MainFormOnTaskBar = true;
|
|
Application->CreateForm(__classid(TUpgradeForm), &UpgradeForm);
|
|
UpgradeForm->m_iMode = mode;
|
|
UpgradeForm->m_idSoft = sid;
|
|
UpgradeForm->m_sVar = sVar;
|
|
Application->Run();
|
|
}
|
|
else{
|
|
TUpgradeThread* pThread = new TUpgradeThread( true, mode, sid, sVar );
|
|
pThread->Start();
|
|
|
|
pThread->WaitFor();
|
|
delete pThread;
|
|
}
|
|
}
|
|
catch (Exception &exception){
|
|
Application->ShowException(&exception);
|
|
}
|
|
catch (...){
|
|
try{
|
|
throw Exception("");
|
|
}
|
|
catch (Exception &exception){
|
|
Application->ShowException(&exception);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
//---------------------------------------------------------------------------
|