Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: map a network drive & create shortcut vbscript

334 views
Skip to first unread message

Ulf Dornheck Busscher

unread,
Nov 10, 2004, 4:15:03 PM11/10/04
to
Hi Samantha,

Try

oShellLink.TargetPath = "\\servername\sharename$"

instead of

> oShellLink.TargetPath = "\\servername\sharename$.lnk"

Regards

Ulf

samantha wrote:
> set WshShell = WScript.CreateObject("Wscript.Shell")
> strDesktop = WshShell.SpecialFolders("Desktop")
> set oShellLink = WshShell.CreateShortcut(strDesktop &
> "\\servername.lnk")
> oShellLink.TargetPath = "\\servername\sharename$.lnk"
> oShellLink.Save


Tom Lavedas

unread,
Nov 10, 2004, 5:03:03 PM11/10/04
to
Actually, since samantha went to the trouble of mapping the share to the H:
drive, it might be better to set the TargetPath to that location, e.g. ...

oShellLink.TargetPath = "H:\"

Tom Lavedas
============

Foss

unread,
Nov 11, 2004, 6:16:01 AM11/11/04
to
Hi there Samantha,

I think the problem is with this line:


set oShellLink = WshShell.CreateShortcut(strDesktop & "\\servername.lnk")

I think it should be:


set oShellLink = WshShell.CreateShortcut(strDesktop & "\servername.lnk")

Note just one backslash before the shortcut name.

Hope this helps!

Cheers,
Pete

"samantha" wrote:

> I am very new to vbscripting. i have am attempting to map to a
> network share and then create a desktop shortcut to that share. i am
> having trouble placing the shortcut and hope someone can help.
>
> What I have below will map the drive but not create a shortcut:
>
>
> Set objNetwork = WScript.CreateObject("Wscript.Network")
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> If Not oFSO.DriveExists("h:") Then
> objNetwork.MapNetworkDrive "h:", "\\shervername\sharename$"
> End If

stacey holland

unread,
Nov 11, 2004, 1:30:02 PM11/11/04
to

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

stacey holland

unread,
Nov 11, 2004, 1:40:04 PM11/11/04
to

Thank you to everyone for your comments. Unfortuantely the script does
not work. The error message is on the last line which attempts to save
the shortcut to the desktop.
If anyone has other ideas i'd be grateful.
----

set WshShell = WScript.CreateObject("Wscript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop &

"\servername\sharename$.lnk")
oShellLink.TargetPath = "l:\"
oShellLink.Save

Foss

unread,
Nov 12, 2004, 4:29:03 AM11/12/04
to
Hi there Stacey,

Sorry, no more ideas. Here's one of mine that makes some shortcuts to shares
etc though, hope it's of use!

on error resume next

Set WshNetwork = WScript.CreateObject("WScript.Network")
set oFileSys= CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
luser = WshNetwork.UserName

ServName = "os_server"
PFtitle = "My Personal Folder"
PFpath = "\\" + ServName + "\PF-" + lUser + "\"
PFdesc = "Open my (" + lUser + ") personal folder on the server (" +
ServName + ")."
SMfolder = "Programs\CDD Applications and Links"
GraphPath = "\\" + ServName + "\GU-Graphics\"
NMpath = "C:\Program Files\NetMeeting\conf.exe"

