delphi修改注册表那些常用操作(续)

本文介绍了如何使用Delphi进行注册表操作,包括添加环境变量,如利用InstallPath设置程序安装路径,并探讨了开启远程桌面服务的相关技巧。
摘要由CSDN通过智能技术生成

添加环境变量:

procedure InstallPath(path: string);
var
  r: TRegistry;
  sysPath: string;
  dwReturnValue: Cardinal;
begin
  r := TRegistry.Create;
  try
    r.RootKey := HKEY_LOCAL_MACHINE;
    if r.OpenKey('System\CurrentControlSet\Control\Session Manager\Environment', true) then
    begin
      sysPath := r.ReadString('Path');
      sysPath := sysPath + ';' + path;
      r.WriteExpandString('Path', sysPath);
      SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
        LParam(pchar('Environment')), SMTO_ABORTIFHUNG, 5000, dwReturnValue);
    end;
  finally
    r.CloseKey;
    r.Free;
  end;
end;

InstallPath(ExtractFileDir(ParamStr(0)));

 

打开远程桌面服务:

procedure TForm_Reg.OpenTerminalServer;
var
  Reg1: TRegistry;
begin
  Reg1 := TRegistry.Create;
  try
    Reg1.RootKey := HKEY_LOCAL_MACHINE;
    if Reg1.OpenKey('SYSTEM\CurrentControlSet\Control\Terminal Server', true) then
    begin
      Reg1.WriteInteger('fDenyTSConnections', 0);
    end;
  finally
    Reg1.CloseKey;
    Reg1.Free;
  end;
end;


 

1:
          begin
            { 禁用CMD }
            Reg := TRegistry.Create;
            Reg.RootKey := HKEY_USERS;
            if Reg.OpenKey(rdpUser + '\Software\Policies\Microsoft\Windows\System', true) then
            begin
              Reg.WriteInteger('DisableCMD', 2);
            end;
            Reg.CloseKey;
            Reg.Destroy;
            ProgressNT.Position := 1;
            { CMD }
          end;
        2:
          begin
            { 禁用磁盘 }
            Reg := TRegistry.Create;
            Reg.RootKey := HKEY_USERS;
            if Reg.OpenKey
              (rdpUser + '\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',true) then
            begin
              Reg.WriteInteger('NoViewOnDrive', NTpolicyInfo.ex_2);
            end;
            Reg.CloseKey;
            Reg.Destroy;
            ProgressNT.Position := 2;
            { }
          end;
        3:
          begin
            { 隐藏磁盘 }
            Reg := TRegistry.Create;
            Reg.RootKey := HKEY_USERS;
            if Reg.OpenKey
              (rdpUser + '\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer', true) then
            begin
              Reg.WriteInteger('NoDrives', NTpolicyInfo.ex_3);
            end;
            Reg.CloseKey;
            Reg.Destroy;
            ProgressNT.Position := 3;
            { }
          end;
        4:
          begin
            { 运行某个指定程序 }
            Reg := TRegistry.Create;
            Reg.RootKey := HKEY_USERS;
            if Reg.OpenKey(rdpUser + '\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer', true) then
            begin
              Reg.WriteInteger('RestrictRun', 1);
            end;
            Reg.CloseKey;
            Reg.Destroy;
            ProgressNT.Position := 4;
            { }
          end;
        5:
          begin
            { 禁用开始菜单 }
            Reg := TRegistry.Create;
            Reg.RootKey := HKEY_USERS;
            if Reg.OpenKey(rdpUser + '\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer', true) then
            begin
              Reg.WriteInteger('NoSimpleStartMenu', 1);
              Reg.WriteInteger('NoRun', 1);
              Reg.WriteInteger('NoFind', 1);
              Reg.WriteInteger('NoSetTaskbar', 1);
              Reg.WriteInteger('NoSetFolders', 1);
              Reg.WriteInteger('NoStartBanner', 1);
              Reg.WriteInteger('NoTrayContextMenu', 1);
              // Reg.WriteInteger('NoFileMenu', 1);
              Reg.WriteInteger('NoSaveSetting', 1);
              Reg.WriteInteger('NoStartMenuMorePrograms', 1);
              Reg.WriteInteger('NoRecentDocsMenu', 1);
              Reg.WriteInteger('NoWindowsUpdate', 1);
              Reg.WriteInteger('NoSMHelp', 1);
              Reg.WriteInteger('NoCommonGroups', 1);
              Reg.WriteInteger('NoStartMenuSubFolders', 1);
              Reg.WriteInteger('NoNtSecurity', 1);
              Reg.WriteInteger('NoControlPanel', 1);
              Reg.WriteInteger('NoUserNameInStartMenu', 1);
              Reg.WriteInteger('NoSMMyDocs', 1);
              Reg.WriteInteger('NoStartMenuNetworkPlaces', 1);
              Reg.WriteInteger('NoStartMenuMFUprogramsList', 1);
              Reg.WriteInteger('NoStartMenuPinnedList', 1);
            end;
            Reg.CloseKey;
            Reg.Destroy;
            ProgressNT.Position := 5;
            { }
          end;
        6:
          begin
            { 禁用控制面板 }
            Reg := TRegistry.Create;
            Reg.RootKey := HKEY_USERS;
            if Reg.OpenKey
              (rdpUser +
              '\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',
              true) then
            begin
              Reg.WriteInteger('NoControlPanel', 1);
            end;
            Reg.CloseKey;
            Reg.Destroy;
            ProgressNT.Position := 6;
            { }
          end;
        7:
          begin
            { 禁用任务栏 }
            Reg := TRegistry.Create;
            Reg.RootKey := HKEY_USERS;
            if Reg.OpenKey
              (rdpUser +
              '\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',
              true) then
            begin
              Reg.WriteInteger('NoSetTaskbar', 1);
            end;
            Reg.CloseKey;
            Reg.Destroy;
            ProgressNT.Position := 7;
            { }
          end;
        8:
          begin
            { 移除托盘区的项 }
            Reg := TRegistry.Create;
            Reg.RootKey := HKEY_USERS;
            if Reg.OpenKey
              (rdpUser +
              '\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',
              
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值