查询远程桌面服务状态:
get-wmiobject -query "select * from win32_service where name='TermService'" | out-string
下面自定义函数,在本地执行下面脚本,开启和关闭远程桌面,win7 、2008可以执行,在win 2003需要稍微修改一点
[javascript] view plaincopy
- write-host "---------------华丽的分割线------------------"
- function OTR(){
- $ts=get-WMIObject Win32_TerminalServiceSetting -Namespace ROOT\CIMV2\TerminalServices
- $r=$ts.AllowTSConnections
- if($r -eq 1)
- {
- Write-Host "远程桌面处于开启状态,无需重复开启"
- }else{
- $ts.SetAllowTSConnections(1) | Out-Null
- Write-Host "远程桌面开启成功"
- }
- }
- function CTR(){ <