开发者

set permissions with a vbs script

I have a VBS script that downloads a file on login and places it in a given folder, It works brilliantly in some places but in others it falls over because the fil开发者_JS百科e was created by user1 and user2 can't overwrite it.

How would i give the group "Everyone" full control of a given file using a VBS script?


Something like this:

Set WshShell = CreateObject("WScript.Shell")
strFile = "c:\test_folder\test_file.txt"
setPerms = "%COMSPEC% /c echo Y| C:\windows\system32\cacls.exe " & Chr(34) & strFile & Chr(34) & " /G domain\everyone:F"

wscript.echo setPerms
WshShell.run setPerms

Partially gleaned from here: http://social.technet.microsoft.com/forums/en-us/ITCG/thread/6CDA091A-6B3D-4F58-8374-9A46F59F389A


One way of doing it would be to use the CACLS command line tool. Just run it from your script using Shell.Run.

Here's another link to information about how to use CACLS that has some samples.


Function giveFullPermissionToFolder(strFolder)

Dim objShell, strCmd, intRunError

Set objShell = CreateObject("Wscript.Shell")

strCmd = "%comspec% /c echo Y| cacls " & strFolder & " /T /E /C /G Users:F"

intRunError = objShell.Run(strCmd, 2, True)

If intRunError<>0 Then

Reporter.ReportEvent micFail, "giveFullPermissionToFolder" , "Unable to give full permission to " & strFolder

End If

Set objShell=Nothing

End Function

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