Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBS run dos command problem

Posted on 2004-04-27
3
Medium Priority
?
2,380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses

721 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