In Association with Amazon.com

Management Scripts

Scripts are text files that can be used to automate a number of helpful system management and maintenance tasks. Script files contain a series of commands written in DOS command language or visual basic script. The commands are executed sequentially to perform functions similar to those a user would perform if they were sitting at the keyboard. Several of them are outlined below.

Clock Synch

DOS provides a method to keep system clocks synchronized with the TIME option of the NET command:

C:\> net time \\<timehost> /set /yes

The /SET option adjusts the Date/Time of the local system-clock and prompts for confirmation; the /YES option provides automatic confirmation.

The command can be added to the autoexec.bat file for automatic operation.

Other alternatives must be used for systems that do not process Autoexec.bat or Config.sys. One alternative is to create a shortcut that executes the Net Time command. Right click the desktop, select New > Shortcut, and enter the command C:\WINDOWS\net.exe time \\<time host> /set /yes. Enter a name and select an icon. Open the shortcut file properties, select the Program tab and select Run: minimized and Close on exit. Place the shortcut in the Programs > StartUp folder.

File Cleanup

::This *.BAT file deletes all subdirectories and files in
::Windows\temp directory and the Recycle bin.
::
::USE WITH CAUTION

@ECHO OFF

C:
CD windows
CD temp
DELTREE /Y *.* >NUL

::delete Recycle bin files.

C:
CD RECYCLED
ATTRIB -h *.*
ATTRIB +h desktop.ini
ECHO Y | DEL *.* > NUL

System Startup

This visual basic script performs basic system start-up tasks including system clock synchronization and network drive mapping. It runs under the Windows Script Host (WSH) which can be installed from the Add/Remove Programs > Windows Setup > Accessories menu in W98 or downloaded from Microsoft.

To execute on system startup copy these script statements into a *.vbs file and place a shortcut to it in the Windows Startup folder.

'Patron workstation initialization script
'v. 11/29/00 modified for external distribution

'This Visual Basic Script performs several administrative startup
'tasks. It runs under the Windows Scrip Host (WSH) which
'can be installed from the Windows Setup > Accessories menu.
'WSH can also be downloaded from the Microsoft website. 
'
'To execute on system startup copy these script statements into a
'*.vbs file and place a shortcut to it in the Windows
'Startup folder.

Option Explicit
On Error Resume Next

'Declare all variables
Dim strPatronShare
Dim oShell, oFS, oFolder, oFiles, xFile, xFolder
Dim oAllDrives, oNetwork
Dim strTimeHost
Dim bConnected, i

Set oShell = WScript.CreateObject("Wscript.Shell")
Set oNetwork = WScript.CreateObject("WScript.Network")
Set oFS= WScript.CreateObject("Scripting.FileSystemObject")

Set oFolder = oFS.GetFolder("c:\windows\temp\")
Set oFiles = oFolder.Files
Set oAllDrives = oNetwork.EnumNetworkDrives() 

'configuration variables

strTimeHost = "\\Fhcserver"
strPatronShare = "\\Fhcserver\Patron Docum\"

Function IsDirExist(sDirName)
on error resume next

Dim oFs, oFolder

Set oFs = Wscript.CreateObject("Scripting.FileSystemObject")
Set oFolder = oFs.GetFolder(sDirName)

if err.number <>0 then
IsDirExist = False
set oFolder = Nothing
set oFs = Nothing
exit function
end if
Set oFolder = Nothing
Set oFs = Nothing
IsDirExist = True
End Function

'** Synchornize patron workstation time to network Time Host ****

oShell.Run "net time " & strTimeHost & "/set /yes",0

'************ Map shared files to Z drive ******************

If IsDirExist(strPatronShare) then

bConnected = False 
For i = 0 To oAllDrives.Count - 1 Step 2 
If oAllDrives.Item(i) = "Z:" Then bConnected = True 
Next
If bConnected = False then oNetwork.MapNetworkDrive "Z:", strPatronShare

End IF

'****** Delete Windows temp directory files and folders **********

For Each xFile in oFiles 
oFS.DeleteFile "c:\windows\temp\"& xFile.Name
Next
For Each xFolder in oFolder.SubFolders 
oFS.DeleteFolder "c:\windows\temp\"& xFolder.Name
Next

'************ Release objects and end script ******************

Set oShell = Nothing
Set oFS= Nothing
Set oFolder = Nothing
Set oNetwork = Nothing
Set oAllDrives = Nothing
Wscript.Quit

Printer Selector

When multiple printers are available the printer connection section can be modified to test the printer connection and switch to a secondary printer if the primary is unavailable.

:: \\client13\hplj6p13 is the primary printer
:: \\Server\hplj6ps is the secondary printer

:: verify printer connection

net use lpt1: \\client13\hplj6p13 /yes
net use | find "HPLJ6p13" > NUL
if not errorlevel 1 goto :continue

net use lpt1: \\Server\hplj6ps /yes
net use | find "HPLJ6pS" > NUL
if errorlevel 1 goto :noprinter

echo.
echo We're sorry, the primary printer is unavailable. The secondary printer will be used for output
pause
goto :continue

:noprinter
echo.
echo We're sorry, no printers are currently available. Please notify the system administrator
pause

:continue
Pages