Wednesday, September 30, 2009

Using Group Policy Preferences to configure Windows Explorer

One of the great new features in Windows 7 are “Preferences”. This are files, folders, registry values etc. you can easily configure using an GPO to set values on the client.

As these are called “Preferences” the purpose of it is to allow the the administrator to configure something but still allow the user to change it later on. When using an policy, the user can change anything.

Preparing the Windows 7 rollout, I found that some settings inside the Windows Explorer should be changed, but I only wanted to change certain values, not the entire “Folder Options” (which is also possible).

Here are the list of values I’m changing using the Registry preference on all of the Windows 7 machines (all these are user settings, so the root is always HKEY_CURRENT_USER):

Folder Options -> Search -> Always search file names and contents (ON)

Path: Software\Microsoft\Windows\CurrentVersion\Explorer\Search\PrimaryProperties\UnindexedLocations
Name: SearchOnly (REG_DWORD)
Value: 0

Folder Options -> Search -> How to search -> Don't use the index when search in file folder for system files (ON)

Path: Software\Microsoft\Windows\CurrentVersion\Explorer\Search\Preferences
Name: WholeFileSystem (REG_DWORD)
Value: 1

Folder Options -> View -> Hide extensions for known file types (OFF)

Path: Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
Name: HideFileExt (REG_DWORD)
Value: 0

Folder Options -> Navigation Pane -> Show all folders (ON)

Path: Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
Name: NavPaneShowAllFolders (REG_DWORD)
Value: 1

Folder Options -> Navigation Pane ->Automatically expand to current folder (ON)

Path: Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
Name: NavPaneExpandToCurrentFolder (REG_DWORD)
Value: 1

Thursday, September 17, 2009

Misusing ROBOCOPY to delete old files

We have a lot of servers that store files that are not needed after some time (for example, Logfiles). Usually these files are sometimes needed for some days but not after that.

Therefore I needed a fast and quick way to delete old files. I found some programs that are able to do so, but I wanted a really simple solution.

After some testing, I decided to “misuse” Robocopy for that. Actually, Robocopy has no option to delete old files but it has the strange option “/CREATE”. This option will copy all files but with 0 bytes, so the copy is very fast.

The Batchfile that does the real work (DeleteOldFiles_Exec.bat) looks like this:


SET SRC=%1
SET PATRN=%2
SET DAYS=%3
IF NOT EXIST C:\TEMP\. md C:\TEMP
IF NOT EXIST C:\TEMP\TRASH\. md C:\TEMP\trash
%~dp0robocopy %SRC% "C:\TEMP\TRASH" %PATRN% /R:1 /s /mov /create /XA:A /minage:%days%
Rem /L for List only
rd C:\TEMP\TRASH /s /q


It will move the given files (%PATRN%) from the source folder (%SRC%) that are older than the given days (%DAYS%). The options for Robocopy are pretty easy except the /CREATE option (see above) and the /XA:A option which excludes all files with the ARCHIVE attribute set. This option is set since I do not want to delete any file that hasn't been backed up.

I then call this batch like this:

CALL deleteoldfiles_exec "C:\Temp" *.* 10

This will delete all files (*.*) in the directory C:\Temp that are older than 10 days.