0

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
5
  • Since you didn't specify... trying to run the value of strCommand in the command prompt succeeds, right? Commented Oct 25, 2012 at 14:45
  • Yes running this from the command line does not return any errors Commented Oct 25, 2012 at 15:05
  • Whats the value of strCommand Commented Oct 25, 2012 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" Commented Oct 25, 2012 at 15:51
  • 3
    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) Commented Oct 25, 2012 at 16:22

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.