System.Environment.GetFolderPath函数中未开放的枚举参数

System.Environment.GetFolderPath函数可以通过Environment.SpecialFolder枚举参数获取系统特定的目录,比如桌面,我的文档,收藏夹等..但是有部分参数.NetFrameWork2.0并未开放,比如AllUser用户的这些特殊目录。我们可以通过windowsApi函数SHGetFolderPath来获取,如果你能通过Reflector看一下FrameWork代码就明白了。

代码如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
... {
class Program
... {
[DllImport(
" shfolder.dll " ,CharSet = CharSet.Auto)]
internal static extern int SHGetFolderPath(IntPtrhwndOwner, int nFolder,IntPtrhToken, int dwFlags,StringBuilderlpszPath);

static void Main( string []args)
... {
for ( int i = 0 ;i <= 255 ;i ++ )
... {
StringBuilderlpszPath
= new StringBuilder( 260 );

SHGetFolderPath(IntPtr.Zero,i,IntPtr.Zero,
0 ,lpszPath);

Console.WriteLine(i.ToString()
+ " : " + lpszPath);
}

Console.Read();
}

}

}

结果如下

0 :C:\DocumentsandSettings\Administrator\桌面
1 :
2 :C:\DocumentsandSettings\Administrator\「开始」菜单\程序
3 :
4 :
5 :C:\DocumentsandSettings\Administrator\MyDocuments
6 :C:\DocumentsandSettings\Administrator\Favorites
7 :C:\DocumentsandSettings\Administrator\「开始」菜单\程序\启动
8 :C:\DocumentsandSettings\Administrator\Recent
9 :C:\DocumentsandSettings\Administrator\SendTo
10 :
11 :C:\DocumentsandSettings\Administrator\「开始」菜单
12 :
13 :C:\DocumentsandSettings\Administrator\MyDocuments\MyMusic
14 :C:\DocumentsandSettings\Administrator\MyDocuments\MyVideos
15 :
16 :C:\DocumentsandSettings\Administrator\桌面
17 :
18 :
19 :C:\DocumentsandSettings\Administrator\NetHood
20 :C:\WINDOWS\Fonts
21 :C:\DocumentsandSettings\Administrator\Templates
22 :C:\DocumentsandSettings\AllUsers\「开始」菜单
23 :C:\DocumentsandSettings\AllUsers\「开始」菜单\程序
24 :C:\DocumentsandSettings\AllUsers\「开始」菜单\程序\启动
25 :C:\DocumentsandSettings\AllUsers\桌面
26 :C:\DocumentsandSettings\Administrator\ApplicationData
27 :C:\DocumentsandSettings\Administrator\PrintHood
28 :C:\DocumentsandSettings\Administrator\LocalSettings\ApplicationData
29 :
30 :
31 :C:\DocumentsandSettings\AllUsers\Favorites
32 :C:\DocumentsandSettings\Administrator\LocalSettings\TemporaryInternetFiles
33 :C:\DocumentsandSettings\Administrator\Cookies
34 :C:\DocumentsandSettings\Administrator\LocalSettings\History
35 :C:\DocumentsandSettings\AllUsers\ApplicationData
36 :C:\WINDOWS
37 :C:\WINDOWS\system32
38 :C:\ProgramFiles
39 :C:\DocumentsandSettings\Administrator\MyDocuments\MyPictures
40 :C:\DocumentsandSettings\Administrator
41 :C:\WINDOWS\system32
42 :
43 :C:\ProgramFiles\CommonFiles
44 :
45 :C:\DocumentsandSettings\AllUsers\Templates
46 :C:\DocumentsandSettings\AllUsers\Documents
47 :C:\DocumentsandSettings\AllUsers\「开始」菜单\程序\管理工具
48 :C:\DocumentsandSettings\Administrator\「开始」菜单\程序\管理工具
49 :
50 :
51 :
52 :
53 :C:\DocumentsandSettings\AllUsers\Documents\MyMusic
54 :
55 :C:\DocumentsandSettings\AllUsers\Documents\MyVideos
56 :C:\WINDOWS\resources
57 :
58 :
59 :C:\DocumentsandSettings\Administrator\LocalSettings\ApplicationData\Microsoft\CDBurning

具体意义可以参照Environment.SpecialFolder枚举说明和windows基本常识来理解。

你可能感兴趣的:(C++,c,windows,Microsoft,C#)