PDA

View Full Version : Shortcut to folder


Philo
04-05-2005, 03:48 AM
Hi All,

Ive got a simple problem while trying to create a shortcut to open a folder on the local hard drive.

I use the following code

Shell.CreateShortcut(Shell.GetFolder(SHF_DESKTOP), "Routefinder Networks", first_hdd.."\\RouteFinder Networks\\", "", "", _WindowsFolder .. "\\explorer.exe", 1, SW_SHOWNORMAL);

The shortcut gets created but when clicked on a dialog box appears and says windows cannot open files of this type please select an application to open the file. If I manually pick explorer.exe it opens up great.

I have also discovered if I right click on the shortcut and go to properties and add an extra \ to the path it is automatically removed by windows but the shortcut then starts working correctly.

Any ideas? Am I doing something stupid?

csd214
04-05-2005, 05:42 AM
What I experienced:

Your code worked well! (WinXP Pro SP2).

You don't need the trailing (double) slash for the folder. "\\RouteFinder Networks" works fine (if the folder exists). The variable 'first_hdd' has to be assigned a valid value, of course.

Sorry, I can't tell you WHY you have problems!

Philo
04-05-2005, 08:44 AM
hmm its strange,

I got it working by changing the code to:

Shell.CreateShortcut(Shell.GetFolder(SHF_DESKTOP), "Routefinder Networks", first_hdd.."RouteFinder Networks", "", first_hdd.."RouteFinder Networks", _WindowsFolder .. "\\explorer.exe", 1, SW_SHOWNORMAL);

I didnt realise I had to set the working folder option as well to get it to work.

csd214
04-05-2005, 09:36 AM
Now your code does not work on my side! You have removed both the leading slash and the trailing slash from target folder. Then I had to add a trailing slash to first_hdd.

At the first test I had:
first_hdd = "D:"
and Target in Shell.CreateShortcut = first_hdd.. "\\RouteFinder Networks"

Solution #2:
first_hdd = "D:\\"
Target in Shell.CreateShortcut = first_hdd.. "RouteFinder Networks"

Both examples build D:\ RouteFinder Networks at runtime and work with and without a working folder. It's hard to understand that the working folder should have any significance; but it does not hurt.

Glad you found a working solution. :)