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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mapping a free drive letter

Status
Not open for further replies.

biglebowski

Technical User
Jan 29, 2004
3,117
GB
I have a script I want to use to automate the setup of an app. It will map a drive to my server and copy 2 files to the correct folders on the users local machine. I have only been able to set it ot take a specific drive letter (Z) is there a way it can check for a drive letter that is not being used and allocate that. Here is what I have so far

Dim strDriveLetter, strRemotePath, strUser, strPassword, strProfile
strDriveLetter = "z:"
strRemotePath = "\\mann-etfms\c$"
strUser = "MNsecurel0gix"
strPassword = "LOG587ix??"
strProfile = "false"
Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _
strProfile, strUser, strPassword

Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFolder "Z:\ETM server files\esc_client", "C:\Program Files\SecureLogix\ETM\",TRUE
fso.CopyFile "Z:\ETM server files\hosts", "C:\WINDOWS\system32\drivers\etc\",TRUE
objNetwork.RemoveNetworkDrive "Z:"

WScript.Echo "Server connection has been configured"
WScript.Quit

That rug really tied the room together, did it not?

 
unc is supported by fso. You can directly copy through the network.
[tt]
fso.CopyFolder "\\mann-etfms\c$\ETM server files\esc_client", "C:\Program Files\SecureLogix\ETM\",TRUE
fso.CopyFile "\\mann-etfms\c$\ETM server files\hosts", "C:\WINDOWS\system32\drivers\etc\",TRUE
[/tt]
 
tsuji has the best solution but to answer your question, here is a script I wrote a while back that does what you are asking.

Code:
'==========================================================================
'
' VBScript Source File 
'
' NAME: MapNextDrive.vbs
'
' AUTHOR: Mark D. MacLachlan , Wells Fargo Services Company
' DATE  : 10/21/2002
'
' COMMENT: Finds the next available drive letter then prompts for 
'          Server Name & Share Name, then maps the drive
'
'==========================================================================
'GetNextDrv.vbs
Dim MyNetDrv, MyServer, MyShare

'Find out next available drive letter
set objFS=CreateObject ("Scripting.FileSystemObject")
set colDrives=objFS.Drives
letter=Asc("c")
while objFS.DriveExists(Chr(letter)+":")
letter=letter+1
wend
Wscript.Echo "The next available drive letter is "+UCASE(Chr(letter))+":" 

'Get path to be mapped info
'************************************
'Uncomment next line and change Server name to remove server prompt
'MyServer = "server"
'Comment next line if bypassing server name prompt
MyServer=inputbox("Enter Server Name")
'Uncomment next line and change ShareName to remove share prompt
'MyShare = "shareName"
'Comment next line if bypassing share name prompt
MyShare=inputbox("Enter Share Name")
MyNetDrv = +UCASE(Chr(letter))+":"
Set oNet = Wscript.CreateObject("WScript.Network")
MsgBox "Drive " & MyNetDrv & " will be mapped To \\" & MyServer & "\" & MyShare, 1, "Map Drive"
'oNet.MapNetworkDrive Chr(34)&MyNetDrv&Chr(34)&", " &Chr(34)&"\\" & MyServer & "\" & MyShare&Chr(34)
oNet.MapNetworkDrive MyNetDrv, "\\"& MyServer & "\" & MyShare

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top