zoukankan      html  css  js  c++  java
  • 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(IntPtr hwndOwner,  int  nFolder, IntPtr hToken,  int  dwFlags, StringBuilder lpszPath);

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

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

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

                Console.Read();
            }

        }

    }

    结果如下

    0 :C:/Documents and Settings/Administrator/桌面
    1 :
    2 :C:/Documents and Settings/Administrator/「开始」菜单/程序
    3 :
    4 :
    5 :C:/Documents and Settings/Administrator/My Documents
    6 :C:/Documents and Settings/Administrator/Favorites
    7 :C:/Documents and Settings/Administrator/「开始」菜单/程序/启动
    8 :C:/Documents and Settings/Administrator/Recent
    9 :C:/Documents and Settings/Administrator/SendTo
    10 :
    11 :C:/Documents and Settings/Administrator/「开始」菜单
    12 :
    13 :C:/Documents and Settings/Administrator/My Documents/My Music
    14 :C:/Documents and Settings/Administrator/My Documents/My Videos
    15 :
    16 :C:/Documents and Settings/Administrator/桌面
    17 :
    18 :
    19 :C:/Documents and Settings/Administrator/NetHood
    20 :C:/WINDOWS/Fonts
    21 :C:/Documents and Settings/Administrator/Templates
    22 :C:/Documents and Settings/All Users/「开始」菜单
    23 :C:/Documents and Settings/All Users/「开始」菜单/程序
    24 :C:/Documents and Settings/All Users/「开始」菜单/程序/启动
    25 :C:/Documents and Settings/All Users/桌面
    26 :C:/Documents and Settings/Administrator/Application Data
    27 :C:/Documents and Settings/Administrator/PrintHood
    28 :C:/Documents and Settings/Administrator/Local Settings/Application Data
    29 :
    30 :
    31 :C:/Documents and Settings/All Users/Favorites
    32 :C:/Documents and Settings/Administrator/Local Settings/Temporary Internet Files
    33 :C:/Documents and Settings/Administrator/Cookies
    34 :C:/Documents and Settings/Administrator/Local Settings/History
    35 :C:/Documents and Settings/All Users/Application Data
    36 :C:/WINDOWS
    37 :C:/WINDOWS/system32
    38 :C:/Program Files
    39 :C:/Documents and Settings/Administrator/My Documents/My Pictures
    40 :C:/Documents and Settings/Administrator
    41 :C:/WINDOWS/system32
    42 :
    43 :C:/Program Files/Common Files
    44 :
    45 :C:/Documents and Settings/All Users/Templates
    46 :C:/Documents and Settings/All Users/Documents
    47 :C:/Documents and Settings/All Users/「开始」菜单/程序/管理工具
    48 :C:/Documents and Settings/Administrator/「开始」菜单/程序/管理工具
    49 :
    50 :
    51 :
    52 :
    53 :C:/Documents and Settings/All Users/Documents/My Music
    54 :
    55 :C:/Documents and Settings/All Users/Documents/My Videos
    56 :C:/WINDOWS/resources
    57 :
    58 :
    59 :C:/Documents and Settings/Administrator/Local Settings/Application Data/Microsoft/CD Burning
     

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

  • 相关阅读:
    Apache的Order Allow,Deny 详解
    apache的AllowOverride以及Options使用详解
    安装启动apache2.4后报Invalid command 'order', perhaps misspelled or defined by a module not included
    前端常见跨域解决方案(全)
    php面试宝典
    php面试题2018
    nginx负载均衡的5种策略
    多台服务器共享session问题
    小程序定义并使用类
    微信小程序真机预览接口不到数据,打开调试确能请求到
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6204959.html
Copyright © 2011-2022 走看看