'------------------------------------------
' Creating shortcuts in My Documents
sfolder = oShell.SpecialFolders("MyDocuments")
If oFileSys.FolderExists(PFpath) Then
Set oSLink = oShell.CreateShortcut(sfolder & "\" + PFtitle + ".lnk")
oSLink.TargetPath = PFpath
oSLink.Description = PFdesc
oSLink.Save
End If
'------------------------------------------
' Creating shortcuts My Pictures (must follow My Documents links)
If oFileSys.FolderExists(GraphPath) Then
Set oSLink = oShell.CreateShortcut(sfolder & "\My Pictures\CDD shared
graphics.lnk")
oSLink.TargetPath = GraphPath
oSLink.Description = "Open the shared graphics folder on the server (" +
ServName + ")."
oSLink.IconLocation = "%SystemRoot%\System32\mydocs.dll,1"
oSLink.Save
End If
'------------------------------------------
' Creating shortcuts on the D: drive
If oFileSys.FolderExists(GraphPath) Then
Set oSLink = oShell.CreateShortcut("D:\Data\Pictures\CDD shared
graphics.lnk")
oSLink.TargetPath = GraphPath
oSLink.Description = "Open the shared graphics folder on the server (" +
ServName + ")."
oSLink.IconLocation = "%SystemRoot%\System32\mydocs.dll,1"
oSLink.Save
End If
'------------------------------------------
' Creating shortcuts on the Desktop
sfolder = oShell.SpecialFolders("Desktop")
If oFileSys.FolderExists(PFpath) Then
Set oSLink = oShell.CreateShortcut(sfolder & "\" + PFtitle + ".lnk")
oSLink.TargetPath = PFpath
oSLink.Description = PFdesc
oSLink.Save
End If

If oFileSys.FileExists(NMpath) Then
Set oSLink = oShell.CreateShortcut(sfolder & "\NetMeeting.lnk")
oSLink.TargetPath = NMpath
oSLink.Description = "Use NetMeeting to chat to other users on the network.
You can also use it to view / control remote desktops and share files."
oSLink.Save
End If
'------------------------------------------
' Creating shortcuts on the Send To menu
sfolder = oShell.SpecialFolders("SendTo")
If oFileSys.FolderExists(PFpath) Then
Set oSLink = oShell.CreateShortcut(sfolder & "\" + PFtitle + ".lnk")
oSLink.TargetPath = PFpath
oSLink.Description = PFdesc
oSLink.Save
End If
'------------------------------------------
' Creating links in the Favourites list
sfolder = oShell.SpecialFolders("Favorites")
Set oSLink = oShell.CreateShortcut(sfolder & "\CDD Intranet Home Page.url")
oSLink.TargetPath = "http://web1/forcenet/?CatID2=970"
oSLink.Save
'------------------------------------------
' Creating links in the Start Menu
sfolder = oShell.SpecialFolders("StartMenu")

If oFileSys.FileExists(NMpath) Then
Set oSLink = oShell.CreateShortcut(sfolder & "\Programs\NetMeeting.lnk")
oSLink.TargetPath = NMpath
oSLink.Description = "Use NetMeeting to chat to other users on the network.
You can also use it to view / control remote desktops and share files."
oSLink.Save
End If

sfolder = sfolder & "\" & SMfolder
oFileSys.DeleteFolder(sfolder)
oFileSys.CreateFolder(sfolder)

Set oSLink = oShell.CreateShortcut(sfolder & "\CDD Intranet Home Page.url")
oSLink.TargetPath = "http://web1/forcenet/?CatID2=970"
oSLink.Save

If oFileSys.FolderExists(PFpath) Then
Set oSLink = oShell.CreateShortcut(sfolder & "\" + PFtitle + ".lnk")
oSLink.TargetPath = PFpath
oSLink.Description = PFdesc
oSLink.Save
End If

If oFileSys.FolderExists(GraphPath) Then
Set oSLink = oShell.CreateShortcut(sfolder & "\CDD shared graphics.lnk")
oSLink.TargetPath = GraphPath
oSLink.Description = "Open the shared graphics folder on the server (" +
ServName + ")."
oSLink.IconLocation = "%SystemRoot%\System32\mydocs.dll,1"
oSLink.Save
End If
'------------------------------------------
'Mapping H: drive to personal folder
If oFileSys.FolderExists(PFpath) Then
WshNetwork.RemoveNetworkDrive "H:"
WshNetwork.MapNetworkDrive "H:", PFpath, true
End If

Tom Lavedas

unread,
Nov 12, 2004, 9:46:05 AM11/12/04
to
If I'm reading this correctly, you're trying to use an unacceptable name for
the shortcut file. You seem to be trying to put it in a subfolder on the
desktop (\servername\) that probably doesn't exist. At least that's what the
backslashes are telling the OS to do - and it can't. Either change the name
to something without slashes or use the FileSystemObject to create the
subfolder first.

Tom Lavedas
============

0 new messages