Solved

Execute icacls in Visual Basic script

Posted on 2013-11-06
6
2,304 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
Technology Partners: 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
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…

707 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