I'm using a setPriv function I wrote, which is supposed to set a privilege for the running program. However it keeps returning a 1300 erbool
setPriv(char privName){
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return( FALSE );
// Get the LUID for the shutdown privilege.
LPCWSTR privString = _T(""+privName);
LookupPrivilegeValue(NULL, privString,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
return true;
}
and the code I'm using to shutdown computers, I'm guessing currently isn't working because it doesn't have the privileges.
setPriv((char)"SE_REMOTE_SHUTDOWN_NAME"); setPriv((char)"SE_SHUTDOWN_NAME"); LPTSTR lpMachineName = L""; // Name of the network machine to be shutdown LPTSTR lpMessage = L"You have been shutdown"; DWORD dwTimeout = 60; BOOL bForceAppsClosed = false; BOOL bRebootAfterShutdown = false; InitiateSystemShutdown(lpMachineName, lpMessage, dwTimeout, bForceAppsClosed, bRebootAfterShutdown);


Sign In
Create Account


Back to top









