[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2006-07-18
8
Medium Priority
?
287 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day 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

649 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