?
Solved

How to add a mapped drive to desktop using VB script.

Posted on 2006-07-18
8
Medium Priority
?
286 Views
Last Modified: 2010-04-17
I am using the VB script below to map a network drive at login, but I would also like to place this same drive onto the users terminal desktop at login. Any ideas would be greatly appreciated.


Option Explicit
Dim objNetwork
Dim strDriveLetter, strRemotePath

strDriveLetter = "k:"
strRemotePath = "\\2kserver\fhhs"

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath

WScript.Quit
0
Comment
Question by:jlycos1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
8 Comments
 
LVL 15

Expert Comment

by:bpmurray
ID: 17133074
Extend your script with this:

set WshShell = WScript.CreateObject("WScript.Shell")
myDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(myDesktop & "\DiskDrive.lnk")
oShellLink.TargetPath = strDriveLetter
oShellLink.Description = "Shortcut to " + strDriveLetter
oShellLink.Save


You can extend this with various tags: oShellLink.WindowStyle, oShellLink.Hotkey, oShellLink.IconLocation, oShellLink.WorkingDirectory
0
 
LVL 1

Author Comment

by:jlycos1
ID: 17133484
Option Explicit
Dim objNetwork, WshShell
Dim strDriveLetter, strRemotePath

strDriveLetter = "k:"
strRemotePath = "\\2kserver\fhhs"

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath

set WshShell = WScript.CreateObject("WScript.Shell")
myDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(myDesktop & "\DiskDrive.lnk")
oShellLink.TargetPath = strDriveLetter
oShellLink.Description = "Shortcut to " + strDriveLetter
oShellLink.Save

WScript.Quit

It keeps erroring on myDesktop = WshShell.SpecialFolders("Desktop")


I am not a VB guru just trying some new things.....


Thanks in advance.....
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 17133546
What does "erroring" mean?
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 1

Author Comment

by:jlycos1
ID: 17133621
Actually i just figured it out...

How can put (if the mapped drive already exists and is mapped to desktop then quit)?


0
 
LVL 1

Author Comment

by:jlycos1
ID: 17133631
Option Explicit
Dim objNetwork, WshShell, oShellLink
Dim strDriveLetter, strRemotePath

strDriveLetter = "k:"
strRemotePath = "\\2kserver\fhhs"

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath

set WshShell = WScript.CreateObject("WScript.Shell")
myDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(myDesktop & "\DiskDrive.lnk")
oShellLink.TargetPath = strDriveLetter
oShellLink.Description = "Shortcut to " + strDriveLetter
oShellLink.Save

WScript.Quit
0
 
LVL 15

Accepted Solution

by:
bpmurray earned 700 total points
ID: 17133782
Try checking it using the filesystem ....



set WshShell = WScript.CreateObject("WScript.Shell")
myDesktop = WshShell.SpecialFolders("Desktop")
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.FileExists(myDesktop & "\DiskDrive.lnk") then
      WScript.Echo("It already exists")
      WScript.quit
end if
set oShellLink = WshShell.CreateShortcut(myDesktop & "\DiskDrive.lnk")
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Simple Linear Regression
Six Sigma Control Plans
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question