Solved

How to start an external program using VBScript.

Posted on 2002-06-17
7
676 Views
Last Modified: 2008-02-01
I want to write a VBscript that runs the program DCDIAG.EXE with switches and outputs the results to a text file.
I want it to do the below equivalent.

"DCDIAG.EXE /S:MYSERVER /Q >C:\DCDIAG.LOG"

What I have so far is below but it doesn't run correctly. It runs the DCDIAG but not with the switches etc.


strComputer = "MyComputer"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process")
RunResult = objWMIService.Create "DCDIAG.EXE /S:MYSERVER /Q  C:\DCDIAG.LOG",null,null )



0
Comment
Question by:petermoh
7 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 7085027
Is there a permissions problem or something?

Set WShell = CreateObject("WScript.Shell")  WShell.Run "c:\DCDIAG.EXE /S:MYSERVER /Q >C:\DCDIAG.LOG"
0
 
LVL 4

Expert Comment

by:TigerZhao
ID: 7086852
Shell "DCDIAG.EXE /S:MYSERVER /Q >C:\DCDIAG.LOG"
0
 

Author Comment

by:petermoh
ID: 7090731
PaulHews, your answer does run

Set WShell = CreateObject("WScript.Shell")  WShell.Run "c:\DCDIAG.EXE /S:MYSERVER /Q >C:\DCDIAG.LOG"

with the switchs /s and /q however it doesn't output the results to a text file. i.e. the >C:\DCDIAG.LOG doesn't work. I need this bit working. Permissions are not a problem I just have very limited knowledge of VBScript. FYI it you want to test just substitute DCDIAG with another simple utility that outputs data like tlist for example.




0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 38

Accepted Solution

by:
PaulHews earned 80 total points
ID: 7090826
That's because of a problem with the way console apps are run from within other processes.  See:

HOWTO: Redirect Standard I/O of a Console App Using Batch File (Q150767)
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q150767



Here is the standard MS workaround outlined in that link, redesigned for VBScript.

Set oWShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextStream = oFSO.CreateTextFile("C:\temp.bat")
oTextStream.Write "Dir C:\*.* > C:\Directory.txt"
oTextStream.Close

oWShell.Run "c:\temp.bat", , True
oFSO.DeleteFile "C:\temp.bat"
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 7090828
I used Dir, but you can use any console app that outputs to the StdOut.
0
 

Author Comment

by:petermoh
ID: 7090890
Thanks Paul.
0
 
LVL 1

Expert Comment

by:ASW3382
ID: 25530063
Just stumbled across this while looking for a creative way to do some scripting and thought I would update that 7 years later now you can run DCDIAG /f:text.log or /ferr:text.log to log only errors.  No batch necessary.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now