Solved

VBS run dos command problem

Posted on 2004-04-27
3
2,354 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 84
Put text in a picture ASP.NET C# 2 61
Publisher:   Unknown     VB.exe Application 1 28
Problem to line 23 54
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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

828 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