Solved

VBS run dos command problem

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

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
DIR issue 7 51
consolidate or create a new vba code for performing tasks 5 64
Excel object stays open 19 71
Exit a vb6 apps when a calling it apps closes 15 43
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

863 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

30 Experts available now in Live!

Get 1:1 Help Now