分享

用代码实现对文件夹权限的控制

 zqx1000 2006-11-15
调用CACLS.EXE程序 
Public   Function   DelFolderUser(ByVal   path   As   String,   ByVal   UserName   As   String)  
                  If   path.EndsWith("\")   Then   path   =   path.Substring(0,   path.Length   -   1)  
                  Dim   CmdTxt   As   String  
                  CmdTxt   =   syspath   &   "Cacls.exe   "   &   path   &   "   /c   /e   /t   /r   "   &   UserName  
                  Shell(CmdTxt,   vbHide)  
                  Return   True  
          End   Function  
          Public   Function   SetFolderUser(ByVal   PathName   As   String,   ByVal   UserFlag   As   String,   ByVal   replace   As   Boolean)   As   Boolean  
                  ‘Set   Change   Permissions   for   the   developer   using   CACLS.exe  
                  If   PathName.EndsWith("\")   And   PathName.Length   >   3   Then   PathName   =   PathName.Substring(0,   PathName.Length   -   1).Trim  
                  ‘   PathName   =   PathName   &   "\"  
                  Dim   strACLCommand   As   String,   objRTC  
                  strACLCommand   =   "   /c   echo   y|"   &   syspath   &   "Cacls.exe   "  
                  strACLCommand   =   strACLCommand   &   PathName  
                  If   replace   Then  
                          strACLCommand   =   strACLCommand   &   "   /c   /t   /g   "   &   UserFlag  
                  Else  
                          strACLCommand   =   strACLCommand   &   "   /c   /e   /t   /g   "   &   UserFlag  
                  End   If  
                  Dim   objWSH  
                  ‘Set   objWSH   =   Server.CreateObject("WScript.Shell")  
                  ‘objRTC   =   objWSH.Run(strACLCommand,   0,   True)  
                  ‘MsgBox(strACLCommand)  
                  Dim   INF   As   ProcessStartInfo   =   New   ProcessStartInfo  
                  INF.FileName   =   syspath   &   "cmd.exe   "  
                  INF.Arguments   =   strACLCommand  
                  INF.WindowStyle   =   ProcessWindowStyle.Hidden  
                  Dim   bb   As   System.Diagnostics.Process   =   System.Diagnostics.Process.Start(INF)  
                  bb.WaitForExit()  
                  bb.Close()  
                  ‘   Shell(strACLCommand,   vbHide)  
                  ‘Set   objWSH   =   Nothing  
                  Return   True  
          End   Function

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多