包含 Vista 上本地用户的程序文件夹的注册表项
-
09-06-2019 - |
题
我正在解决创建 Vista 快捷方式的问题。
我想确保我们的安装程序正在从正确的注册表项读取程序文件夹。
它从以下位置读取它:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Programs
它显示了程序的这个目录:
C:\Users\NonAdmin2 UAC OFF\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
从我读到的内容来看,这似乎是正确的,但我想仔细检查一下。
解决方案
使用 Windows 安装程序属性。可能会更容易。
http://msdn.microsoft.com/en-us/library/aa370905(VS.85).aspx#system_folder_properties
其他提示
不要使用注册表来读取此内容。使用 SH获取文件夹路径 与 CSIDL_PROGRAMS。
究其原因,请参阅 Raymond Chen 对“Shell 文件夹”键的评论:
http://blogs.msdn.com/oldnewthing/archive/2003/11/03/55532.aspx
您可能应该为此使用 API,例如 SH获取文件夹路径
对我来说听起来是正确的。
VB 中的 SHGetFolderPath 示例http://support.microsoft.com/kb/252652
有用的代码片段:
public class Utilities
{
public enum FolderPaths
{
CSIDL_DESKTOP = 0x0000, // <desktop>
CSIDL_INTERNET = 0x0001, // Internet Explorer (icon on desktop)
CSIDL_PROGRAMS = 0x0002, // Start Menu\Programs
CSIDL_CONTROLS = 0x0003, // My Computer\Control Panel
CSIDL_PRINTERS = 0x0004, // My Computer\Printers
CSIDL_PERSONAL = 0x0005, // My Documents
CSIDL_FAVORITES = 0x0006, // <user name>\Favorites
CSIDL_STARTUP = 0x0007, // Start Menu\Programs\Startup
CSIDL_RECENT = 0x0008, // <user name>\Recent
CSIDL_SENDTO = 0x0009, // <user name>\SendTo
CSIDL_BITBUCKET = 0x000a, // <desktop>\Recycle Bin
CSIDL_STARTMENU = 0x000b, // <user name>\Start Menu
CSIDL_MYDOCUMENTS = CSIDL_PERSONAL, // Personal was just a silly name for My Documents
CSIDL_MYMUSIC = 0x000d, // "My Music" folder
CSIDL_MYVIDEO = 0x000e, // "My Videos" folder
CSIDL_DESKTOPDIRECTORY = 0x0010, // <user name>\Desktop
CSIDL_DRIVES = 0x0011, // My Computer
CSIDL_NETWORK = 0x0012, // Network Neighborhood (My Network Places)
CSIDL_NETHOOD = 0x0013, // <user name>\nethood
CSIDL_FONTS = 0x0014, // windows\fonts
CSIDL_TEMPLATES = 0x0015,
CSIDL_COMMON_STARTMENU = 0x0016, // All Users\Start Menu
CSIDL_COMMON_PROGRAMS = 0X0017, // All Users\Start Menu\Programs
CSIDL_COMMON_STARTUP = 0x0018, // All Users\Startup
CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019, // All Users\Desktop
CSIDL_APPDATA = 0x001a, // <user name>\Application Data
CSIDL_PRINTHOOD = 0x001b, // <user name>\PrintHood
CSIDL_LOCAL_APPDATA = 0x001c // <user name>\Local Settings\Applicaiton Data (non roaming)
}
[DllImport("shfolder.dll", CharSet = CharSet.Unicode)]
public static extern int SHGetFolderPath(IntPtr owner, int folder, IntPtr token, int flags, StringBuilder path);
}
void MyFunction()
{
StringBuilder path = new StringBuilder(260);
String folderPath = "";
if (0 == Utilities.SHGetFolderPath(IntPtr.Zero, (int) Utilities.FolderPaths.CSIDL_MYVIDEO, IntPtr.Zero, 0, path))
{
folderPath = path.ToString();
}
}
不隶属于 StackOverflow