0% found this document useful (0 votes)
19 views

RDP

Uploaded by

gemskpt
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

RDP

Uploaded by

gemskpt
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

'==========================================================================

'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.SetDWORDValue HKEY_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

You might also like