# 3389脚本开启代码(vbs版)
将以下代码复制到记事本里并保存为rots.vbs
on error resume next
set utstreem=wscript.stdout
set instreem=wscript.stdin
if (lcase(right(wscript.fullname,11))="wscript.exe") then
set bjShell=wscript.createObject("wscript.shell")
objShell.Run("cmd.exe /k cscript. //nologo "&chr(34)&wscript.scriptfullname&chr(34))
wscript.quit
end if
if wscript.arguments.count<3 then
usage()
wscript.echo "Not enough parameters."
wscript.quit
end if
ipaddress=wscript.arguments(0)
username=wscript.arguments(1)
password=wscript.arguments(2)
if wscript.arguments.count>3 then
port=wscript.arguments(3)
else
port=3389
end if
if not isnumeric(port) or port<1 or port>65000 then
wscript.echo "The number of port is error."
wscript.quit
end if
if wscript.arguments.count>4 then
reboot=wscript.arguments(4)
else
reboot=""
end if
usage()
outstreem.write "Conneting "&ipaddress&" ...."
set bjlocator=createobject("wbemscripting.swbemlocator")
set bjswbemservices=objlocator.connectserver(ipaddress,"root/cimv2",username,password)
objswbemservices.security_.privileges.add 23,true
objswbemservices.security_.privileges.add 18,true
showerror(err.number)
outstreem.write "Checking OS type...."
set colinstoscaption=objswbemservices.execquery("select caption from win32_operatingsystem")
for each objinstoscaption in colinstoscaption
if instr(objinstoscaption.caption,"Server")>0 then
wscript.echo "OK!"
else
wscript.echo "OS type is "&objinstoscaption.caption
outstreem.write "Do you want to cancel setup?[y/n]"
strcancel=instreem.read
if lcase(strcancel)<>"n" then wscript.quit
end if
next
outstreem.write "Writing into registry ...."
set bjinstreg=objlocator.connectserver(ipaddress,"root/default",username,password).get("stdregprov")
HKLM=&h80000002
with objinstreg
.createkey ,"SOFTWARE\Microsoft\Windows\CurrentVersion\netcache"
.setdwordvalue HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\netcache","Enabled",0
.createkey HKLM,"SOFTWARE\Policies\Microsoft\Windows\Installer"
.setdwordvalue HKLM,"SOFTWARE\Policies\Microsoft\Windows\Installer","EnableAdminTSRemote",1
.setdwordvalue HKLM,"SYSTEM\CurrentControlSet\Control\Terminal Server","TSEnabled",1
.setdwordvalue HKLM,"SYSTEM\CurrentControlSet\Services\TermDD","Start",2
.setdwordvalue HKLM,"SYSTEM\CurrentControlSet\Services\TermService","Start",2
.setstringvalue HKLM,".DEFAULT\Keyboard Layout\Toggle","Hotkey","1"
.setdwordvalue HKLM,"SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp","PortNumber",port
end with
showerror(err.number)
rebt=lcase(reboot)
if rebt="/r" or rebt="-r" or rebt="\r" then
outstreem.write "Now, reboot target...."
strwqlquery="select * from win32_operatingsystem where primary='true'"
set colinstances=objswbemservices.execquery(strwqlquery)
for each objinstance in colinstances
objinstance.win32shutdown(6)
next
showerror(err.number)
else
wscript.echo "You need to reboot target."&vbcrlf&"Then,"
end if
wscript.echo "You can logon terminal services on "&port&" later. Good luck!"
function showerror(errornumber)
if errornumber Then
wscript.echo "Error 0x"&cstr(hex(err.number))&" ."
if err.description <> "" then
wscript.echo "Error description: "&err.description&"."
end if
wscript.quit
else
wscript.echo "OK!"
end if
end function
function usage()
wscript.echo string(79,"*")
wscript.echo "ROTS v1.01"
wscript.echo "Remote Open Terminal services Script, by zzzEVAzzz"
wscript.echo "Welcome to visite www.isgrey.com"
wscript.echo "Usage:"
wscript.echo "cscript. "&wscript.scriptfullname&" targetIP username password [port] [/r]"
wscript.echo "port: default number is 3389."
wscript.echo "/r: auto reboot target."
wscript.echo string(79,"*")&vbcrlf
end function
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
####################################################### 描述:远程启动终端服务的windows脚本。 特点:不依赖于目标的ipc$开放与否。 原理:直接访问目标的windows管理规范服务(WMI)。该服务为系统重要服务,默认启动。 支持平台:win2kpro win2kserver winxp win.net 使用方法: 在命令行方式下使用windows自带的脚本宿主程序cscript.exe调用脚本,例如:
c:\>cscript ROTS.vbs <目标IP> <用户名> <密码> [服务端口] [自动重起选项]
服务端口: 设置终端服务的服务端口。默认是3389。 自动重起选项: 使用/r表示安装完成后自动重起目标使设置生效。使用此参数时,端口设置不能忽略。
脚本会判断目标系统类型,如果不是server及以上版本,就会提示你是否要取消。 因为pro版不能安装终端服务。 如果你确信脚本判断错误,就继续安装好了。
如果要对本地使用,IP地址为127.0.0.1或者一个点(用.表示),用户名和密码都为空 ##################################
# 写在最后
如果你觉得冰河写的还不错,请微信搜索并关注「 冰河技术 」微信公众号,跟冰河学习高并发、分布式、微服务、大数据、互联网和云原生技术,「 冰河技术 」微信公众号更新了大量技术专题,每一篇技术文章干货满满!不少读者已经通过阅读「 冰河技术 」微信公众号文章,吊打面试官,成功跳槽到大厂;也有不少读者实现了技术上的飞跃,成为公司的技术骨干!如果你也想像他们一样提升自己的能力,实现技术能力的飞跃,进大厂,升职加薪,那就关注「 冰河技术 」微信公众号吧,每天更新超硬核技术干货,让你对如何提升技术能力不再迷茫!