Solved

Execute icacls in Visual Basic script

Posted on 2013-11-06
6
2,154 Views
Last Modified: 2013-11-12
Can anyone help with the VB script below:
 
set wshshell = wscript.createobject("wscript.shell")
wshshell.run "icacls "C:\WINDOWS\Company Docs" /grant:r "Domain Users":(OI)(CI)M"

Open in new window


Thank you!
0
Comment
Question by:the_omnific
  • 4
  • 2
6 Comments
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39629420
Sample Script to Set CACLS permissions
 

' Cacls.vbs
' Example VBScript to set Administrators permissions with Cacls
' Version 2.1 - September 2010
' ---------------------------------------------------------'
Option Explicit
Dim strHomeFolder, strHome, strUser
Dim intRunError, objShell, objFSO

strHomeFolder = "\\grand\home\user"

Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strHomeFolder) Then
' Assign user permission to home folder.
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " _
& strHomeFolder & " /t /c /g Administrators:F ", 2, True)
   If intRunError <> 0 Then
   Wscript.Echo "Error assigning permissions for user " _
   & strUser & " to home folder " & strHomeFolder
   End If
End If

WScript.Quit

' End of Cacls example VBScript


you can find the full explanation here
http://www.computerperformance.co.uk/vbscript/vbscript_cacls.htm
0
 
LVL 1

Author Comment

by:the_omnific
ID: 39629448
Thanks but the code you posted does not contain the values in my script.
0
 
LVL 1

Accepted Solution

by:
the_omnific earned 0 total points
ID: 39632328
Found the answer myself.

Dim oShell, FoldPerm, Calcds, oFSO

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")

sSysDir = oFSO.GetSpecialFolder(1).Path
If Right(sSysDir,1) <> "\" Then sSysDir = sSysDir & "\"

Calcds = sSysDir & "cacls.exe" 

FoldPerm = """" & Calcds &"""" & """C:\WINDOWS\Company Docs""" & " /E /T /C /G " & """Domain Users""" & ":C" 

oShell.Run FoldPerm, 1 ,True

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:QuinnDex
ID: 39632693
thats what i posted, you just had to adapt it to your needs ????
0
 
LVL 1

Author Comment

by:the_omnific
ID: 39632695
It's not what you posted. The code is different. I tried to adapt your code but it didn't work.
0
 
LVL 1

Author Closing Comment

by:the_omnific
ID: 39641106
Found the answer myself.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now