Solved

How to start an external program using VBScript.

Posted on 2002-06-17
7
678 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

777 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