码迷,mamicode.com
首页 > 其他好文 > 详细

2019-10-19 打开远程桌面

时间:2019-10-19 20:40:19      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:write   shared   epo   exe   isp   lru   controls   local   str   

procedure CloseSleepAndDisplayOn;
begin
  ShellExecute(0, open, cmd.exe, /c powercfg /x /monitor-timeout-ac 0, nil, SW_HIDE);
  ShellExecute(0, open, cmd.exe, /c powercfg /x /monitor-timeout-dc 0, nil, SW_HIDE);
  ShellExecute(0, open, cmd.exe, /c powercfg /x /hibernate-timeout-ac 0, nil, SW_HIDE);
  ShellExecute(0, open, cmd.exe, /c powercfg /x /hibernate-timeout-dc 0, nil, SW_HIDE);
  ShellExecute(0, open, cmd.exe, /c powercfg /x /standby-timeout-ac 0, nil, SW_HIDE);
  ShellExecute(0, open, cmd.exe, /c powercfg /x /standby-timeout-dc 0, nil, SW_HIDE);
end;

procedure EnableWindowsFirewall(turnOn: Boolean);
const
  firewall_cmd: array[Boolean] of string
    = (/c netsh advfirewall set allprofiles state off,
      /c netsh advfirewall set allprofiles state on);
begin
  ShellExecute(0, open, cmd.exe, PChar(firewall_cmd[turnOn]), nil, SW_HIDE);
end;

procedure OpenRemoteDesktop;
var
  Reg: TRegistry;
  v: Integer;
  sText: string;
begin
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_LOCAL_MACHINE;
  if not Reg.OpenKey(SYSTEM\ControlSet001\Control\Terminal Server, True) then
    Exit;
  Reg.WriteInteger(fDenyTSConnections, 0);
  Reg.CloseKey;
  Reg.Free;

  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_LOCAL_MACHINE;
  if not Reg.OpenKey(SYSTEM\ControlSet001\Services\SharedAccess\Epoch, True) then
    Exit;
  v := Reg.ReadInteger(Epoch);
  Reg.WriteInteger(Epoch, v + 3);
  Reg.CloseKey;
  Reg.Free;

  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_LOCAL_MACHINE;
  if not Reg.OpenKey(SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules, True) then
    Exit;
  sText := Reg.ReadString(RemoteDesktop-Shadow-In-TCP);
  StringReplace(sText, Active=FALSE, Active=TRUE, []);
  Reg.WriteString(RemoteDesktop-Shadow-In-TCP, sText);

  sText := Reg.ReadString(RemoteDesktop-UserMode-In-TCP);
  StringReplace(sText, Active=FALSE, Active=TRUE, []);
  Reg.WriteString(RemoteDesktop-UserMode-In-TCP, sText);

  sText := Reg.ReadString(RemoteDesktop-UserMode-In-UDP);
  StringReplace(sText, Active=FALSE, Active=TRUE, []);
  Reg.WriteString(RemoteDesktop-UserMode-In-UDP, sText);

  Reg.CloseKey;
  Reg.Free;

  SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);
end;

 

2019-10-19 打开远程桌面

标签:write   shared   epo   exe   isp   lru   controls   local   str   

原文地址:https://www.cnblogs.com/onlyou13/p/11704801.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!