[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-07-18
8
Medium Priority
?
288 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
  • 3
  • 3
6 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Six Sigma Control Plans

873 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