Solved

Execute icacls in Visual Basic script

Posted on 2013-11-06
6
2,130 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Modifying Conditional Format from VBA code 3 33
Hide Tab Page 3 20
Showdialog 8 21
Convert to Hour/minute textbox and compare 3 37
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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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…
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…

743 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

14 Experts available now in Live!

Get 1:1 Help Now