feedback on a script please

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I put a version of this script out once but I have rewritten it since. I'm
sure all of you have better things to do now before the holidays start, but
if you have a bit of time, please give me feedback on this script.

CODE
---------------------------
'Author Jeremy Schubert
'047diploma.vbs
'Logon Script to:
' - map diploma users Home Drive
' - set appropriate printer
' - create and open a word document pre-formatted with Alberta
Education's requirements
' - name the document with the exam ID#
'****************Begin Initial Tasks Section********************
On Error Resume Next
'*** Declarations ***
Dim Shell,FSO,Network,word, WSHNetwork, UserString
'*** Objects ***
Set Network = WScript.CreateObject("WScript.Network")
Set Shell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

'Disconnect ALL existing mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next

'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300

'Map H: to users home share
WSHNetwork.MapNetworkDrive "H:", "\\S047-S-0371-01\" & UserString & "$",True

'Map S: to \\s047-s0371-01\047diploma$
objNetwork.MapNetworkDrive "S:" , "\\S047-S0371-01\047diplomasusers$"
'*************End Initial Task Section**************************

'*************Begin Printer Setup Section***********************
Dim oNet
Set oNet = CreateObject("WScript.Network")
Dim strComputerName
strComputerName = oNet.ComputerName

If InStr(strComputerName, "047-C303") > 1 Then
oNet.AddWindowsPrinterConnection "\\S047-S0371-01\C303"
oNet.setdefaultprinter "file://server/printer"
End If

If InStr(strComputerName, "047-C309") > 1 Then
oNet.AddWindowsPrinterConnection "\\S047-S0371-01\C309"
oNet.setdefaultprinter "\\S047-S0371-01\C309"
End If

If InStr(strComputerName, "047-C310") > 1 Then
oNet.AddWindowsPrinterConnection "\\S047-S0371-01\C310"
oNet.setdefaultprinter "\\S047-S0371-01\C310"
End If

If InStr(strComputerName, "047-C312") > 1 Then
oNet.AddWindowsPrinterConnection "\\S047-S0371-01\C312"
oNet.setdefaultprinter "\\S047-S0371-01\C312"
End If

If InStr(strComputerName, "047-C110") > 1 Then
oNet.AddWindowsPrinterConnection "\\S047-S0371-01\C110"
oNet.setdefaultprinter "\\S047-S0371-01\C110"
End If

If InStr(strComputerName, "047-C111") > 1 Then
oNet.AddWindowsPrinterConnection "\\S047-S0371-01\C111"
oNet.setdefaultprinter "\\S047-S0371-01\C111"
End If

If InStr(strComputerName, "047-LIB") > 1 Then
oNet.AddWindowsPrinterConnection "\\S047-S0371-01\Lib"
oNet.setdefaultprinter "\\S047-S0371-01\Lib"
End If

If InStr(strComputerName, "047-LIB1") > 1 Then
oNet.AddWindowsPrinterConnection "\\S047-S0371-01\Lib1"
oNet.setdefaultprinter "\\S047-S0371-01\Lib1"
End If
'*******************End Printer Setup Section*****************************

'*******************Begin Document Creation Section***********************
'Instruct user to enter the 6 digit exam id number
user = inputbox("Please enter your 6 DIGIT EXAM NUMBER")

'Check to see if the users's document already exists. The document may
already exist if 'this is the second time a 'user is logging in if (for
example) the computer crashed and 'needed to be rebooted). In that case,
the user's 'existing document is opened.

If Object.File("H:" & "\" & user & ".doc")
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("H:\" & User & ".doc")

Else

'Copy template (diplomas.doc) from S: to H:
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "S:\diplomas.doc" , "H:\diplomas.doc", OverwriteExisting

'Rename template to User & doc
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "H:\diplomas.doc" , "H:\" & User & ".doc"

'Open the new document
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("H:\" & User & ".doc")
'******************End Document Creation Section**************************

'******************Terminate Script***************************************
wscript.quit


.



Relevant Pages

  • Re: vbs output to txt file
    ... Easiest is to code the VBScript to echo output to the console, ... Set objFSO = CreateObject ... should set that object to Nothing at the end of the script. ...
    (microsoft.public.scripting.wsh)
  • Re: Globally changing the Local Admin Password on Windows 2000
    ... Use a script: ... Set objFSO = CreateObject ... Dim objDomain ... Dim objComputer ...
    (microsoft.public.win2000.general)
  • wmi timeout on untactable workstations
    ... I've created the script below, which queries each workstation in a input text file then returns the logged on user to a second text file. ... Set objFSO = CreateObject ... Dim objWMI, colOS, strUsers, objItem ... Sub subCreateResultsFile ...
    (microsoft.public.scripting.vbscript)
  • Object required: [string: "C:Documents and Set"] error message
    ... and Set"] when running the following script: ... Set objFSO = CreateObject ... Dim WSHShell ... directory called Network Applications. ...
    (microsoft.public.windows.server.scripting)
  • Re: check for drive letter before copying files.
    ... exists before i allow a script to copy data ... Set objfso = CreateObject ... DriveStatus = CheckDrive ... I think you will see that line wrapping did occur here: ...
    (microsoft.public.scripting.vbscript)