Pause W2K3 SMB shares

Although, there is no clicky way to pause a Windows servers shares, there is a bit more unconvenient way to prevent users from accessing your servers shares:

  • Fire up a registry editor and navigate to HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares
  • Export all shares you want to reopen again later
  • Delete all shares you want to pause and close the registry editor
  • Restart the service called “Server

et voila, you’re done.

Recursively delete outdated files with VBScript

Recently, I came across the situation, where I had to delete outdated SQL backup files from our MS SQL servers Backup directory. To tidy up the backup folder, I wrote a small VB script which handles this for me:


' DeleteOutdated
'
' Parameters
' MaxFileAge: Maximum file age in days (modification date)
' Path: Folder which contains the files
'
' VBScript ref. http://msdn.microsoft.com/en-us/library/t0aew7h6(VS.85).aspx
' FSO ref. http://msdn.microsoft.com/en-us/library/z9ty6h50(VS.85).aspx

Dim objFso
Set objFso = CreateObject("Scripting.FileSystemObject")

Sub DeleteOutdated(Path, MaxFileAge)
	Set objDir = objFso.GetFolder(Path)
	For Each objFile in objDir.Files
		If objFile.DateLastModified < (Date() - MaxFileAge) Then
			AskDelete = MsgBox("Delete "&objFile.Path&"?",3,"Delete file")
			If AskDelete = 6 Then
				objFile.Delete
			End If
			If AskDelete = 2 Then
				WScript.Quit
			End If
		End If
	Next

	For Each objSubfolder in objDir.Subfolders
		Call DeleteOutdated(objSubfolder, MaxFileAge)
	Next
End Sub

Call DeleteOutdated("c:\outdatedstuff", 1)

Hint
In this state, the script asks to delete everytime, if it finds a file wich is older than specified. Of course, you might want to remove that in productive usage, when script execution is scheduled.

Extended
Here I attached a version, which writes a logfile and processes empty subfolders (updated on 26.08.2009):
deleteoutdated-wlog

Resizing a VMware vmdk image

If you have to enlarge a VMware server vmdk- file, do the following if your VMware server runs on windows:

  1. Make sure, the VM is not running
  2. Remove or commit any snapshots of the VM
  3. Open a command prompt and cd to this path:
    C:\Program Files\VMWare\VMWare Server
  4. Run this command:
    vmware- vdiskmanager -x XGB “PATHTOIMAGE.vmdk”
    (replace XGB with the new size e.g. 30GB and PATHTOIMAGE with the path to the vmdk- file)
  5. Power up your VM and adjust the partition sizes
    (for example with the open source tool GParted)

Uninstalling a managed Symantec AntiVirus CE client w.o. uninstall password

While dealing with managed antivirus solutions, you might want to remove outdated antivirus clients from your workstations. In the case of Symantec’s AntiVirus CE, you will be asked for an uninstall password. If you don’t know the password for any reason, do the following:
Open up regedit (Start -> Run -> regedit) and go to

HKEY_LOCAL_MACHINE\SOFTWARE\Intel\LANDesk\VirusProtect6\CurrentVersion\AdministratorOnly\Security

and set the value of UseVPUninstallPassword to “0

Now the uninstall- routine runs without asking for a password.

Mapping of network drives via batchfile

If you work in a ActiveDirectory based environment and all your clients are connected to the domain, you might not have to deal with manually map home drives and other resources.

However, if some of your clients are not connected to the domain, but need access to domain resources, you probably noticed that it can be pretty annoying having service calls because of forgotten network paths and locked accounts.

To encounter that problem, I wrote a quick and dirty script, which gives the user a basic dialogue driven netdrive-mapper, so your service desk gets rid of the most basic calls.


@ECHO OFF

ECHO Removing all available mappings...
PAUSE
NET USE * /D

:USER
ECHO Attempting to connect to SERVER and map your homedrive...
PAUSE
SET /P USER=Please enter your username (username@domain.local):
NET USE U: \\server.domain.local\%USER:~0,-13%$ /USER:%USER% /PERSISTENT:NO

ECHO Attempting to connect to SERVER and map your Groupdrives...
PAUSE

:GROUP1
SET /P GROUP1=Please enter your main Group:
NET USE V: \\server.domain.local\%GROUP1% /PERSISTENT:NO
SET /P CONTINUE=Add another Groupdrive? (y or n)

IF /I '%CONTINUE%'=='y' GOTO GROUP2
IF /I '%CONTINUE%'=='n' GOTO PUB
ECHO "%CONTINUE%" is not valid. Going to map public drives GOTO PUB

:GROUP2
SET /P GROUP2=Please enter your second Group:
NET USE W: \\server.domain.local\%GROUP2% /PERSISTENT:NO
GOTO PUB

:PUB
ECHO Attempting to connect to SERVER and map public drives...
NET USE p: \\server.domain.local\public /USER:%USER% /PERSISTENT:NO
GOTO PRINTERS

:PRINTERS
ECHO Attempting to connect to SERVER and map printers...
PAUSE
START \\server.domain.local\printer1
START \\server.domain.local\printer2

Recursively delete files by extension

Recently, I got the task to remove all MP3- files from some shared folders (SMB shares). To do so, I wrote a tiny batch- script wich processes the DIR command’s output and examines it to match the MP3 extension.

Usage:
The script processes all folders and subfolders in its working directory (e.g. if you run it in c:\scripts it processes all folders and subfolders from there on – c:\scripts\*)


@ECHO OFF
FOR /F "tokens=*" %%G IN ('DIR /B /S *.mp3') DO DEL /F "%%G"