bbanis2k
asked on
VB Script Syntax error on Sub Routine
I have no idea why I am getting a syntax error on the sub routine "sub getcurrentdrives()"
Any help would be great!
Thank you,
B.
Any help would be great!
Thank you,
B.
'---------------------------------------------------------------------------------------------------------------
'This script checks for the exsistence of network drives and writes them to
'c:\documents and settings\%userpfrofile%\OldDriveslistDrives.txt
'This happens only the first time that it runs.
'The script then deletes all network drives and maps the new drives
'The new drives are mapped one of two ways:
'1. Under the section labled ALL USERS these drives map for everyone
'2. Under the section labled BY GROUP these drives map only for groups
'---------------------------------------------------------------------------------------------------------------
On Error Resume Next
Set WshS = WScript.CreateObject("WScript.Shell")
strNoPrinterDeleteFileDirectory = "C:"
strNoPrinterDeleteFile = "\TerminalServer.txt"
strDirectory = WshS.ExpandEnvironmentStrings("%UserProfile%") & "\oldDrivesPrinters1"
'wscript.echo strDirectory
strOldDrivesFile = "\listDrives.txt"
strOldPrintersFile = "\listOldPrinters1.txt"
strText = ""
Set objSysInfo = CreateObject("ADSystemInfo") 'Get user distinguished name
Set objNetwork = CreateObject("Wscript.Network")
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath) 'Bind to the user account in Active Directory
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists (strNoPrinterDeleteFileDirectory & strNoPrinterDeleteFile) Then
else
ListAndRemoveCurrentPrinters
mapPrinters
end if
'--------------------------Remove all mapped drives--------------------------------------------------------------
Set CheckDrive = objNetwork.EnumNetworkDrives()
strDriveLetter = UCase("z:" ) ' Force UPPER case
Dim intdrive, bforce, bUpdateProfile
bforce = true
bUpdateProfile = true
For intDrive = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(intDrive) <> strDriveLetter Then
objNetwork.RemoveNetworkDrive CheckDrive.Item(intDrive), bforce, bUpdateProfile
wscript.sleep 300
End if
'-----------------------------------------------------------------------------------------------------------------
'---------------------------------------ALL USERS-----------------------------------------------------------------
'--------------------------Add drives in this section that will map for all users---------------------------------
objNetwork.MapNetworkDrive "p:", "\\chdifs01\public$"
objNetwork.MapNetworkDrive "g:", "\\ohserver1\etime software"
'-----------------------------------------------------------------------------------------------------------------
'--------------------------Add all Printers in this section ------------------------------------------------------
'Define network printers to be connected
'Sub mapPrinters()
' Dim colNewPrinters(1)
' colNewPrinters (0) = "\\chdifs01\registration"
'
' For Each strNewPrinter In colNewPrinters
' objNetwork.AddWindowsPrinterConnection strNewPrinter
' Next
'end sub
'-----------------------------------------------------------------------------------------------------------------
For Each strGroup in objUser.MemberOf 'Walk through the groups that user is a member of
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath) 'Bind to the group in Active Directory
strGroupName = objGroup.CN 'Get the group name
strGroupName = lcase(strGroupName) 'Set group name to all lowercase
'-------------------------------------BY GROUP--------------------------------------------------------------------
'-----------------------------------------------------------------------------------------------------------------
Select Case strGroupName
Case "hr" 'If in this group map the drive on next line
objNetwork.MapNetworkDrive "X:", "\\chdifs01\hr"
Case "accounting" 'If in this group map the drive on next line
objNetwork.MapNetworkDrive "O:", "\\chdifs01\accounting"
Case "mis" 'If in this group map the drive on next line
objNetwork.MapNetworkDrive "m:", "\\chdifs01\mis"
Case "administration"
objNetwork.MapNetworkDrive "Z:", "\\chdifs01\admin assistants"
End Select
'-----------------------------------------------------------------------------------------------------------------
'-----------------------------------------------------------------------------------------------------------------
''Add a printer by adding the following two lines before "End select"
'' Case "group name" 'If in this group map the printer on next line
'' objNetwork.MapNetworkDrive "drive letter:", "\\server\printer"
'
''When you add a group name it must be in lower case
'-----------------------------------------------------------------------------------------------------------------
' Select Case strGroupName
' Case "txen dispatch printer mapping" 'If in this group map the drive on next line
' objNetwork.AddWindowsPrinterConnection "\\chdifs01\TXEN-CLASER-PRT001"
' objNetwork.AddWindowsPrinterConnection "\\chdifs01\TXEN-LASER-PRT003"
'
' Case "txen ar printer mapping" 'These are the folks in Ms. Pauline's area
' objNetwork.AddWindowsPrinterConnection "\\chdifs01\TXEN-LASER-PRT001"
' objNetwork.AddWindowsPrinterConnection "\\chdifs01\TXEN-LASER-PRT002"
'
'
' Case "txen corporate accounting printer mapping" 'If in this group map the drive on next line
' objNetwork.AddWindowsPrinterConnection "\\chdifs01\ACCT-MARI"
' objNetwork.AddWindowsPrinterConnection "\\chdifs01\CheckPrinter-Robin"
'
' Case "txen hr printer mapping" 'If in this group map the drive on next line
' objNetwork.AddWindowsPrinterConnection "\\chdifs01\TXEN-CLASER-PRT004"
' objNetwork.AddWindowsPrinterConnection "\\chdifs01\TXEN-CKPRINTER02"
'
' Case "txen john crisp printer mapping" 'If in this group map the drive on next line
' objNetwork.AddWindowsPrinterConnection "\\chdifs01\TXEN-CLASER-PRT005"
' objNetwork.AddWindowsPrinterConnection "\\chdifs01\TXEN-CLASER-PRT006"
'
' Case "txen ap printer mapping" 'These are the folks in Ms. Pauline's area
' objNetwork.AddWindowsPrinterConnection "\chdifs01\TXEN-CKPRINTER03"
'
' Case "txen collections printer mapping"
' objNetwork.AddWindowsPrinterConnection "\\chdifs01\TXEN-Laser-PRT006"
' End Select
'-----------------------------------------------------------------------------------------------------------------
Next
sub getCurrentDrives()
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strDirectory & strOldDrivesFile) Then
else
createFolderAndFileIfNotExist strOldDrivesFile
Set objDrive = objNetwork.EnumNetworkDrives
' Extra section to troubleshoot
If objDrive.Count = 0 Then
'WScript.Echo " No Drives Mapped "
End If
' Here is the where the script reads the array
For intDrive = 0 To (objDrive.Count -1) Step 2
intNetLetter = IntNetLetter +1
appendToFile objDrive.Item(intDrive) & " " & objDrive.Item(intDrive +1), strOldDrivesFile
Next
end if
end sub
sub ListAndRemoveCurrentPrinters()
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strDirectory & strOldPrintersFile) Then
else
createFolderAndFileIfNotExist strOldPrintersFile
Set objOldPrinters = objNetwork.EnumPrinterConnections
For nPrinter = 0 To objOldPrinters.Count - 1 Step 2
strPrinter = objOldPrinters.Item ( nPrinter + 1 )
If Left ( strPrinter, 2) = "\\" Then
appendToFile strPrinter, strOldPrintersFile
objNetwork.RemovePrinterConnection strPrinter, True, True 'removes printer
end if
Next
end if
end sub
sub createFolderAndFileIfNotExist(strFile)
exsist = 0
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
exsist = 1
exit sub
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
End If
If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
End If
set objFile = nothing
set objFolder = Nothing
exsist = 1
end sub
sub appendToFile(strText, strFile)
Set objFSO = CreateObject("Scripting.FileSystemObject")
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8
Set objTextFile = objFSO.OpenTextFile (strDirectory & strFile, ForAppending, True)
' Key Section to write the strText to the file.
' Writes strText every time you run this VBScript
objTextFile.WriteLine(strText)
objTextFile.Close
end Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER