使用VCPP的远程桌面

使用VCPP的远程桌面

问题描述:



如何使用MFC应用程序远程登录(远程桌面)到计算机?
有人可以帮我吗?

在此先感谢

Hi,

How to remote login( remote desktop ) to a computer using MFC applications?
Can anybody help me?

Thanks in advance

BOOL MySystemShutdown(LPTSTR lpMsg)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
BOOL fResult; //系统关闭标志

//获取当前进程令牌句柄,以便我们可以关闭
//特权.

如果(!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken))
返回FALSE;

//获取用于关闭特权的LUID.

LookupPrivilegeValue(NULL,SE_REMOTE_SHUTDOWN_NAME,
&tkp.Privileges [0] .Luid);

tkp.PrivilegeCount = 1; //设置权限的一个权限
tkp.Privileges [0].属性= SE_PRIVILEGE_ENABLED;

//获取此过程的关闭特权.

AdjustTokenPrivileges(hToken,FALSE,&tkp,0,
(PTOKEN_PRIVILEGES)NULL,0);

//无法测试AdjustTokenPrivileges的返回值.

如果(GetLastError()!= ERROR_SUCCESS)
返回FALSE;

//显示关闭对话框并开始倒数计时.

fResult = InitiateSystemShutdown(
(远程计算机名称"),//关闭远程计算机
lpMsg,//给用户的消息
10,//超时期限,以秒为单位
否,//要求用户关闭应用程序
真的); //关机后重新启动

int s = GetLastError();
CString ss;
ss.Format(%d",s);
AfxMessageBox(ss);

如果(!fResult)
返回FALSE;

//禁用关闭权限.

tkp.Privileges [0] .Attributes = 0;
AdjustTokenPrivileges(hToken,FALSE,&tkp,0,
(PTOKEN_PRIVILEGES)NULL,0);

返回TRUE;
}
BOOL MySystemShutdown( LPTSTR lpMsg )
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
BOOL fResult; // system shutdown flag

// Get the current process token handle so we can get shutdown
// privilege.

if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return FALSE;

// 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.

if (GetLastError() != ERROR_SUCCESS)
return FALSE;

// Display the shutdown dialog box and start the countdown.

fResult = InitiateSystemShutdown(
("remote computer name "), // shut down remote computer
lpMsg, // message for user
10, // time-out period, in seconds
FALSE, // ask user to close apps
TRUE); // reboot after shutdown

int s = GetLastError();
CString ss;
ss.Format("%d",s);
AfxMessageBox(ss);

if (!fResult)
return FALSE;

// Disable shutdown privilege.

tkp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);

return TRUE;
}