none
cacls within vbscript fails - possibly because of spaces in path?

    Question

  • I'm trying to do something simple and after failing miserably for the last 2 hours have decided to ask for help.

    All I need to do is set everyone = full control on a remote computer, for a folder in Program Files. I'm trying to use cacls to do this. If I run the command in a cmd window, it works. The wscript.echo setPerms at the end of the script is showing the correct command.

    Any hints welcomed!

    ----


    strComputer = InputBox("Enter the remote computer name:", "Input required")
    Set objShell = CreateObject("Wscript.Shell")
    
    If strComputer = False then
        'user clicked the cancel button, exit the script
        wscript.quit
    End If
    
    ' end the script if the computer does not ping
    
    Set WshShell = CreateObject("WScript.Shell")
    PINGFlag = Not CBool(WshShell.run("ping -w 500 -n 1 " & strComputer,0,True))
        If PINGFlag = False Then
        MsgBox strComputer & ": Host was not reachable.", vbexclamation, "Connect failed"
        wscript.quit
    End If
    
    strDest = "\\" & strComputer & "\c$\Program Files\vbscript test\"
    setPerms = "%COMSPEC% /c echo Y| C:\windows\system32\cacls.exe " & Chr(34) & strDest & Chr(34) & " /G domain\everyone:F"
    
    wscript.echo setPerms
    WshShell.run setPerms
    Wednesday, November 04, 2009 12:02 PM

Answers

  • Fixed by injecting some command prompt language in there:

    setPerms = "%COMSPEC% /c for /F ""tokens=*"" %i in (""\\" & strComputer & "\c$\Program Files\vbscript test"") do echo Y| cacls ""%~fsi"" /G domain\everyone:F"


    Cheers for the reply.
    • Marked as answer by Ben Stokes _UK_ Wednesday, November 04, 2009 12:53 PM
    Wednesday, November 04, 2009 12:53 PM

All replies

  • you can try by changing strDest = "\\" & strComputer & "\c$\Program Files\vbscript test\"
    in strDest = "\\" & strComputer & """\c$\Program Files\vbscript test\"""
    and by adding &Chr(34) you profide 2 spaces to the centinse since there is alraedy a space in it.
    Wednesday, November 04, 2009 12:19 PM
  • Fixed by injecting some command prompt language in there:

    setPerms = "%COMSPEC% /c for /F ""tokens=*"" %i in (""\\" & strComputer & "\c$\Program Files\vbscript test"") do echo Y| cacls ""%~fsi"" /G domain\everyone:F"


    Cheers for the reply.
    • Marked as answer by Ben Stokes _UK_ Wednesday, November 04, 2009 12:53 PM
    Wednesday, November 04, 2009 12:53 PM