待定文章

/*
* 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);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值