Script code for enabling the telnet service (1)

Source: Internet
Author: User

Some content of the Telnet service is described a lot. We will not go into details about its basic information and settings. Here we will mainly explain the implementation of wmi scripts such as enabling the telnet service through port 135. The Code is as follows:

On error resume next
Set xsjd = wscript. stdout
If (lcase (right (wscript. fullname, 11) = "wscript.exe") then
Set objShell = wscript. createObject ("wscript. shell ")
ObjShell. Run ("cmd.exe/k cscript // nologo" & chr (34) & wscript. scriptfullname & chr (34 ))
Wscript. quit
End if
Change = wscript. arguments (0)
Ip = wscript. arguments (1)
User = wscript. arguments (2)
Pass = wscript. arguments (3)
Main ()
Xsjd. write "connection" & ip ...."
Select case change
Case "1"
Set ob1_mi = createobject ("wbemscripting. swbemlocator ")
Set ob1_miservices = ob1_mi. connectserver (ip, "root/cimv2", user, pass)
Wscript. echo "the service you selected is to open the terminal service of the target host ."
If wscript. arguments. count <4 then
Wscript. echo "there are not enough parameters ."
Wscript. quit
End if
If wscript. arguments. count <4 then
Port = 3389
Else
Port = wscript. arguments (4)
End if
If not isnumeric (port) or port <1 or port> 65000 then
Wscript. echo "port error ."
Wscript. quit
End if
If wscript. arguments. count> 5 then
Reboot = wscript. arguments (5)
Else
Reboot = ""
End if
Ob1_miservices. security _. privileges. add 23, true
Ob1_miservices. security _. privileges. add 18, true
Error (err. number)
Xsjd. write "check over system type ...."
Set objcxwql1_ob1_miservices.exe cquery ("select caption from win32_operatingsystem ")
For each objinstoscaption in objcxwql
If instr (objinstoscaption. caption, "Server")> 0 then
Wscript. echo "OK! "
Else
Wscript. echo ":" & objinstoscaption. caption
Xsjd. write "are you sure you want to end? [Y/n]"
Strcancel = instreem. read
If lcase (strcancel) <> "n" then wscript. quit
End if
Next
Xsjd. write "opening the service. Please wait ...."
Set ob1_miinstreg = ob1_mi. connectserver (ip, "root/default", user, pass). get ("stdregprov ")
HKLM = & h80000002
With ob1_miinstreg
. 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
Error (err. number)
Rebt = lcase (reboot)
If rebt = "c" then
Xsjd. write "restart the target computer ...."
Strwql = "select * from win32_operatingsystem where primary = 'true '"
Set wqlstances1_ob1_miservices.exe cquery (strwql)
For each objinstance in wqlstances
Objinstance. win32shutdown (6)
Next
Error (err. number)
Else
Wscript. echo "your account requires sufficient permissions." & vbcrlf &""
End if
Wscript. echo "is enabled. You can connect to the terminal service at:" & port & ". Good luck! "
Wscript. quit
Case "2"
If wscript. arguments. count <6 then
Wscript. echo "the parameters for enabling the telnet service are insufficient ."
Wscript. quit
End if
Ntlm = wscript. arguments (4)
Port = wscript. arguments (5)
If not isnumeric (port) or port <1 or port> 65000 then
Wscript. echo "port error ."
Wscript. quit
End if
If not isnumeric (ntlm) or ntlm <0 or ntlm> 2 then
Main ()
Wscript. echo "NTML terminal type error ."
Wscript. quit
End if
Set ob1_mi = createobject ("wbemscripting. swbemlocator ")
Set ob1_miservices = ob1_mi. connectserver (ip, "root/default", user, pass)
Error (err. number)
Xsjd. write "sets the terminal type to NTLM =" & ntlm &"...."
Set ob1_mistance = ob1_miservices. get ("stdregprov ")
Set ob1_mimethod = ob1_mistance. methods _ ("SetDWORDvalue ")
Set ob1_miinparam = ob1_mimethod. inparameters. spawninstance _()
Ob1_miinparam. hdefkey = & h80000002
Ob1_miinparam. ssubkeyname = "SOFTWARE \ Microsoft \ TelnetServer \ 1.0"
Ob1_miinparam. svaluename = "NTLM"
Ob1_miinparam. uvalue = ntlm
Set ob1_mioutparam1_ob1_mistance.exe cmethod _ ("SetDWORDvalue", ob1_miinparam)
Error (ob1_mioutparam. returnvalue)

Xsjd. write "set the telnet port: port =" & port &"...."
Ob1_miinparam. svaluename = "TelnetPort"
Ob1_miinparam. uvalue = port
Set ob1_mioutparam1_ob1_mistance.exe cmethod _ ("SetDWORDvalue", ob1_miinparam)
Error (ob1_mioutparam. returnvalue)


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.