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

Using VBScript to map a: drive

Status
Not open for further replies.

jbyrne

MIS
Jun 21, 2002
11
0
0
GB
Can anyone give me an example of a tasty bit of script that will map the users a: drive

Assuming all PCs on the network have their A Drive shared as "Adrive" could you do something like setting a constant called "COMPUTERNAME" which picks up the PCs Name and then does something like "use z: \\COMPUTERNAME\Adrive"

This will then have the Z drive on that PC as a mapped drive to that PCs floppy disk drive.

I hope this makes sense to a VB expert out there.

Thanking you in advance....
 
assuming the drive is shared as adrive:

Set WshNetwork = WScript.CreateObject("WScript.Network")

ComputerName = WshNetwork.ComputerName
WshNetwork.MapNetworkDrive "Z:", "\\" & computername & "\adrive"

Hope this helps.

Dana Hallenbeck
 
Thank You, this is exactly what I was looking for
 
Is it possible to map a user's local a: drive in their terminal server session? I am not bothered if it is mapped as a:, it can be k: as long as it is that PCs floppy drive.

I can get my pc to share it's a drive and then, using vbscript, lookup the pc name and map it as the k: drive. However, when I go into Terminal Server 2000, the script doesn't work as WshNetwork.ComputerName looks at the Terminal Server's Computer Name. Is there any way I can get it to look at the client's computer name automatically instead?
 
If the session will always be start from the computer you want to map the drive to, there is a variable in the terminal session called CLIENTNAME that provides the computer name of the attaching computer. You could use something like the following script to get the variable.

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("Volatile")
compname = objEnv("CLIENTNAME")
wscript.echo compname

Hope this helps.

Dana Hallenbeck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top