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

来源:百度文库 编辑:神马文学网 时间:2024/05/01 01:00:49
调用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