3389 script enabling code (vbs Version)

Source: Internet
Author: User
Set the following Code Copy to notepad and save as 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.exe cquery ("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
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.exe cquery (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

######################################## ###############
Description: Used to remotely start the terminal service.WindowsScript.
Feature: whether the target IPC $ is enabled or not.
Principle: directly access the target Windows Management Specification Service (Wmi ). This service isSystemImportant services, which are started by default.
Supported platforms: win2kpro win2kserver WINXP win.net
Usage:
InCommandUse the Script Host provided by windows in Line ModeProgramCscript.exe calls the script, for example:

C: \> cscript rots. vbs <target IP address> <User Name> <Password> [ServicePort] [Automatic Restart options]

Service port: Set the service port of the terminal service. The default value is 3389.
Automatic Restart option: Use/R to automatically restart the target after the installation is complete for the setting to take effect. When this parameter is used, port settings cannot be ignored.

The script will determine the target system type. If it is not a server or a later version, it will prompt you whether to cancel it.
Because the Pro Version cannot install Terminal Services.
If you are sure that the script is incorrectly determined, continue to install it.

If you want to use the IP address locallyAddressIt is 127.0.0.1 or a point (in. Format). The username and password are empty.
##################################

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.