zoukankan      html  css  js  c++  java
  • Powershell 开启远程桌面

    function Set-RemoteDesktop
    {
      while($InNumber -ne 6)
      {
      Write-Host " ##########################################################" -ForegroundColor Green
      Write-Host " # 1、自定义远程桌面端口;                                #"
      Write-Host " # 2、开启远程桌面;                                      #"
      Write-Host " # 3、开启防火墙远程桌面出入端口;                        #"
      Write-Host " # 4、恢复系统默认的远程桌面端口;                        #"
      Write-Host " # 5、禁用远程桌面;                                      #"
      Write-Host " # 6、退出菜单;                                          #"
      Write-Host " # ########################################################" -ForegroundColor Green
      $InNumber = Read-Host "输入编号进行操作"

          switch ($InNumber)
          {
              1 {
                  $PortNumber = Read-Host "请输入修改远程桌面端口号"
                  Set-ItemProperty -Path 'HKLM:SYSTEMCurrentControlSetControlTerminal ServerWinStationsRDP-Tcp' -Name 'PortNumber' -Value $PortNumber
                  $PortResult = Get-ItemProperty -Path 'HKLM:SYSTEMCurrentControlSetControlTerminal ServerWinStationsRDP-Tcp' -Name 'PortNumber'
                  if($PortResult.PortNumber -eq $PortNumber)
                      {
                        Write-Host "已经成功修改端口为$PortNumber" -ForegroundColor Green
                      }
                      else
                      {
                        Write-Error "端口修改失败,请重试...."
                      }
              }
              2 {
                  Set-ItemProperty -Path 'HKLM:SYSTEMCurrentControlSetControlTerminal Server' -Name 'fDenyTSConnections' -Value 0
                  Write-Host 正在重启 Remote Desktop Services ... -ForegroundColor DarkYellow
                  Set-Service TermService -StartupType Automatic -Status Running -PassThru             
              }
              3 {
                  $Check = New-NetFirewallRule -DisplayName "Allow RDP" -Direction Inbound -Protocol TCP -LocalPort $PortNumber -Action Allow
                  if($Check.PrimaryStatus -eq 'OK')
                    {
                        Write-Host "成功设置防火墙策略" -ForegroundColor Green
                    }
                    else
                    {
                        Write-Error "防火墙策略设置失败,请重试..."
                    }

              }
              4 {
                  Set-ItemProperty -Path 'HKLM:SYSTEMCurrentControlSetControlTerminal ServerWinStationsRDP-Tcp' -Name 'PortNumber' -Value 3389             
                  $PortResult = Get-ItemProperty -Path 'HKLM:SYSTEMCurrentControlSetControlTerminal ServerWinStationsRDP-Tcp' -Name 'PortNumber'
                  if($PortResult.PortNumber -eq 3389)
                      {
                        Write-Host "已经成功恢复系统默认设置" -ForegroundColor Green
                      }
                      else
                      {
                        Write-Error "恢复失败,请重试...."
                      }
         
              }
              5 {
               
                  Write-Host 正在停止 Remote Desktop Services ... -ForegroundColor DarkYellow
                  Set-Service TermService -StartupType Disabled -Status Stopped -PassThru
                  Set-ItemProperty -Path 'HKLM:SYSTEMCurrentControlSetControlTerminal Server' -Name 'fDenyTSConnections' -Value 1
              }
              6 {}
              Default { Write-Error "请输入1-5编号"}
          }
        Start-Sleep 2
        Invoke-Command {cls}
        }
    }

    image

  • 相关阅读:
    pytorch-卷积基本网络结构-提取网络参数-初始化网络参数
    pytorch-mnist神经网络训练
    python 面对对象 类(继承, 多态)
    注意机制CBAM
    python sqlalchemy 进行 mysql 数据库操作
    python pymysql 连接 mysql数据库进行操作
    mysql数据库基础
    python正则表达式解析(re)
    python 装饰器 (test = submit(test))
    对opencv读取的图片进行像素调整(1080, 1920) 1.cv2.VideoCapture(构造图片读取) 2.cv2.nameWindow(构建视频显示的窗口) 3.cv2.setWindowProperty(设置图片窗口的像素) 4.video_capture(对图片像素进行设置)
  • 原文地址:https://www.cnblogs.com/motools/p/3386942.html
Copyright © 2011-2022 走看看