VBScript
Windows XP Favorites Folder Redirection via GPOs
Per [MS-GPFR] - In Windows 2000 Server, Windows XP, and Windows Server 2003, a constant list of exactly five user profile folders can be redirected, including My Documents, My Pictures, Desktop, Start Menu, and Application Data.
[MS-GPFR]: Group Policy: Folder Redirection Protocol Extension documentation can be downloaded here.
So in other words folder redirection for Favorites and others file folders in not supported until Vista or later.
So using Folder Redirection for My Documents only I created two Group Policy objects. One GPO being the standard Folder Redirection Policy pointing serveral groups to various MyDocuments stores. With a second Group Policy object I added the following script to the logon process. The script sleeps for 30 seconds allowing time for other group policy objects to complete processing and then using special folders the script gets the MyDocuments location and appends \Favorites to the end and then populates the appropriate registry value to redirect Favorites. I additionally added a three minute timeout to the script incase the scripts hangs, not that it would, but you wouldn’t want it to hang indefinitely.
Simple Favorites Folder Redirection using Special Folders for MyDocuments
On Error Resume Next
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
WScript.Timeout 180
WScript.Sleep 30000
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
strValueName = "Favorites"
strValue = WshShell.SpecialFolders("MyDocuments") & "\Favorites"
oReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
Re-Usable VBScript Functions – Part I
In this Multi-Part Series I will post lists on VBScript Functions and Subs that I have either found or written. I am a big fan of turning any useful code into a functions and adding it to my default VBScript Template, it saves a ton of time on the next scripting task. By no means am I claiming I wrote all of these, most were just re-purposed into reusable functions. I hope you find these useful. In the later part of the series I will include my template I use to begin all my scripts.
Determine if the computer is a laptop:
Function IsLaptop(strComputer) On Error Resume Next Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" ) Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery", , 48 ) IsLaptop = False For Each objItem in colItems IsLaptop = True Next If Err Then Err.Clear On Error GoTo 0 End Function |
Example of use
If IsLaptop( "." ) Then WScript.Echo "Laptop Else WScript.Echo "Desktop or server End If |
Shell out a command line with switches:
Sub RunSwch(ByVal strRunCmd, strRunSwitch)
Dim objWshShell
Set objWshShell = CreateObject("WScript.Shell")
objWshShell.Run Chr(34) & strRunCmd & Chr(34)& " " & strRunSwitch, 1, True
Set objWshShell = Nothing
End Sub |
Example of use
RunSwch "C:\Program Files\ApplicationX\Start.exe","/S /X /Log C:\log.log" |
Shell out a command line without switches:
Sub Run(ByVal strRunCmd)
Dim objWshShell
Set objWshShell = CreateObject("WScript.Shell")
objWshShell.Run Chr(34) & strRunCmd & Chr(34), 1, True
Set objWshShell = Nothing
End Sub |
Example of use
Run "C:\Program Files\ApplicationX\Start.exe" |
