Solved

VBS run dos command problem

Posted on 2004-04-27
3
2,345 Views
Last Modified: 2007-12-19
Hi.

srvinfo.exe is a W2K Resource Kit program that will list all sorts of information about local and remote computers. I cannot get the below VBS to work. It is supposed to open a dos prompt, run a command, write the results to a file, then close the dos prompt. Any suggestions?

--------------------------
Option Explicit
Dim fso, ts, strComputer, objShell, iReturn, objCommand
Const ForReading = 1
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
' CHANGE THE PATH ON THE NEXT LINE
Set ts = fso.OpenTextFile("C:\Documents and Settings\user\Desktop\SDService\serverlist.txt", ForReading)

Do While Not ts.AtEndOfStream
  strComputer = Trim(ts.ReadLine)
Set objCommand = WScript.CreateObject ("srvinfo -nf \\" & strComputer & " > C:\Documents and Settings\User\Desktop\SDService\Results\" & strComputer & ".txt")
Set objShell = wscript.createObject("wscript.shell")
iReturn = objShell.Run ("%comspec% /C objCommand",1,True)
Loop

ts.Close
Set ts = Nothing
Set fso = Nothing
-----------------------------------

Thanks

PLSM
0
Comment
Question by:PLSM
3 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 10927255
Hmm-you might try including the full path to srvinfo, and/or preceding that command by
CMD /C srvinfo...
0
 

Accepted Solution

by:
PLSM earned 0 total points
ID: 10927819
Sorry but this has been solved like:
--------------------------------------------
Option Explicit
Dim fso, ts, strComputer, objShell, objComputer, Service, strSvrList
Const ADS_SERVICE_RUNNING = &H4
Const ForReading = 1

Set fso = WScript.CreateObject("Scripting.FileSystemObject")
' CHANGE THE PATH ON THE NEXT LINE
Set ts = fso.OpenTextFile("C:\Documents and Settings\user\Desktop\SDService\serverlist.txt", ForReading)
Do While Not ts.AtEndOfStream
  strComputer = Trim(ts.ReadLine)

Set objComputer = GetObject("WinNT://" & strComputer)
strSvrList = "The Service on " & objComputer.ADsPath & " is started: "
For Each Service In objComputer
      If Service.Name = "SDService" then
            If Service.Class = "Service" Then            
                  If Service.Status = ADS_SERVICE_RUNNING then
                        strSvrList = strSvrList & Service.name
                  End If
            End if
      End If
Next
WScript.Echo strSvrList

Loop

ts.Close
Set ts = Nothing
Set fso = Nothing
-------------------------------------------
So I will ask for a PAQ and Refund if that's ok with all?
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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.
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…

773 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