-
May 6th, 2010, 11:33 PM
#1
Desktop Shortcut to All Users Desktop
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?
-
May 7th, 2010, 10:56 PM
#2
Re: Desktop Shortcut to All Users Desktop
I am not sure but I am not aware of any method where you could change the location of the desktop for a given user and not the others. If this is the case then once you find the desktop it should be simple to determine where the all users desktop is.
You are aware however that if you place a shortcut on the desktop of the current user and that same shortcut on the desktop of all users then the current user will have 2 of them and may very likely delete one of them which also may very likely be the one for all users 50/50 chance.
Always use [code][/code] tags when posting code.
-
May 7th, 2010, 11:48 PM
#3
Re: Desktop Shortcut to All Users Desktop
Originally Posted by DataMiser
I am not sure but I am not aware of any method where you could change the location of the desktop for a given user and not the others. If this is the case then once you find the desktop it should be simple to determine where the all users desktop is.
What I meant was, there is the likely scenario of user having had his driver letters changed at installation time. So if I were to hardcode the path and run the setup on such a computer it'll ruin everything. So that's why I was looking for a way to dynamically obtain the All Users Desktop.
Originally Posted by DataMiser
You are aware however that if you place a shortcut on the desktop of the current user and that same shortcut on the desktop of all users then the current user will have 2 of them and may very likely delete one of them which also may very likely be the one for all users 50/50 chance.
Actually I'm not planning to have both on the same setup so it's alright.
-
May 8th, 2010, 07:29 AM
#4
Re: Desktop Shortcut to All Users Desktop
If you use the code you already have working for the users desktop and simply look at what that returns you can determine the correct path for the all users.
Simply take the drive letter and root folder from what is returned for the current user, check to see if the root folder is users if so then add the public portion to it, if not then add the all users portion.
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|