Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Execute icacls in Visual Basic script

Posted on 2013-11-06
6
Medium Priority
?
2,440 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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

618 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