提高程序权限的函数.
bool myclose::UpPrivilege()
{
HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp; // pointer to token structure
bool result = OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,
&hToken);
if(!result) //打开进程错误
return result;
result = LookupPrivilegeValue( NULL,
SE_DEBUG_NAME,
&tkp.Privileges[0].Luid);
if(!result) //查看进程权限错误
return result;
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
result = AdjustTokenPrivileges( hToken,
FALSE,
&tkp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL);
return result;
}
bool myclose::StopIt()
{
bool result = true;
result = UpPrivilege();
LProcessInfo Process;
Process.GetInfo();
for (int i = 0 ; i < Process.Num() ; i++)
{
string tmpfileName;
tmpfileName = Process.ExeFile(i);
bool bClientRun = !(strnicmp(tmpfileName.c_str() , "smss.exe", strlen("smss.exe")));
if(bClientRun)
{
HANDLE hHandle = OpenProcess( PROCESS_ALL_ACCESS,
false,
Process.ID(i));
if(!hHandle) //如果打开失败
{
result = false;
break;
}
else
{
result = TerminateProcess(hHandle, 0);
if(!result)
break;
}
}
}
return result;
}
{
HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp; // pointer to token structure
bool result = OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,
&hToken);
if(!result) //打开进程错误
return result;
result = LookupPrivilegeValue( NULL,
SE_DEBUG_NAME,
&tkp.Privileges[0].Luid);
if(!result) //查看进程权限错误
return result;
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
result = AdjustTokenPrivileges( hToken,
FALSE,
&tkp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL);
return result;
}
bool myclose::StopIt()
{
bool result = true;
result = UpPrivilege();
LProcessInfo Process;
Process.GetInfo();
for (int i = 0 ; i < Process.Num() ; i++)
{
string tmpfileName;
tmpfileName = Process.ExeFile(i);
bool bClientRun = !(strnicmp(tmpfileName.c_str() , "smss.exe", strlen("smss.exe")));
if(bClientRun)
{
HANDLE hHandle = OpenProcess( PROCESS_ALL_ACCESS,
false,
Process.ID(i));
if(!hHandle) //如果打开失败
{
result = false;
break;
}
else
{
result = TerminateProcess(hHandle, 0);
if(!result)
break;
}
}
}
return result;
}