Showing posts with label vbscript. Show all posts
Showing posts with label vbscript. Show all posts

Saturday, February 7, 2009

Enable Remote Desktop Access

A newly provisioned Windows server or desktop may not have had Remote Desktop enabled. That can certainly make it more difficult to stay in your seat.

The simple script below will enable Remote Desktop using WMI. It takes effect in a few seconds.

Supply a username and password if you don't have administrative rights natively. Yes, this exposes the password.


strComputer = "."
strUsername = ""
strPassword = ""

If WScript.Arguments.Count > 0 Then
strComputer = WScript.Arguments(0)
If Left(strComputer, 2) = "\\" Then
strComputer = Mid(strComputer, 3)
End If
WScript.Echo "Querying \\" & strComputer & "..." & vbCrLf
End If

If WScript.Arguments.Count > 1 Then
strUserName = WScript.Arguments(1)
End If

If WScript.Arguments.Count > 2 Then
strPassword = WScript.Arguments(2)
End If

Set objLocator = CreateObject("WBEMScripting.SWBEMLocator")
Set objWMIService = objLocator.ConnectServer(strComputer, "root/cimv2", _
strUsername, strPassword)

Set colItems = objWMIService.ExecQuery("Select * from Win32_TerminalServiceSetting")
For Each objItem In colItems
WScript.Echo "AllowTSConnections: " & objItem.AllowTSConnections
If objItem.AllowTSConnections = 0 Then
WScript.Echo "Enabling Terminal Services connections..."
objItem.SetAllowTSConnections(1)
Else
WScript.Echo "Already enabled."
End If
Next

Sunday, January 18, 2009

Logfile Maintenance

Keep logfile sprawl on your servers in check with the below script. A bit of a hack; it could likely use some cleanup. Customize the aFolders array for a list of directories to recurse. Customize sFilePattern as a regular expression to match the logfiles you see on your servers.

The script accepts an argument for the number of days. Any matching files that are older than this number of days are targets for deletion.

As with all file deletion scripts, the potential for danger is high. Use the 2nd argument of TEST to be sure of the intended results.

I install the script as a scheduled task on our servers, wrapped in a CMD file. It even updates itself at each run from Amazon AWS. More on that later.


PurgeLogs.vbs.txt