• 0

VB Scripting Question


Question

I am just trying to find a way to create a VB script that is designed to create a desktop shortcut(Under All Users) that points to a shared folder on one of our Microsoft servers, any assistance would be very helpful, Thank You in advance.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

You can use the WScript.Shell object to create this shortcut:

Dim workingDirectory : workingDirectory = "C:\Windows"		'The shortcuts working directory.
Dim application : application = "\\ServerPath\PathToApplication\Notepad.exe" 	'The path to your application.
Dim icon : icon = "%SystemRoot%\system32\shell32.dll,5" 	'The icon, in this example load it from shell32.dll

Dim shell : Set shell = CreateObject("WScript.Shell")
Dim desktop : desktop = shell.SpecialFolders("AllUsersDesktop")
Dim link : Set link = shell.CreateShortcut(desktop & "\NotepadShortcut.lnk")

link.Description = "Notepad"
link.HotKey = "CTRL+SHIFT+X"
link.IconLocation = icon
link.TargetPath = application
link.WindowStyle = 3
link.WorkingDirectory = workingDirectory
link.Save

Hope that helps.

There are a couple of things to note:

  1. You need to specifiy the target path using UNC path notations, unless you can guaruntee that each client machine has the network path mapped to the same drive letter.
  2. You use the SpecialFolders property to get the path of the All User's Desktop. There are other properties too (SpecialFolders Property @ MSDN).
  3. The icon you use can be a physical icon, or it can be a contained resource in a DLL. In the above example, we are pulling an icon out of shell32.dll
  4. The window style we use here (3) will cause the application to maximise in the foreground. (WindowStyle Property @ MSDN).

I adapted this from Guy's Scripting Ezine 119

Link to comment
Share on other sites

  • 0
You can use the WScript.Shell object to create this shortcut:

Dim workingDirectory : workingDirectory = "C:\Windows"		'The shortcuts working directory.
Dim application : application = "\\ServerPath\PathToApplication\Notepad.exe" 	'The path to your application.
Dim icon : icon = "%SystemRoot%\system32\shell32.dll,5" 	'The icon, in this example load it from shell32.dll

Dim shell : Set shell = CreateObject("WScript.Shell")
Dim desktop : desktop = shell.SpecialFolders("AllUsersDesktop")
Dim link : Set link = shell.CreateShortcut(desktop & "\NotepadShortcut.lnk")

link.Description = "Notepad"
link.HotKey = "CTRL+SHIFT+X"
link.IconLocation = icon
link.TargetPath = application
link.WindowStyle = 3
link.WorkingDirectory = workingDirectory
link.Save

Hope that helps.

There are a couple of things to note:

  1. You need to specifiy the target path using UNC path notations, unless you can guaruntee that each client machine has the network path mapped to the same drive letter.
  2. You use the SpecialFolders property to get the path of the All User's Desktop. There are other properties too (SpecialFolders Property @ MSDN).
  3. The icon you use can be a physical icon, or it can be a contained resource in a DLL. In the above example, we are pulling an icon out of shell32.dll
  4. The window style we use here (3) will cause the application to maximise in the foreground. (WindowStyle Property @ MSDN).

I adapted this from Guy's Scripting Ezine 119

Nice post a special thanks from myself........

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.