VBscript Unable to Run Shell Command

vbscriptwsh

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?

Thanks,

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

Best Answer

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:

objWshShell.Run("cmd /k echo Hello World", 1, TRUE)
Related Topic