Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically Answer "Yes" in VBScript

Status
Not open for further replies.

cjones46

IS-IT--Management
Mar 19, 2013
2
US
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!
 
Piping that in was my first thought. I just can't seem to make it work with what I've presented. Where, in the script that I posted, do I put that "echo Y |"? I can't get the script to run if I add that in. I even tried breaking the sSyDir and cacls.exe commands apart and then adding the pipe but it just breaks.

You have to speak slowly and use small words, this is not my forte :)
 
I dont know if you have already checked this out. It gives you an idea how to get
the solution I think you are looking for:



Hope this helps in some way


“Patience, n. A minor form of dispair, disguised as a virtue.”
 
First, the FoldPerm string contains an erroneous command. When you [tt]msgbox FoldPerm[/tt], it's clear where the problems lie. If this is the command that is executed, I don't see how it ever ran without error.

[tt]"C:Windows\System32\cacls.exe""C:\test" /T /C /G "-username-":f[/tt]

There needs to be a space between the quoted Calcds and "C:\test". Also, I assume """-username-""" is supposed to represent the user in which to grant. Is there actually a user in your domain with a username of "-username-"?

Code:
strUser = "mydomain\bill"
FoldPerm = """" & Calcds & """[highlight #CC0000] [/highlight]" & """C:\test""" & " /T /C /G " & strUser & ":f"

To prevent confusion, I use chr(34) to represent a quote:

Code:
strUser = "mydomain\bill"
FoldPerm = chr(34) & Calcds & chr(34) & " " & chr(34) & "C:\test" & chr(34) & " /T /C /G " & strUser & ":f"

Pipe in the Y before calling the Calcds

Code:
strUser = "mydomain\bill"
FoldPerm = [red]"echo Y | " &[/red] chr(34) & Calcds & chr(34) & " " & chr(34) & "C:\test" & chr(34) & " /T /C /G " & strUser & ":f"

Well, I can't get this to work on Windows7. It did work on XP some years ago but I can't verify that that is still the case

-Geates

NOTE: If paths have spaces in them (e.g. c:\program files), they need to be surround by quotes. If the path don't contain spaces, they don't need to be surrounded. Because none of you paths contain spaces, they don't need to be surrounded. Also, the shell knows in what directories to look for executables - c:\windows\system32 is one of the directories so that doesn't need to be included either.

Code:
strUser = "mydomain\bill"
FoldPerm = "echo Y | cacls c:\test /T /C /G " & strUser & ":f"




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top