Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

Question

Auto answer Y to VB script prompt

Mar 21, 2013 2:54AM PDT

I am using the following script to automate changing permissions on our file servers using cacls.exe:

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 & "\"

'Remove all existing permsissions and grant domain admins full rights
Calcds = sSysDir & "cacls.exe"

FoldPerm = """" & Calcds &"""" & """C:\test""" & " /T /C /G " & """-username-""" & ":f"

oShell.Run FoldPerm, 1 , True

If you use the /E switch for cacls the entire script runs without issue. However, I want the first set of alterations to completely overwrite the existing permissions so the /E switch will not be used.

When the /E switch is not used you are prompted, in a separate command window "Are you sure Y/N?" Since this will be running at 2 Am on Sundays I'd prefer to not have to wake up and answer "Yes" every time it hits a new directory.

I'm not very good at this so I'm hoping for some help.

Thank you!

Discussion is locked

- Collapse -
Clarification Request
Sorry but I don't use the vb script for this.
Mar 21, 2013 3:01AM PDT
- Collapse -
Reply
Mar 21, 2013 3:47AM PDT

I have two questions:

1) The notation preceding the batch files strictly dictates that this be used for users home directories, or directories whose names match the username. Will this work outside those parameters?

2) Since I am doing overwriting and replacing permissions, weekly, for an entire fileserver, how modular is this language? With the script that I provided initially all you need to do is copy and paste the below segment of script and change the directory and username accordingly. For example:

Calcds = sSysDir & "cacls.exe"

FoldPerm = """" & Calcds &"""" & """C:\test""" & " /T /C /G " & """-username-""" & ":f"

oShell.Run FoldPerm, 1 , True

Calcds = sSysDir & "cacls.exe"

FoldPerm = """" & Calcds &"""" & """C:\test""" & " /E /T /C /G " & """-usernameA-""" & ":f"

oShell.Run FoldPerm, 1 , True
Calcds = sSysDir & "cacls.exe"

FoldPerm = """" & Calcds &"""" & """C:\testA""" & " /E /T /C /G " & """-usernameB-""" & ":f"

oShell.Run FoldPerm, 1 , True

and so on throughout the entire file structure. So in relatively little time I can assemble the language for an entire file server.

- Collapse -
1. I don't see why not.
Mar 21, 2013 3:52AM PDT

But more importantly I want to be sure you understand my replies. That is, I can not write scripts for anyone. Why this is, and this is important to understand is that folk may hold me liable. Second, as the administrator you must fully grasp your script.

With that out of the way there is one last issue.

The solution will likely change with the Server OS in use. I don't see that here so I found something very close to what we used in a Microsoft issued KB article. That way I can't be held liable.
Bob

- Collapse -
Answer
Re: script
Apr 5, 2013 8:16PM PDT

Run the script with input redirected to a file that contains 1000 lines containing Y. Then it will read Y 1000 times. Might be enough. If not, add more lines.

Input and output redirection are basic features of the command processor, so I won't go into details here.

Kees