Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Terminal Services Port Changer Script. Help Needed...

Status
Not open for further replies.

baldhead

Technical User
Apr 27, 2004
111
0
0
US
I am making a script for easily changing the terminal services port on a windows 2003/2000 server or on a windows XP workstation. The problem is that I don't know how to take the users input and convert this into hexidecimal in the dword PortNumber entry. I have bolded the area where I would need to take the users decimal input and convert this into hexidecimal to place in this dword. I would greatly appreciate any help someone could provide.

thanks

Code:
'Script used to change the Default Terminal Services Port

'On Error Resume Next

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")

Dim WshNet       'WshNetwork object
Dim TSPortChange 'Variable to hold the new TS port
Dim Continue
Dim Exiting

'Create reference to Windows Scripting Host Network Object
Set WshNet = wscript.CreateObject("Wscript.Network")

'Providing an Input box to Enter TS Port

TSPortChange = InputBox("What Port would you like your Terminal Server or Remote Desktop Machine on? (i.e. 4000)","TS Port Changer")

Continue = MsgBox ("Is port "& TSPortChange &" correct?", 4, "TS Port Changer")
If (Continue = 7) Then
	Exiting = MsgBox ("Nothing has been done. Exiting...", 64, "TS Port Changer")
Else
	Call WSHShell.Run("cmd.exe /c copy port.reg portfinal.reg /Y")
	Call WSHShell.Run("cmd.exe /c echo ""[b]PortNumber"=dword:00000fa1[/b]"" >> portfinal.reg")	
	Call WSHShell.Run("cmd.exe /c regedit /s portfinal.reg")
	MsgBox ("Port chanaged to "& TSPortChange &", 64, "TS Port Changer")
End If
 
Why not use the Hex function ?
Call WSHShell.Run("cmd.exe /c echo ""PortNumber"=dword:" & Right("0000000" & Hex(TSPortChange), 8) & """ >> portfinal.reg", , True)


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thats just it, I don't know functions off the top of the top of my head how to implement them like a lot of you. Can you explain to me what you did and how this works to achieve what I'm looking for? by the way, I get an:

Line: 26
Char: 56
Error: Expected ')'

on the line you gave. I appreciate your quick response PHV, you are definately one of the experts here in VBS.


 
Could you please your actual line 26 ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Call WSHShell.Run("cmd.exe /c echo ""PortNumber"=dword:" & Right("0000000" & Hex(TSPortChange), 8) & """ >> portfinal.reg", , True)
 
Missing a double quote in front of =dword:"
Here's what the line should look like:

Call WSHShell.Run("cmd.exe /c echo ""PortNumber""=dword:" & Right("0000000" & Hex(TSPortChange), 8) & """ >> portfinal.reg", , True)
 
Call WSHShell.Run("cmd.exe /c echo ""PortNumber=dword:" & Right("0000000" & Hex(TSPortChange), 8) & """ >> portfinal.reg", , True)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
can you use

WshShell.RegWrite "hklm\software\registrypath\PortNumber", Right("0000000" & Hex(TSPortChange), 8),"REG_DWORD
 
figured it out guys. thanks mrmovie, your idea simplified things quite a bit. I also appreciate all the other help that was given to me on this task. I ended up finding that there was no need to convert the users input into HEX, the registry takes care of this already. here is my final code that will work every time:

Code:
'Script used to change the Default Terminal Services Port

'On Error Resume Next

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")

Dim WshNet       'WshNetwork object
Dim TSPortChange 'Variable to hold the new TS port
Dim Continue
Dim Exiting

'Create reference to Windows Scripting Host Network Object
Set WshNet = wscript.CreateObject("Wscript.Network")

'Providing an Input box to Enter TS Port

TSPortChange = InputBox("What Port would you like your Terminal Server or Remote Desktop Machine on? (i.e. 4000)","TS Port Changer")

Continue = MsgBox ("Is port "& TSPortChange &" correct?", 4, "TS Port Changer")
If (Continue = 7) Then
	Exiting = MsgBox ("Nothing has been done. Exiting...", 64, "TS Port Changer")
Else
	WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\PortNumber", ""& TSPortChange &"" , "REG_DWORD"
	Ending = MsgBox ("Port chanaged to "& TSPortChange &"", 64, "TS Port Changer")
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top