|
' EnableRemoteDesktop.vbs
' Copyleft 2004 Alejandro Leal
' ajleal@cantv.net
' Version 0.1 - August 20, 2004 - First version
' Version 0.2 - September 31, 2004 - OS Detection to prevent registry
' change if is not WinXP or Win2003
'
' This script ask for an machine name and enable Remote Desktop
' for Administration (Windows XP & Windows 2003).
'
' You have a royalty-free right to use, modify, reproduce, and
' distribute this script file in any way you find useful, provided that
' you agree that the copyright owner above has no warranty, obligations,
' or liability for such use.
Option Explicit
On Error Resume Next
Dim objReg, objWMIService, objItem, colItems
Dim strComputer, strKeyPath, strValueName, strValue
Const HKEY_LOCAL_MACHINE = &H80000002
If WScript.Arguments.Count <> 1 Then
strComputer = InputBox("Enter machine name you want to " &_
"enable Remote Desktop", "Machine Name?", "")
If strComputer = "" Then
Call cleanUP
End If
Else
strComputer = WScript.Arguments(0)
End If
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
If Err.Number <> 0 Then
Wscript.Echo Err.Number & " The remote machine (" & strComputer & ")" &_
" is unavailable or access denied."
Err.Clear
Call cleanUP
End If
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
strValueName = "CurrentVersion"
objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If strValue >= 5.1 Then
strKeyPath = "SYSTEM\CurrentControlSet\Control\Terminal Server"
strValueName = "fDenyTSConnections"
objReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If strValue = 0 Then
Wscript.Echo "Remote Desktop is already enabled on: " & strComputer
Call cleanUP
Else
strValue = 0
objReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
Wscript.Echo "Remote Desktop was enabled on: " & strComputer
Call cleanUP
End If
Else
Wscript.Echo "The remote machine (" & strComputer & ")" &_
"is not Windows XP or Windows 2003"
Call cleanUP
End If
'Cleanning UP
Sub cleanUP
Set strComputer = Nothing
Set strKeyPath = Nothing
Set strValueName = Nothing
Set strValue = Nothing
Set stdOut = Nothing
Set objReg = Nothing
WScript.Quit
End Sub
|
|
|
|