1,105,644 Community Members

Desktop Shortcut to All Users Desktop

Member Avatar
sachintha81
Junior Poster in Training
97 posts since Apr 2008
Reputation Points: 17 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

I am required to create a Desktop shortcut to a specific folder from within my C# program. I have two requirements.
1) On the Desktop of Current User
2) On the All Users Desktop

Following is the code I used:

WshShellClass WshShell = new WshShellClass();
IWshShortcut MyDesktopShortcut;
MyDesktopShortcut = (IWshShortcut)WshShell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\XYZ.lnk");
MyDesktopShortcut.TargetPath = "C:\\ABC\\XYZ";
MyDesktopShortcut.Description = "Shortcut to " + MyDesktopShortcut.TargetPath;
MyDesktopShortcut.Save();

In order to do that I need to obtain the path to Desktop folder, and in the first case I can easily do that using;

Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

However, I am facing a problem when trying to get the path of the All Users Desktop folder. My program should be able to run on a variety of Windows OS ranging from Windows Server 2003 to Windows 7. As far as I know, the location of All Users Desktop in Vista or above is as follows:

"C:\\Users\\Public\\Desktop\\"

And the location in XP or below is as follows:

"C:\\Documents and Settings\\All Users\\Desktop\\"

Of course I can hard code my program, but I'm looking for a way to acquire the path using some C# method or something similar so as to eliminate obvious possible errors of those paths being changed by users. What can I do?

Member Avatar
finito
Nearly a Posting Virtuoso
1,264 posts since May 2010
Reputation Points: 46 [?]
Q&As Helped to Solve: 140 [?]
Skill Endorsements: 0 [?]
 
0
 
Member Avatar
sachintha81
Junior Poster in Training
97 posts since Apr 2008
Reputation Points: 17 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Thank you finito. However, my problem is not actually how to create a Desktop shortcut - that I can do. What I need is a way to retriew the path of the All Users Desktop programmatically without having to hard code it. I also need my program to be able to run on a variety of Windows OS from Windows Server 2003 to Windows 7.

Member Avatar
finito
Nearly a Posting Virtuoso
1,264 posts since May 2010
Reputation Points: 46 [?]
Q&As Helped to Solve: 140 [?]
Skill Endorsements: 0 [?]
 
0
 
Member Avatar
sachintha81
Junior Poster in Training
97 posts since Apr 2008
Reputation Points: 17 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

http://www.daniweb.com/forums/thread281849.html

This should be helpful.

I'm sorry mate, but what am I to understand from it? Isn't that a thread about recursion? Did you give me a wrong link by mistake?

Member Avatar
finito
Nearly a Posting Virtuoso
1,264 posts since May 2010
Reputation Points: 46 [?]
Q&As Helped to Solve: 140 [?]
Skill Endorsements: 0 [?]
 
0
 

Read on,

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: