I am writing a script to read through CSV files. The files contain 5 fields
that I then parse and use to create some shortcuts on the START menu. I want
to be able to have 1 script that reads through the files and adds the icons
accordingly. And so far it works great.
My problem is this:
Not all the CSV files will be readable by all users. I hope to create
several CSV files, and give only file rights to read for the users/groups
that will require those shortcuts.
For example:
I will have a menu-common.csv file that will have shortcuts for all users. I
then want one for HR, admin, receiving, shipping... to have their shortcuts.
My current script is set to read them both. But if I run it as a user that
does not have rights to read a CSV (like HR's CSV), the script just loops
and never ends.
Is there a way to set it so if it cannot read the CSV file, it will just go
down the list to the next CSV? Like "On Error Goto Next Section" command.
Here is my script.
--------------
' Script to create start menu folders and shortcuts based on a csv file
' by: Dan King
' 2/6/04
'
'
'
'
Option Explicit
On Error Resume Next
Dim ws, smenu, fs, fsr, scut, scFldr, uName, mFile, uFile
Set ws = WScript.CreateObject("WScript.Shell")
smenu = ws.SpecialFolders("StartMenu")
Set fs = CreateObject("Scripting.FileSystemObject")
uName = ws.ExpandEnvironmentStrings("%USERNAME%")
mFile = "menu-common.csv" 'Common menu file name and location
uFile = "menu-" & uName & ".csv" 'User menu file name and location
'Delete Existing Folders. Add to this as you add to the
fs.DeleteFolder(smenu & "\Data Trak") 'Delete folder from Start Menu
fs.DeleteFolder(smenu & "\Install") 'Delete folder from Start Menu
fs.DeleteFolder(smenu & "\Internet") 'Delete folder from Start Menu
fs.DeleteFolder(smenu & "\Accounting") 'Delete folder from Start Menu
Dim strOTF 'Object to contain contents of CSV file
Dim strARR 'Array name created from CSV file
Dim scFolder 'Array Field-0 : Start Menu folder name
Dim scName 'Array Field-1 : Shortcut name
Dim scTarget 'Array Field-2 : Target file of Shortcut
Dim scArguments 'Array Field-3 : Shortcut Arguments
Dim scIcon 'Array Field-4 : Icon for Shortcut
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objCTF
Set objCTF = objFSO.OpenTextFile(mFile,1)
Dim objUTF
Set objUTF = objFSO.OpenTextFile(uFile,1)
'*
'* Read Common File
'*
Do While Not objCTF.AtEndOfStream
strOTF = objCTF.ReadLine()
strARR = Split(strOTF,",")
scFolder = strARR(0)
scName = strARR(1)
scTarget = strARR(2)
scArguments = strARR(3)
scIcon = strARR(4)
Set scFldr = fs.CreateFolder(smenu & "\" & scFolder)
Set scut = ws.CreateShortCut(smenu & "\" & scFolder & "\" & scName &
".lnk")
scut.TargetPath = scTarget
scut.Arguments = scArguments
scut.IconLocation = scIcon
scut.Save
scFolder = ""
scName = ""
scTarget = ""
scArguments = ""
scIcon = ""
Loop
'*
'* Read Users File
'*
Do While Not objUTF.AtEndOfStream
strOTF = objUTF.ReadLine()
strARR = Split(strOTF,",")
scFolder = strARR(0)
scName = strARR(1)
scTarget = strARR(2)
scArguments = strARR(3)
scIcon = strARR(4)
Set scFldr = fs.CreateFolder(smenu & "\" & scFolder)
Set scut = ws.CreateShortCut(smenu & "\" & scFolder & "\" & scName &
".lnk")
scut.TargetPath = scTarget
scut.Arguments = scArguments
scut.IconLocation = scIcon
scut.Save
scFolder = ""
scName = ""
scTarget = ""
scArguments = ""
scIcon = ""
Loop
WScript.Echo "Done"