I use Winbatch to do my Windows scripting. Tech support at Wilson Windowware provided me with a user-defined function because I couldn't get two of their built-in functions (RunShell and ShellExecute) to run correctly while accepting parameters. The code for the user-defined function is below:
#DefineFunction GetSTDOUT(cmd)
objShell = ObjectOpen("WScript.Shell")
objWshScriptExec = objShell.Exec(cmd)
objStdOut = objWshScriptExec.StdOut
line = objStdOut.ReadAll
objStdOut = 0
objWshScriptExec = 0
objShell = 0
Return line
#EndFunction
Now, to use this function to run a DOS command-line utility, I simply define the cmd variable (such as cmd = "ipconfig /all"). And this user-defined function has worked perfectly for every command-line utility that I've thrown at it.......except one. If I run "wmic SERVICES LIST BRIEF" manually, from the command line, it runs just fine and displays a list of installed services (for those that are going to suggest it, I don't like the output of the sc command).
But if I set the value of the cmd variable to that (cmd = "wmic SERVICES LIST BRIEF") and run my script, to run that user-defined function, I get an Ole Exception Error (the error dialog box say, "Error: C:\Program Files\Winbatch\System\SMTPConnect.wbt 1261: Ole: Exception ON line 51 of C:\Program...h\System\SMTPConnect.wbt In Routine "getstdout" objWshScriptExec = objShell.Exec(cmd) ").
I contacted the person that created the above user-defined function but she said that she didn't know enough about Wscript to figure out why trying to have it run wmic would cause this Ole exception error.
Does anyone know why this won't work and what I can do to get it working?
>> Stay informed about: Wshell.Exec