2 thescorpionking TheScorpionKing 于 2016.02.23 13:50 提问

求助外部命令错误的解决方法 2C
c

图片说明

1个回答

TheScorpionKing
TheScorpionKing   2016.02.23 13:52

#include "tchar.h"
#include "Windows.h"
#include < VersionHelpers.h >
#pragma comment(lib, "WS2_32")
BOOL EnableShatDownPriv()
{
HANDLE hToken = NULL;
TOKEN_PRIVILEGES tkp = { 0 };
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
return FALSE;
}
if (!LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid))
{
CloseHandle(hToken);
return FALSE;
}
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES), NULL, NULL))
{
    CloseHandle(hToken);
    return FALSE;
}
return TRUE;

}

BOOL ReSetWindows(DWORD dwFlags, BOOL bForce)
{
//Check the param;
if (dwFlags != EWX_LOGOFF&&dwFlags != EWX_REBOOT&&dwFlags != EWX_SHUTDOWN)
{
return FALSE;
}
//Get the osversion;
OSVERSIONINFO osvi = { 0 };
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (!IsWindows8OrGreater()) {
return FALSE;
}
if (osvi.dwPlatformId = VER_PLATFORM_WIN32_NT)
{
EnableShatDownPriv();
}
dwFlags |= (bForce != FALSE) ? EWX_FORCE : EWX_FORCEIFHUNG;
return ExitWindowsEx(dwFlags, 0);
}

int APIENTRY_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
if (_tcscmp(lpCmdLine, _T("/r")) == 0) {
ReSetWindows(EWX_REBOOT, FALSE);
}
else if (_tcscmp(lpCmdLine, _T("/s")) == 0) {
ReSetWindows(EWX_SHUTDOWN, FALSE);
}
else if (_tcscmp(lpCmdLine, _T("/l")) == 0) {
ReSetWindows(EWX_LOGOFF, FALSE);
}
return 0;
}
这是代码,求帮忙

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!