开发者

Assign rights to folder VBA

开发者 https://www.devze.com 2022-12-12 09:19 出处:网络
I use the below code to assign rights to a folder. This works fine when I create a folder on say \"C:/Test\" and run the code. It works fine without any issues, but once I try the same with the folder

I use the below code to assign rights to a folder. This works fine when I create a folder on say "C:/Test" and run the code. It works fine without any issues, but once I try the same with the folder "C:/Documents and Settings", I get an error.

Here is the code; it's VBA code done in a Word document.

Dim intRunError, objShell, objFSO,strHomeFolder         
strHomeFolder = "C:/Documents and Settings"

Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderE开发者_JS百科xists(strHomeFolder) Then
    intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " _
        & strHomeFolder & " /e /c /g everyone:F ", 2, True)
End If
MsgBox intRunError


Perhaps:

"%COMSPEC% /c Echo Y| cacls """ & strHomeFolder & """ /e /c /g everyone:F "
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号