?
Solved

Execute icacls in Visual Basic script

Posted on 2013-11-06
6
Medium Priority
?
2,352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

752 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