Solved

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

Posted on 2006-07-18
8
280 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

867 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

22 Experts available now in Live!

Get 1:1 Help Now