WshShell.Exec: The system cannot find the file specified.

I'm a running a script to apply permissions to a folder. I've added the location to xcacls.exe in system path, played around with the syntax and I always get the following error: WshShell.Exec: The system cannot find the file specified.

I've echoed the variables. Below is the output from primal script:

strUserID: dduck
strHomeDir: \\acs01\users\PAstu\2011\dduck
Setting Permissions For dduck on \\acs01\users\PAstu\2011\dduck

G:\IS_NTS_Shared\NetAdmin\Scripts\Account_Automation\School\PA\Permissions.vbs(102, 1) WshShell.Exec: The system cannot find the file specified.

Below is the function.

Function setAdmin()
wscript.Echo strUserID
wscript.Echo strHomeDir
wscript.echo("Setting Permissions For " & strUserID & " on " & strHomeDir)
Set objShell = CreateObject("WScript.Shell")
objShell.Exec "xcacls.exe " & strHomeDir & " /G builtin\administrators:F /y" 
wscript.echo("Administrator Permissions granted")
End Function

Open in new window

Who is Participating?

Improve company productivity with a Business Account.Sign Up

abhimail2002Connect With a Mentor Commented:
Try Doing this instead of Set objShell = CreateObject("WScript.Shell")

$objShell = CreateObject("WScript.Shell")
if @error
 ? @error " - " @serror ?
 get $
rejoinderConnect With a Mentor Commented:
Try adding extra quotes around the strHomeDir variable...
objShell.Exec "xcacls.exe """ & strHomeDir & """ /G builtin\administrators:F /y"
JB4375Author Commented:
@abhimail2002: Errors on this line: $objShell = CreateObject("WScript.Shell")
G:\IS_NTS_Shared\NetAdmin\Scripts\Account_Automation\School\PA\Permissions.vbs(103, 1) Microsoft VBScript compilation error: Invalid character
@rejoinder: I added the quotes and got the same error.
If you execute the command manually, does it work?
JB4375Author Commented:
OK, I figured out the that the path to xcacls.exe was off. So much that. Points awarded to both for timely response. Thanks guys
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.