Solved

How to start an external program using VBScript.

Posted on 2002-06-17
7
677 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Opening Remote & Local Data Connection 2 51
Visual Basic Excel Formatting error 4 83
MS Access Search and Replace Using VBA 6 57
vbModal 12 34
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 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

23 Experts available now in Live!

Get 1:1 Help Now