Solved

VBS run dos command problem

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

758 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

17 Experts available now in Live!

Get 1:1 Help Now