Creating network folder shortcut using script
-
Thursday, May 17, 2012 12:01 PM
I am trying to create a shortcut for a folder under a network share and it is not working as intended. The script creates the shortcut fine but I cannot open it using double click. The shortcut type is being set to "File" instead of "Share" or "File Folder". It works if I manually create the shortcut.
-----------------------
set WshShell = WScript.CreateObject("WScript.Shell")
strMyDocuments = WshShell.SpecialFolders("MyDocuments")
set Shortcut1 = WshShell.CreateShortcut(strMyDocuments + "\Department.lnk")
Shortcut1.TargetPath = "\\FileServer\Company\Department\"
Shortcut1.WindowStyle = 1
Shortcut1.IconLocation = "explorer.exe, 0"
Shortcut1.Description = "Department"
Shortcut1.Save
-----------------------The above script works if I set my target to \\FileServer\Company\ but if I go one level deeper it stops working. Company is the shared folder and Department is a folder under Company and it is not explicitly shared.
Thanks for reading.
All Replies
-
Thursday, May 17, 2012 12:42 PMJust tested your script and it works fine here, are you getting an error message? Also which OS are you running on and are you starting the script as an administrator?
Jaap Brasser
http://www.jaapbrasser.com -
Thursday, May 17, 2012 12:51 PMModerator
This worked for me (regardless of the depth of the path) ...
set WshShell = CreateObject("WScript.Shell")
strMyDocuments = WshShell.SpecialFolders("MyDocuments")
set Shortcut1 = WshShell.CreateShortcut(strMyDocuments & "\Department.lnk")
Shortcut1.TargetPath = "explorer.exe"
Shortcut1.Arguments = \\fileserver\Company\Department\
Shortcut1.WindowStyle = 1
Shortcut1.IconLocation = "explorer.exe, 0"
Shortcut1.Description = "Department"
Shortcut1.SaveTom Lavedas
-
Thursday, May 17, 2012 5:44 PM
Permissions?
¯\_(ツ)_/¯
-
Friday, May 18, 2012 3:44 AM
Thanks for the replies. It does seem to work after all. The computer I was trying to run this script is not joined to domain. The script is working fine on other computers.- Marked As Answer by Mark Polo Friday, May 18, 2012 3:44 AM

