如何获取共享文件的路径

using   System;  
  using   System.Management;  
   
  namespace   ConsoleApplication1  
  {  
  ///   <summary>  
  ///   Class1   的摘要说明。  
  ///   </summary>  
  class   Class1  
  {  
  ///   <summary>  
  ///   应用程序的主入口点。  
  ///   </summary>  
  [STAThread]  
  static   void   Main(string[]   args)  
  {  
                          ManagementObjectSearcher   searcher   =   new    
                                  ManagementObjectSearcher("select   *   from   win32_share");  
                          foreach   (ManagementObject   share   in   searcher.Get())    
                          {  
                                  Console.WriteLine(share["Name"].ToString());                 //名称  
                                  Console.WriteLine(share["Path"].ToString());                 //路径  
                          }  
  }  
  }  
  } 

 

注册表中有:  
  HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/lanmanserver/Shares 

不知从select   *   from   win32_share还可以得到其它什么属性

应该是包括下面这些信息,在msdn中有  
   
      uint32   AccessMask;  
      boolean   AllowMaximum;  
      string   Caption;  
      string   Description;  
      datetime   InstallDate;  
      uint32   MaximumAllowed;  
      string   Name;  
      string   Path;  
      string   Status;  
      uint32   Type;  
   
   
   
   
   
   
  Properties  
  The   Win32_Share   class   defines   the   following   properties.    
   
  AccessMask    
  Data   type:   uint32  
  Access   type:   Read-only  
   
  List   of   access   rights   to   the   given   file   or   directory   held   by   the   user   or   group   on   whose   behalf   the   instance   is   returned.   This   property   is   only   supported   under   Windows   NT   and   Windows   2000.   On   Windows   98   and   on   Windows   NT/Windows   2000   FAT   volumes,   the   FULL_ACCESS   value   is   returned   instead,   indicating   no   security   has   been   set   on   the   object.  
   
   
  Windows   2000,   Windows   XP:     This   property   is   no   longer   used   due   to   the   expense   of   calling   GetEffectiveRightsFromAcl.   You   should   use   the   Win32_Share.GetAccessMask   method   instead.   The   value   of   the   AccessMask   property   is   set   to   NULL.  
   
   
   
   
  AllowMaximum    
  Data   type:   boolean  
  Access   type:   Read-only  
   
  Number   of   concurrent   users   for   this   resource   has   been   limited.   If   TRUE,   the   value   in   the   MaximumAllowed   property   is   ignored.  
   
   
  Caption    
  Data   type:   string  
  Access   type:   Read-only  
   
  Short   description   (one-line   string)   of   the   object.  
   
   
  Description    
  Data   type:   string  
  Access   type:   Read-only  
   
  Description   of   the   object.  
   
   
  InstallDate    
  Data   type:   datetime  
  Access   type:   Read-only  
   
  Object   was   installed.   This   property   does   not   need   a   value   to   indicate   that   the   object   is   installed.  
   
   
  MaximumAllowed    
  Data   type:   uint32  
  Access   type:   Read-only  
   
  Limit   on   the   maximum   number   of   users   allowed   to   use   this   resource   concurrently.   The   value   is   only   valid   if   the   AllowMaximum   property   is   set   to   FALSE  
   
   
  Name    
  Data   type:   string  
  Access   type:   Read-only  
  Qualifiers:   Key  
   
  Alias   given   to   a   path   set   up   as   a   share   on   a   Windows   system.  
   
  Example:   "public"  
   
   
  Path    
  Data   type:   string  
  Access   type:   Read-only  
   
  Local   path   of   the   Windows   share.  
   
  Example:   "C:/Program   Files"  
   
   
  Status    
  Data   type:   string  
  Access   type:   Read-only  
   
  Current   status   of   the   object.   Various   operational   and   non-operational   statuses   can   be   defined.   Operational   statuses   include:   "OK",   "Degraded",   and   "Pred   Fail"   (an   element,   such   as   a   SMART-enabled   hard   drive,   may   be   functioning   properly   but   predicting   a   failure   in   the   near   future).   Non-operational   statuses   include:   "Error",   "Starting",   "Stopping",   and   "Service".   The   latter,   "Service",   could   apply   during   mirror-resilvering   of   a   disk,   reload   of   a   user   permissions   list,   or   other   administrative   work.   Not   all   such   work   is   on-line,   yet   the   managed   element   is   neither   "OK"   nor   in   one   of   the   other   states.    
   
  Values   are:  
   
  "OK"  
  "Error"  
  "Degraded"  
  "Unknown"  
  "Pred   Fail"  
  "Starting"  
  "Stopping"  
  "Service"  
  "Stressed"  
  "Nonrecover"  
  "Nocontact"  
  "LostComm"  
   
   
   
  Type    
  Data   type:   uint32  
  Access   type:   Read-only  
   
  Type   of   resource   being   shared.   Types   include   disk   drives,   print   queues,   interprocess   communications   (IPC),   and   general   devices.  
   
  Value   Meaning    
  0   Disk   Drive    
  1   Print   Queue    
  2   Device    
  3   IPC    
  2147483648   Disk   Drive   Admin    
  2147483649   Print   Queue   Admin    
  2147483650   Device   Admin    
  2147483651   IPC   Admin    

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值