Enable a Remote Desktop connection with this member-submitted admin script
Takeaway: TechRepublic asked members to submit their favorite network administration scripts and this is one of the responses. This script allows an administrator to remotely enable the Remote Desktop connection.
By Manes Claude
TechRepublic asked members to submit their favorite Network Administration scripts for possible publication. One of the latest to make a submission was Manes Claude. This contribution to TechRepublic earned Manes Claude $100 and the satisfaction derived from seeing those scripts published.
Earn $100 for your admin script
Let us pay you for your original scripts so that we can publish them as downloads on TechRepublic and allow your fellow IT professionals to benefit from your scripting savvy. We only ask that you put in the appropriate comments to your scripts so that it's easy to tell what the script is doing and which variables might need to be customized. Send us your original admin scripts and we'll pay you $100 for each one that we publish as a TechRepublic download.
Editor's note: This script is included in the downloadable Zip file for your convenience.
In their own words
Find enclosed a "small" script that allows an administrator to remotely enable the Remote Desktop connection.
As an admin, you might need to connect remotely to a server in order to perform some specific management tasks. You normally use the Remote Desktop connection. However, from time to time, you realize that the feature is not enabled on the specific server you want to connect to and this server is not located on your site but located on a remote site where nobody can really perform the operation for you.
To solve this problem, I use this small script, which simply changes a registry key on the remote server and performs a reboot. When the machine is rebooted, I'm able to connect using the Remote Desktop Connection utility
Listing A
'======================================================
'Script_Name :Enable_RDP_Remotely.vbs
'Description : This script enables the Remote desktop functionality remotely
' The script perform registry changes. In order to apply those changes
' a reboot is required......
'Date : 19/11/2005
'Version: 0.1
'Written by : Claudio Manes (aka Griffon)
'Remarks and Limitations : Works for WinXP and Windows 2003 Servers.
Win2000 has not been tested Yet
' A Reboot is required
'======================================================
'Error Handling, Declare Constants and Variable...
'---------------------------
On Error Resume Next
Const HKEY_LOCAL_MACHINE = &H80000002
dim vbYesNo
dim vbQuestion
vbYesNo = 4
vbQuestion = 48
'Create inputbox in order to collect the computer Name
'----------------------------
StrComputer=InputBox("Enter Name of the Remote Computer...","Connect to Remote Computer")
'Connect to the Remote Registry using WMI space
...We assume that you have administrative rights
'---------------------------------
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
'Error handling...if not able to connect to the remote machine...you will be notified
'---------------------------------------------------------
If Err.Number <> 0 Then
MsgBox "Error. Computer not accessible...Possible reasons" & vbcrlf & vbcrlf &_
"1.the computer name is incorrect" & vbcrlf & _
"2.the computer is not running... " & vbcrlf & _
"3.the currently logged-on user has no admin rights"& vbcrlf & vbcrlf &_
"End of Script",64,"An Error occured"
WScript.Quit()
End If
'to enable remote desktop,
'registry key HKLM\System\CurrentControlSet\Control\Terminal Server\fsDenyTSConnections
'should be set to 0
strKeyPath = "System\CurrentControlSet\Control\Terminal Server"
strValueName = "fDenyTSConnections"
dwValue = 0
oReg.SetDWORDValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
'Ask the User if he wants to reboot the machine right now or do it later....
'-------------------------------------
retry= msgbox ("A Reboot is required in order to apply the changes" & vbcrlf & _
"Do you want to reboot the remote computer Now ?",52,"Reboot the Remote Machine")
Select Case retry
Case vbYes
'WMI Code used to reboot the remote computer
Set oWMI = GetObject("winMgmts:\\"& strComputer)
Set colComputers = oWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each refComputer In colComputers
If refComputer.Reboot() <> 0 Then
WScript.Echo "Reboot failed"
Else
WScript.Echo "Computer rebooted"
WScript.echo " Action completed sucessfully "
End If
Next
Case vbNo
WScript.Echo("Changes will not be applied for the moment")
End Select
Print/View all Posts Comments on this article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SponsoredWhite Papers, Webcasts, and Downloads
- Ten Ways To Protect Your IT Infrastructure: Reduce costs while protecting critical business systems Eaton Corp.
- Creating Operational Efficiencies in Identity and Access Management Quest Software
- How Voice over IP Works Cisco Systems
- Web 2.0 for the Enterprise: Setting the Foundation for Success Oracle
- Case Study: Productivity Doesn't Depend on a Desk Cisco Systems
Article Categories
- Security
- Security Solutions, IT Locksmith
- Networking and Communications
- E-mail Administration NetNote, Cisco Routers and Switches
- CIO and IT Management
- Project Management, CIO Issues, Strategies that Scale
- Desktops, Laptops & OS
- Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
- Data Management
- Oracle, SQL Server
- Servers
- Windows NT, Linux NetNote, Windows Server 2003
- Career Development
- Geek Trivia
- Software/Web Development
- Web Development Zone, Visual Basic, .NET
