Solved

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

Posted on 2006-07-18
8
279 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
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 175 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
maxMirror challenge 10 88
VBA color chart bars 12 66
topping3 challenge 14 50
Please explain: Aspect Oriented Programming 2 54
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now