/*
* File: one.cpp
* Author: Administrator
*
* Created on 2009年3月5日, 下午6:08
*/
#include <windows.h>
#include <iostream.h>
BOOL MySystemShutdown( LPTSTR lpMsg )
{
HANDLE hToken; // handle to process token
HANDLE hLogonToken;
HANDLE hAdminToken;
TOKEN_PRIVILEGES tkp; // pointer to token structure
BOOL fResult; // system shutdown flag
// Get the current process token handle so we can get shutdown
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hLogonToken); // AfxMessageBox("OpenProcessToken failed.");
// Get the LUID for shutdown privilege.
LookupPrivilegeValue(NULL, SE_TCB_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process.
AdjustTokenPrivileges(hLogonToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
// privilege.
BOOL b1=LogonUser( "zhou", "192.168.2.18", "670025",
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
&hLogonToken );
int t=GetLastError();
cout<< t;
if(b1) cout<<"正确"; else cout<<"错误";
// return FALSE;
DuplicateTokenEx( hLogonToken, TOKEN_ALL_ACCESS, NULL,
SecurityIdentification, TokenPrimary, &hAdminToken );
ImpersonateLoggedOnUser( hAdminToken );
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
// AfxMessageBox("OpenProcessToken failed.");
// Get the LUID for shutdown privilege.
LookupPrivilegeValue(NULL, SE_REMOTE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
// Display the shutdown dialog box and start the time-out countdown.
fResult = InitiateSystemShutdown("192.168.2.18", // shut down local computer
"Click on the main window and press the Escape key to cancel shutdown.", // message to user
1, // time-out period
FALSE, // ask user to close apps //注意这一段API调用!
FALSE); // reboot after shutdown
if (!fResult)
{
// AfxMessageBox("InitiateSystemShutdown failed.");
}
// Disable shutdown privilege.
tkp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
return TRUE;
}
BOOL getBooleans (){
HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp;
BOOL fResult; // error code return
OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,
&hToken);
fResult = GetLastError();
cout<<"开::"<<fResult<<"::";
LookupPrivilegeValue(NULL,SE_TCB_NAME, &tkp.Privileges[0].Luid);
fResult = GetLastError();
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
fResult = GetLastError();
fResult = LogonUser(
"Administrator",
"\\192.168.2.25",
"*",
/*"192.168.2.15",
"990714",*/
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
&hToken);
fResult = GetLastError();
cout<<fResult;
return TRUE;
}
/*
*
*/
int main(int argc, char** argv) {
BOOL b=getBooleans();//MySystemShutdown("ddd");
if(b) cout<<"right";
else cout<<"error";
return (EXIT_SUCCESS);
}
* File: one.cpp
* Author: Administrator
*
* Created on 2009年3月5日, 下午6:08
*/
#include <windows.h>
#include <iostream.h>
BOOL MySystemShutdown( LPTSTR lpMsg )
{
HANDLE hToken; // handle to process token
HANDLE hLogonToken;
HANDLE hAdminToken;
TOKEN_PRIVILEGES tkp; // pointer to token structure
BOOL fResult; // system shutdown flag
// Get the current process token handle so we can get shutdown
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hLogonToken); // AfxMessageBox("OpenProcessToken failed.");
// Get the LUID for shutdown privilege.
LookupPrivilegeValue(NULL, SE_TCB_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process.
AdjustTokenPrivileges(hLogonToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
// privilege.
BOOL b1=LogonUser( "zhou", "192.168.2.18", "670025",
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
&hLogonToken );
int t=GetLastError();
cout<< t;
if(b1) cout<<"正确"; else cout<<"错误";
// return FALSE;
DuplicateTokenEx( hLogonToken, TOKEN_ALL_ACCESS, NULL,
SecurityIdentification, TokenPrimary, &hAdminToken );
ImpersonateLoggedOnUser( hAdminToken );
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
// AfxMessageBox("OpenProcessToken failed.");
// Get the LUID for shutdown privilege.
LookupPrivilegeValue(NULL, SE_REMOTE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
// Display the shutdown dialog box and start the time-out countdown.
fResult = InitiateSystemShutdown("192.168.2.18", // shut down local computer
"Click on the main window and press the Escape key to cancel shutdown.", // message to user
1, // time-out period
FALSE, // ask user to close apps //注意这一段API调用!
FALSE); // reboot after shutdown
if (!fResult)
{
// AfxMessageBox("InitiateSystemShutdown failed.");
}
// Disable shutdown privilege.
tkp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
return TRUE;
}
BOOL getBooleans (){
HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp;
BOOL fResult; // error code return
OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,
&hToken);
fResult = GetLastError();
cout<<"开::"<<fResult<<"::";
LookupPrivilegeValue(NULL,SE_TCB_NAME, &tkp.Privileges[0].Luid);
fResult = GetLastError();
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
fResult = GetLastError();
fResult = LogonUser(
"Administrator",
"\\192.168.2.25",
"*",
/*"192.168.2.15",
"990714",*/
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
&hToken);
fResult = GetLastError();
cout<<fResult;
return TRUE;
}
/*
*
*/
int main(int argc, char** argv) {
BOOL b=getBooleans();//MySystemShutdown("ddd");
if(b) cout<<"right";
else cout<<"error";
return (EXIT_SUCCESS);
}