Take the 2-minute tour ×

I have set up the following Sub to run shell commands quickly and easily. This script works for the login scripts at my company without fail. I am currently developing a script to add a large batch of users to our domain. When I used this Sub in my new script I receive an error saying that the file cannot be found. I have tried using the fix in this stackoverflow post, but I recieve the same error even with this code. VBScript WScript.Shell Run() - The system cannot find the file specified

The part I find puzzling is that this sub works just fine when run from the netlogon folder of our domain controller. What am I doing wrong?


Sub runcommand(strCommand)
Dim objWshShell, intRC
set objWshShell = WScript.CreateObject("WScript.Shell")
intRC = objWshShell.Run(strCommand, 0, TRUE)
call reportError(intRC,strCommand)
set objWshShell = nothing 
end Sub

function reportError(intRC, command)
if intRC <> 0 then 
 WScript.Echo "Error Code: " & intRC 
 WScript.Echo "Command: " & command 
end if
end function
share|improve this question
Since you didn't specify... trying to run the value of strCommand in the command prompt succeeds, right? –  Daniel Cook Oct 25 '12 at 14:45
Yes running this from the command line does not return any errors –  Talon06 Oct 25 '12 at 15:05
Whats the value of strCommand –  Alex K. Oct 25 '12 at 15:46
It varies depending on what is needed, but so far in testing I was trying to just echo out variables. Currently the value of strCommand is "echo Hello World" –  Talon06 Oct 25 '12 at 15:51
Well that's not an executable program, to run that you need to pass it to the command interpreter objWshShell.Run("cmd /k echo Hello World", 1, TRUE) –  Alex K. Oct 25 '12 at 16:22

1 Answer 1

up vote 1 down vote accepted

The previous values for strCommand had no spaces and were very straightforward. Your new script is passing more complex variables to your Sub so you need additional conditional handling, as Alex K. pointed out in his Collusion (i.e., "Comment/Solution") above. Alex K.'s sample above is perfect, so, being a Point Pimp tonight, will post it as the solution:

share|improve this answer

Your Answer


