Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript Persistent Drive Mappings

Status
Not open for further replies.

jwithi

Technical User
Jan 13, 2008
32
GB
I am in the process of replacing our current batch file login scripts with a VBScript.

The batch file used to map persitent drives using the /persistent:yes switch.

Is it possible to do the same in VBScript? I have read something about using 'boolpersistent' to do this.

Here is the script i am currently working on:-

ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path, sTime, sDate

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")

'==============================================================================================
'AUTOMATICALLY GRAB THE USERS DOMAIN NAME
'----------------------------------------------------------------------------------------------
DomainString = Wshnetwork.UserDomain

'==============================================================================================
'FIND WINDOWS DIRECTORY
'----------------------------------------------------------------------------------------------
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

'==============================================================================================
'GRABS THE USERNAME
'----------------------------------------------------------------------------------------------
UserString = WSHNetwork.UserName

'==============================================================================================
'BIND TO USER OBJECT TO GET USERNAME AND CHECK FOR GROUP MEMBERSHIP LATER
'----------------------------------------------------------------------------------------------
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'==============================================================================================
'GRABS COMPUTER NAME FOR USE IN ADD-ON CODE LATER
'----------------------------------------------------------------------------------------------
strComputer = WSHNetwork.ComputerName

'==============================================================================================
'WELCOME MESSAGE BOX
'----------------------------------------------------------------------------------------------
sTime = Hour (now)
sDate = Now
strUser = objnetwork.UserName

If sTime <=11 Then
GreetingTime = "Morning"
ElseIf sTime <=18 Then
GreetingTime = "Afternoon"
Else
GreetingTime = "Evening"
End If


WshShell.Popup "Good " & GreetingTime & " " & UserString & "!" ,3, "Welcome"

WshShell.Popup "You Are Now Being Logged Into The System, Please Be Patient...",4, "Log on"

'==============================================================================================
'DISCONNECTS ALL DEFINED MAPPED DRIVES (DO NOT INCLUDE U: DRIVE!!!!!!!!)
'----------------------------------------------------------------------------------------------
WSHNetwork.RemoveNetworkDrive "F:", True, True
WSHNetwork.RemoveNetworkDrive "G:", True, True
WSHNetwork.RemoveNetworkDrive "H:", True, True
WSHNetwork.RemoveNetworkDrive "I:", True, True
WSHNetwork.RemoveNetworkDrive "J:", True, True
WSHNetwork.RemoveNetworkDrive "K:", True, True
WSHNetwork.RemoveNetworkDrive "L:", True, True
WSHNetwork.RemoveNetworkDrive "M:", True, True
WSHNetwork.RemoveNetworkDrive "N:", True, True
WSHNetwork.RemoveNetworkDrive "O:", True, True
WSHNetwork.RemoveNetworkDrive "P:", True, True
WSHNetwork.RemoveNetworkDrive "Q:", True, True
WSHNetwork.RemoveNetworkDrive "R:", True, True
WSHNetwork.RemoveNetworkDrive "S:", True, True
WSHNetwork.RemoveNetworkDrive "T:", True, True
WSHNetwork.RemoveNetworkDrive "V:", True, True
WSHNetwork.RemoveNetworkDrive "W:", True, True
WSHNetwork.RemoveNetworkDrive "X:", True, True
WSHNetwork.RemoveNetworkDrive "Y:", True, True
WSHNetwork.RemoveNetworkDrive "Z:", True, True

'==============================================================================================
'GIVES THE PC TIME TO DISCONNECT CURRENTLY MAPPED DRIVES
'----------------------------------------------------------------------------------------------
wscript.sleep 300

'==============================================================================================
'MAP DEFAULT DRIVES FOR EVERYONE
'----------------------------------------------------------------------------------------------
WSHNetwork.MapNetworkDrive "K:", "\\SVRDATA\Data",True

'==============================================================================================
'CHECKS GROUP MEMBERSHIP AND MAPS APPROPRIATE DRIVES - GLOBAL GROUPS ONLY!!!!!
'GROUPS MUST BE ADDED IN UPPERCASE
'----------------------------------------------------------------------------------------------
For Each GroupObj In UserObj.Groups
On Error Resume Next
Select Case UCase(GroupObj.Name)

'==============================================================================================
'RDASH DRIVE MAPPINGS
'----------------------------------------------------------------------------------------------
Case "DRIVE MAP G"
WSHNetwork.MapNetworkDrive "G:", "\\Data1-2K\Data",True

Case "DRIVE MAP R"
WSHNetwork.MapNetworkDrive "R:", "\\Data2-2K\Data",True

Case "DRIVE MAP Q"
WSHNetwork.MapNetworkDrive "Q:", "\\Data1-2K\Qas",True

Case "DRIVE MAP L"
WSHNetwork.MapNetworkDrive "L:", "\\Data1-2K\Maracis$",True

Case "DRIVE MAP O"
WSHNetwork.MapNetworkDrive "O:","\\SVRSAFEGUARD\Safeguard",True

End Select

Next

'===============================================================================================
'CREATES ENTRY IN EVENT VIEWER FOR ERROR LOGGING PURPOSES
'-----------------------------------------------------------------------------------------------
Set oShell = CreateObject("Wscript.Shell")
Const EVENT_SUCCESS = 0
Const EVENT_FAIL = 1
if err.number <> 0 then
oShell.LogEvent EVENT_ERROR, "RDASHLogin Script Exited With An Error." & vbcrlf & "Error Number: " & err.number & vbcrlf & "Error: " & err.description
else
oShell.LogEvent EVENT_SUCCESS, "RDASHLogin Script Completed Successfully."
end if

'==============================================================================================
'Clean Up Memory We Used
'----------------------------------------------------------------------------------------------
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing

'==============================================================================================
'Quit the Script
'----------------------------------------------------------------------------------------------
wscript.quit
 
Thanks for that PHV,

A colleague of mine has said that they thought the ,True at the end of each drive mapping meant it was persistent?

What does the ,True actually mean?
 
Did you follow the link that PHV provided? It tells you there.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top