More VBS Scripts for System Administrators

Posted on March 30, 2007 at 8:56 am

Over the past few years as a Systems Admin, I’ve had to write a good number of scripts to manage desktops, security, and data backup. Here are a couple of short scripts that I’ve used in my environment!

How to create a shortcut on the desktop - Using this script, you can get a reference to the destop using the special folders function, so you don’t have to worry about the exact path for each user. Then just point to a URL or in my case, an internal web server.

set WshShell = WScript.CreateObject(”WScript.Shell”)

strDesktop = WshShell.SpecialFolders(”Desktop”)
set oShellLink = WshShell.CreateShortcut(strDesktop & “\Support Site.URL”)
oShellLink.TargetPath = “http://websvr/TechSupport”
oShellLink.Save

How to create a folder with items in the Start Menu

Set FSO = CreateObject(”Scripting.FileSystemObject”)

‘Get the start menu path
strStartMenu = WshShell.SpecialFolders(”StartMenu”)

‘First delete the old start menu folder - mine is called Apps
‘ This is the main folder when you click All Programs, then we’ll create
‘ subfolders by dept later on
NewFolder = strStartMenu & “\Programs\Apps”

If FSO.FolderExists( NewFolder ) then
FSO.DeleteFolder NewFolder
end if

‘Re-Create or create the folder

If NOT FSO.FolderExists( NewFolder ) then
FSO.CreateFolder NewFolder
End if

‘Now we create sub-folders for each department
strStartMenu = WshShell.SpecialFolders(”StartMenu”)
DeptFolder = strStartMenu & “\Programs\Apps\Dept1″

If NOT FSO.FolderExists( DeptFolder ) then
FSO.CreateFolder DeptFolder
End if

‘Work around the short file name problem
Dim ret
’subst a drive to make the mapping work
ret = WshShell.Run (”cmd /c subst i: c:\”, 0, TRUE)

‘Create the links here, assign shortcut keys, path on server, and working dir

set oShellLink = WshShell.CreateShortcut(DeptFolder & “\Search Lab Track.lnk”)
oShellLink.TargetPath = “i:\SearchLab\SearchLab.exe”
oShellLink.WindowStyle = 1
oShellLink.Hotkey = “CTRL+SHIFT+S”
oShellLink.IconLocation = “i:\SearchLab\SearchLab.exe, 0″
oShellLink.Description = “2 - Search Lab Track quickly”
oShellLink.WorkingDirectory = “i:\SearchLab”

‘ You can continue to add more links into the folder, by copying this code above

‘remove the subst
ret = WshShell.Run (”cmd /c subst i: /d”, 0, TRUE)

‘Make sure the start menu is alphatecially ordered
‘Deleting from the registry, can’t use regular method. Must delete by first deleting all subkeys and then deleting key

strComputer = “.” ‘ use “.” for local computer

Const HKCU = &H80000001 ‘HKEY_CURRENT_USER

Set objRegistry = GetObject _
(”winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\default:StdRegProv”)

KillKey HKCU, “Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu”

Sub KillKey(lHive, strKey)

Dim strElement, IsSubscriptOutOfRange
Dim sKeys()

objRegistry.EnumKey lHive, strKey, sKeys

On Error Resume Next
IsSubscriptOutOfRange = sKeys(0)

If Err = 0 Then
For Each strElement In sKeys
KillKey lHive, strKey & “\” & strElement
Next
End If

Err.Clear
objRegistry.DeleteKey lHive, strKey
End Sub

How to enable the Encrypt File shorcut in the context menu - This will allow a user to right click on a file and choose Encrypt, rather than having to open the properties of the file.

‘ Create an object to hold a reference to the Wscript.Shell object
Dim objShell
Set objShell = WScript.CreateObject(”WScript.Shell”)

‘ Create some registry keys and values using RegWrite with objShell
objshell.RegWrite “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\EncryptionContextMenu”, 1, “REG_DWORD”

How to open a Word document from your file server automatically - This little script does nothing but create a link to a Word Doc off the file server and then opens it. You can add some code to maybe open on the file only on Mondays, maybe like a once a week update to the company. Then all you have to do is update the Word file on the server.

Set FSO = CreateObject(”Scripting.FileSystemObject”)

set WshShell = WScript.CreateObject(”WScript.Shell”)
strDesktop = WshShell.SpecialFolders(”Desktop”)
set oShellLink = WshShell.CreateShortcut(strDesktop & “\Company News.lnk”)
oShellLink.TargetPath = “K:\Public\CompanyNews.doc”
oShellLink.Save

‘ Get a reference to the Word Application object.
Set appWord = Wscript.CreateObject(”Word.Application”)
‘ Display the application.
appWord.Visible = TRUE

‘ Open ITdocument.
link = strDesktop & “\Company News.lnk”
appWord.Documents.Open(link)

How to remove admin shares from a computer - This greatly increases security as long as you’re not using Admin shares on any of your desktops.

‘ Create an object to hold a reference to the Wscript.Shell object
Dim objShell
Set objShell = WScript.CreateObject(”WScript.Shell”)

‘ Create some registry keys and values using RegWrite with objShell
objshell.RegWrite “HKLM\SYSTEM\CurrentControlSet\Services\LanManServer\Parameters\AutoShareWks”, 0, “REG_DWORD”

I’ll post some more later on when I have time!

Related Posts:

Top things Windows System Administrators should and should not do!

VBS Script for System Administrators - How to backup Outlook email automatically in a login or logoff script

If you enjoyed this post, make sure you subscribe to my RSS feed!

» Filed Under IT Job Stuff

Related Posts

Please post your comments/suggestions!