I can't create a shortcut or even create a folder inside C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\
and get an "Access is denied" error in both cases. I am using C++(WinAPI) and am interested in creating a shortcut inside that folder. Code for creating shortcut is working perfectly for other locations(for example for creating shortcuts on Desktop). How can I workaround this error?
Asked
Active
Viewed 1,346 times
0
-
Can you manually create a folder in that location as your own user? – BoBTFish Feb 27 '16 at 17:38
-
Yes, in Windows explorer there is "New->Folder" menu item in windows context menu, however that command required Administrative privileges. – IKM2007 Feb 27 '16 at 17:47
-
2"that command required Administrative privileges" - so, no, then. Try running your program with admin privileges. – BoBTFish Feb 27 '16 at 17:50
-
What does the documentation on MSDN say? – David Heffernan Feb 27 '16 at 18:57
-
4Don't write to `%ProgramData%\Microsoft\Windows\Start Menu` directly. Use `CSIDL_COMMON_STARTMENU`/`FOLDERID_CommonStartMenu` (all users) or `CSIDL_STARTMENU`/`FOLDERID_StartMenu` (current user) to get a suitable path, then create your custom folder underneath it. – Remy Lebeau Feb 27 '16 at 19:10
-
@RemyLebeau Could you elaborate on how? Maybe propose a separate answer? Does this help bypass the admin rights issue? – Enigma Mar 09 '18 at 17:15
-
@Enigma look at `SHGetFolderPath()` and `SHGetKnownFolderPath()`. And no, this doesn't bypass the admin issue. You still need admin rights to create a folder/file in a "common" location for all users. – Remy Lebeau Mar 09 '18 at 17:32
1 Answers
2
Writing to the All-users start menu requires UAC rights. So, you'll need to run your application as administrator. Or just use the current-user start menu "C:\Users\[CurrentUser]\AppData\Roaming\Microsoft\Windows\Start Menu"
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
string StartMenuLocation=
(string)getenv("HOMEDRIVE")+"\\Users\\"+(string)getenv("USERNAME")+"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu";
cout<<StartMenuLocation;
cin.get();
}
Hope this helps.

xxx
- 44
- 5
-
This is based on undocumented internals, and not guaranteed to work. In fact, it doesn't even work for all supported versions of Windows. The [comment by Remy Lebeau](http://stackoverflow.com/questions/35673086/creating-shortcut-inside-windows-start-menu/37418624#comment59027217_35673086) explains, how to do it properly. – IInspectable Nov 11 '16 at 19:38
-
@xxx You can also considered the suggestion of not suggesting an answer based undocumented behavior. You should improve your answer. – Security Hound Nov 12 '16 at 19:09
-
If you feel like fixing things, you should start with your proposed answer. You have all the information you need to come up with a robust solution, that works across all versions of Windows. – IInspectable Nov 13 '16 at 11:03