The struggle with quotes, WScript.Shell RUN propertie and XCACLS

Set permissions on bulk with XCACLS and VBScript is rather easy. But if you must pass some variables through the commad line, it can give you a long and painfull headache. For example quotes around variables for domain\username …

Using XCACLS with variables:


strUsername = "jos.de.vos"
strExerciseFolder = "D:\profiles\TEST\jos.de.vos\Exercises"

CommandLine2 = "cscript XCACLS.vbs " & strExerciseFolder & " /g " & chr(34) & chr(34) & "vcampus\" & strUsername & chr(34) & chr(34) & ":m /e"

Set WshShell = CreateObject("WScript.Shell")
WScript.Echo CommandLine2 'print out your command line, to verify your string..
WshShell.Run "CMD /K " & CommandLine2