Monday, June 22, 2009

Reinstalled my HTPC

My HTPC was giving more and more problems and so I decided to reinstall the system. I'm running Windows 7 on my laptop and workstation so I wanted to try it on the HTPC as well. I did run into a couple of problems but though, here's what I needed to fix:

The soundcard of my Biostar P4VBM800 motherboard was working. The onboard chip is a C-Media CMI9761, which should be AC97 compatible but Windows did not detect it. after a little trial and error I found these drivers. Audio's working fine now, even the digital output works.

My ATI Radeon X1600 was detected but the standard MS driver does not support OpenGL. After trying a couple of solutions I found that the 7.11 Catalyst Vista Drivers work fine.

My HTPC is quite old (Pentium 4 @2,53 GHz with 1 GB RAM) but Windows 7 was running like a champ, better then XP and of course the biblically terrible Vista. So now I needed to install some media players:

First I installed XBMC as my main media center. This was the main reason I needed to get OpenGL going. XBMC does not do hardware accelerated video playback so I also installed MPC-HC and now my old HTPC is capable of 720p video playback at 25% CPU load.

Last I installed Hulu and used HotSpot Shield to access Hulu outside of the US. Video playback is fairly watchable on low quality, I'm going to check some other VPN solutions to see if I can get this to work better.

Tuesday, June 16, 2009

VBScript: Remove old Windows Updates

My virtual machines regularly fill up their system disks, with old uninstall information. I was getting tired of fixing this manually, so I wanted to create a script to do this automatically. I found a script that removed all updates and modified it to only remove updates older than 90 days:


Option Explicit
Dim o, oShell, nConfirm
Set o = WScript.Application
o.Interactive = True
Set oShell = CreateObject("WScript.Shell")
nConfirm = oShell.Popup("Do you want to remove Windows Update Uninstall Files?", 0, "Remove Windows Update Uninstall Files", 4 + 32)
If nConfirm = 7 Then
o.Quit 0
End If
Dim oFSO, sWinDir, oFolder, oDictionary, oSubFolder, sFolderName, sFolderPath, sUpdateName, sDeleted, sFolderDate
Set oFSO = CreateObject("Scripting.FileSystemObject")
sWinDir = oFSO.GetSpecialFolder(0)
sDeleted = vbNullString
Set oFolder = oFSO.GetFolder(sWinDir)
Set oDictionary = CreateObject("Scripting.Dictionary")
For Each oSubFolder In oFolder.SubFolders
sFolderName = LCase(oSubFolder.Name)
sFolderPath = LCase(oSubFolder.Path)
'Check date of update
sFolderDate = oSubFolder.DateCreated
If Left(sFolderName, 12) = "$ntuninstall" And Mid(sFolderName, 13, 2) = "kb" Or Mid(sFolderName, 13, 2) = "q" Then
sUpdateName = Mid(sFolderName, 13, Len(sFolderName) - 13)
'Remove update if older than x days
If DateDiff("d", sFolderDate, Now) > 90 Then
oDictionary.Add sUpdateName, sFolderPath
End If
End If
Next
For Each sUpdateName in oDictionary.Keys
sDeleted = sDeleted & vbCrLF & sUpdateName
sFolderPath = oDictionary.Item(sUpdateName)
On Error Resume Next
oShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & sUpdateName & "\"
On Error Goto 0
oShell.Run "%ComSpec% /C RD /S /Q " & Chr(34) & sFolderPath & Chr(34), 0, True
Next
If Len(sDeleted) > 0 Then
WScript.Echo "The uninstall data for the following updates are now removed:" & vbCrLf & UCase(sDeleted), vbOKOnly
sDeleted = vbNullString
Else
WScript.Echo "No Windows Update Folders found for removal", vbOKOnly + vbInformation, "Nothing To Do"
End If
o.Quit 0

Save this code as removeOldUpdates.vbs and schedule a task to run weekly.

I'm thinking about expanding this script to clean up all kinds of temporary files.

Thursday, June 11, 2009

VBScript: Find username by AD fullname

I needed to find the username for a large number of active directory users. Turns out it's actually quite easy to do this with VBScript. Save the following script as a VBScript, for instance username.vbs. Change "domainname" to your own domain name.

Set oArgs = WScript.Arguments
Set objDomain = GetObject("WinNT://domainname")
objDomain.Filter = Array("User")
str2Find = oArgs(0)
For Each aUser In objDomain
If LCase(str2Find) = LCase(aUser.FullName) Then
Wscript.Echo str2Find & "=" & aUser.Name
strUser = aUser.Name
End If
Next
Set objDomain = Nothing

Now you can search a username by running: cscript username.vbs "Full Username"