Mittwoch, 29. Dezember 2010

Delete specific files

This script was developed to delete files with a specific extension inside a given folder. In this case, installation logs from MS Patch / Hotfix Installations will be deleted. This script can easily be adopted to delete other files also.

DIM fso, f, fc, file
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("c:\winxp")
Set fc = f.Files
For Each file in fc
  if strcomp(right(file.name,4),".log",1)=0 then
    fso.DeleteFile("c:\winxp\" & file.name)
  end if
Next

Delete specific folders

This script is designed to search and delete temporary folders, which are created by MS Patch / Hotfix Installations. The script can be easily adopted to be used for other folders also. This script will find and delete hidden and system folders also, so be careful when using it.
The script uses the Windows Scripting Host functions.

DIM fso, folder, subflds, fld
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("c:\winxp")
Set subflds = folder.SubFolders
For Each fld in subflds
  if strcomp(left(fld.name,1),"$",1)=0 then
    fso.DeleteFolder("c:\winxp\" & fld.name)
  end if
Next

Donnerstag, 2. Dezember 2010

Enable TimeMachine for Unsupported Drives

By Default, TimeMachine only supports Network Drives capable of the "afp" protokoll. The problem is, that these drives often are more expensive then regular one's dedicated for use in Windows Networks. MacOS X Supports "smb" protokoll too, but TimeMachine would not accept those drives by default. Following there is a short guide, how to enable that support. You will need the Terminal Console, so open it an continue:

1. Enable use of unsupported drives

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

2. Create Sparsebundle File

hdiutil create -size 200G -fs HFS+J -type SPARSEBUNDLE "MACNAME_MAC-adress.sparsebundle"

where:
-size defines Max. space used for Backups
MACNAME is the name of your Mac e.g. iMac
MAC-Adress is the MAC adress of your Ethernet Card

3. Mount Share and copy Sparsebundle File

Now mount the NAS Share to your Mac and copy the sparsebundle file onto.

Take care the share is mounted always and start TimeMachine. Now you're Done.

Dienstag, 16. November 2010

Enable / Disable Client Side Caching (Offline Files)

On Windows System, the function "Client Side Caching" can be used. This funktion caches a definded file and folder structure to the local harddisk. This aims to support laptop users when they are not connected to their (corporate) LAN. Because the whole topic is quite difficult, there would no deeper explaination at this point. I assume, you know what you're doing. Here is just a list of used RegKeys:

Key:
HKLM\Software\Microsoft\Windows\ CurrentVersion\NetCache

Value:
Enabled

String Value:
1 = Active
0 = Disabled

P.S.This setting can also be controlled using a GPO. In this case,the GPO overrides this RegKey.

Clear Pagefile at Shutdown

Unter Windows existiert die Funktion "ClearPageFileAtShutdown". Es ist ein weit verbreiteter Irrglaube, dass hierdurch das Pagefile beim herunterfahren des Systems gelöscht würde. Ein genaues Lesen des entsprechenden Originalartikels in der MS KB (auf englisch !), fördert dann zutage, dass die Verwendung des Begriffes "Clear" nicht löschen, im Sinne eines physikalischen entfernens der Datei, bezeichnet, sondern statt dessen ein Überschreiben der gesamten Datei mit Nullen. Je mehr Hauptspeicher sich in dem betroffenen System befindet, desto größer die Auslagerungsdatei und umso länger benötigt das System, bis die gesamte Datei einmal komplett überschrieben wurde. Die mag in Zeiten von 256 MB RAM noch erträglich gewesen sein, aber da mittlerweile mehrere GB RAM Standard sind, ergibt das eine spürbare Verlängerung der Shutdownzeit. Daher sollte die betreffende Funktion möglichst NICHT verwendet werden.

Key:
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management

Value:
ClearPageFileAtShutdown

Wert:
1 = An
0 = Aus

Freitag, 5. November 2010

Remove Network Printers

The following script has been written to disconnect all mapped Network Printers on a client computer. There are two examples. One using WMI and the other is using WSH Methods. Both are working. It's just a question of personal preference which one is chosen.

WSH Method
'Remove all Network printers but not local printers
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers = WshNetwork.EnumPrinterConnections
For i = 0 to Printers.Count - 1 Step 2
    If Left(ucase(Printers.Item(i+1)),2) = "\\" Then
        WScript.Echo Printers.Item(i+1)
        WSHNetwork.RemovePrinterConnection Printers.Item(i+1)
    End IF
Next

WMI Method
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Network = TRUE")
For Each objPrinter in colInstalledPrinters
    'objPrinter.Delete_
 Wscript.Echo objPrinter.Name
Next

Freitag, 10. September 2010

Search for specific Files and write to INI

This script was developed as a part of an automated backup solution for user data. It is the engine, which performs filesystem searches for files of a specified type (e.g. PST) using WMI Query. All found files will be written to an INI file with their complete path for further processing. The needed informations are read from a specific registry key.


'Script created by: Zierer, Markus
'Script created on: 2010 08 26
'
'This script performs file search operations and writes the results into an INI File.
'Note that it values stored in Windows Registry
'
'Prepare Variables
Dim objWMIService, objFSO, objTextFile
Const ForReading = 1, ForWriting = 2, ForAppending = 8
const HKCU = &H80000001
const HKLM = &H80000002
strComputer = "."
strRegKeyPath = "SOFTWARE\FITS\Software\Backup"
strRegValueExtension = "Extension"
strRegValueSearchDrive = "SearchDrive"
strRegValueINIFile = "INIFile"
strRegValueSection = "Section"

'Read Variable Values from Registry
Set objRegRead = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objRegRead.GetStringValue HKLM,strRegKeyPath,strRegValueExtension,strExtension
objRegRead.GetStringValue HKLM,strRegKeyPath,strRegValueSearchDrive,strSearchDrive
objRegRead.GetStringValue HKLM,strRegKeyPath,strRegValueINIFile,strINIFile
objRegRead.GetStringValue HKLM,strRegKeyPath,strRegValueSection,strSection

'Wscript.Echo strExtension,strSearchDrive,strINIFile,strSection
'Wscript.Quit

'Perform File Search Operation
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_DataFile Where Extension = '" & strExtension & "' AND Drive = '" & strSearchDrive & "'")

'Prepare Write to INI File Operation
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objINIFile = objFSO.OpenTextFile(strINIFile, ForAppending)

'Write Section to INI File
objINIFile.WriteLine(strSection)

'End Script if no files found
If colFiles.Count = 0 Then
objINIFile.WriteLine("1=")
Wscript.Quit
End If

'Write Keys and Values to INI File
intCounter = 1
intKey = intCounter

For Each objFile in colFiles
boolWriteToINI = True
Call Exception()
If boolWriteToINI = True Then
objINIFile.WriteLine(intKey & "=" & objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension)
intKey = intCounter + 1
intCounter = intKey
End If

Next

'Write an Empty Key to declare End of Section
objINIFile.WriteLine(intKey & "=")

'Function to Check for Excluded Paths
'Copy a IF Section to add additional Exception
Function Exception
If instr(objFile.Name, "c:\winxp\pchealth\") Then
boolWriteToINI = False
End If
If instr(objFile.Name, "c:\winxp\softwaredistribution\") Then
boolWriteToINI = False
End If
If instr(objFile.Name, "c:\winxp\system32\") Then
boolWriteToINI = False
End If
If instr(objFile.Name, "c:\recycler\") Then
boolWriteToINI = False
End If
If instr(objFile.Name, "c:\programme\microsoft office\") Then
boolWriteToINI = False
End If
If instr(objFile.Name, "c:\programme\sap\") Then
boolWriteToINI = False
End If
If instr(objFile.Name, "c:\programme\techsmith\") Then
boolWriteToINI = False
End If
If instr(objFile.Name, "c:\programme\vorlagen\fi-ts\") Then
boolWriteToINI = False
End If
If instr(objFile.Name, "normal.dot") Then
boolWriteToINI = False
End If
If instr(objFile.Name, "c:\temp\") Then
boolWriteToINI = False
End If
If instr(objFile.Name, "c:\programme\netinst\") Then
boolWriteToINI = False
End If
End Function

Write Windows Patches to INI

This script was developed as a part of an self-written update engine within enteo Netinstall. It's purpose is, to scan a specified directory for Windows Patches and write them to a INI File. Only Patches, using the "Update.exe", should be added to the list. Other Patches, like MSXML or .NET SP should NOT be mentioned, because they are using MSI and therefore the parameters are not compatible.


'Script created by: Zierer, Markus
'Script created on: 2010 09 09
'
'This script performs file search operations and writes the results into an INI File.
'
'Prepare Variables
strComputer = "."
strINIFile = "c:\winxp\Temp\updates.ini"
strSection = "[updates]"

'Perform File Search Operation
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_LogicalFile Where Drive = 'c:' AND Path = '\\Winxp\\Temp\\Updates\\' AND FileName Like '%WindowsXP%'")

'Prepare Write to INI File Operation
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objINIFile = objFSO.CreateTextFile(strINIFile)

'Write Section to INI File
objINIFile.WriteLine(strSection)

'End Script if no files found
If colFiles.Count = 0 Then
objINIFile.WriteLine("1=")
Wscript.Quit
End If

'Write Keys and Values to INI File
intCounter = 1
intKey = intCounter

For Each objFile in colFiles
objINIFile.WriteLine(intKey & "=" & objFile.Name)
intKey = intCounter + 1
intCounter = intKey
Next

'Write an Empty Key to declare End of Section
objINIFile.WriteLine(intKey & "=")