Solved

How to start an external program using VBScript.

Posted on 2002-06-17
7
681 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

690 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