Re: output to test file/command window

From: Peter (peter_news_at_rus.cz)
Date: 01/12/05


Date: Wed, 12 Jan 2005 13:14:41 +0100

Fred wrote:
> I have the following script, designed to list members of
> the admins group on networked PCs. I can get the script to
> display the results in a msgbox. Is there an easy way to
> output the results to the command window or a text file
> rather than the msgbox?
>
> Mant thanks in advance
>
> 'On Error Resume Next
> Title = "Get Admins"
> Set WshNet = CreateObject("Wscript.Network")
> strComputer = "."
> Set wmi = GetObject("winmgmts:
> {impersonationLevel=impersonate}!//" & strcomputer)
> ' check the service pack level
> qry = "select * from Win32_OperatingSystem"
> For each OS in wmi.ExecQuery(qry)
> sp = OS.CSDVersion
> osver = OS.Version
> Next
> If (sp = "Service Pack 4" and osver = "5.0.2195") Or osver
>
>>"5.1" Then
>
> getlocaladmins(strcomputer)
> Else
> try = MsgBox(strcomputer & " may not be optimized
> to perform the WMI query in this script. Therefore this
> may take a significant period of time to query" & vbcrlf &
> vbcrlf & "Do you want to try it anyway?",4100)
> If try = 6 Then
> getlocaladmins(strcomputer)
> Else
> Wscript.Echo "....quitting"
> End If
> End If
> Function getlocaladmins(strcomputer)
> outputstrg = "Type" & vbtab & "Domain" & vbtab &
> vbtab & "Name" & vbcrlf
> qry = "SELECT * FROM Win32_GroupUser WHERE
> GroupComponent = " & Chr(34) & "Win32_Group.Domain=\" & Chr
> (34) & "BUILTIN\" & Chr(34) & ",Name=\" & Chr(34)
> & "Administrators\" & Chr(34) & Chr(34)
> For Each Admin in wmi.ExecQuery(qry)
> acct = admin.PartComponent
> 'MsgBox acct
> If InStr(LCase(acct),"win32_useraccount")
>
>>0 Then
>
> SIDType = "User"
> ElseIf InStr(LCase(acct),"win32_group") >
> 0 Then
> SIDType = "Group"
> End If
> Domain = Mid(acct,InStr(LCase
> (acct),"domain=" & Chr(34)) + 8,(InStr(LCase
> (acct),",name=")) - (InStr(LCase(acct),"domain=" & Chr
> (34)) + 8) -1)
> NameStrg = Mid(acct,InStr(LCase
> (acct),"name=" & Chr(34)) + 6,Len(acct) - (InStr(LCase
> (acct),"name=" & Chr(34)) + 6))
> outputstrg = outputstrg & vbcrlf & SIDType
> & vbtab & domain & vbtab & vbtab & NameStrg
> Next
>
> End Function

Hi,

yes, there is:
start your script from command line with cscript
cscript /nologo yourscript.vbs
or change default script interpreter to cscript (currently you use wscript):
cscript /h:cscript

Wishing a nice day,

Peter

Olomouc, Czech Rep.



Relevant Pages

  • Re: output to test file/command window
    ... If you use WScript.echo rather than MsgBox then output goes to StdOut ... > script itself calls the message box. ... >>> 'MsgBox acct ... >>start your script from command line with cscript ...
    (microsoft.public.scripting.wsh)
  • Re: cscript errors when running many concurrent vbs scripts
    ... > i have a java application that spawns cscript to run a simple vbs ... > Script Host failed. ... > processes from java), i'm looking into writing a c++ dll that makes ...
    (microsoft.public.scripting.wsh)
  • Re: redirect error output to file
    ... the script fails. ... something like that to capture the error message flahsing by in my ... Run the script from a command window: ... Use the cscript host at a command prompt. ...
    (microsoft.public.scripting.vbscript)
  • RE: Using SMS to install network printers
    ... - When it spawns it has to have appropriate rights. ... directory from a command line and run the batch file. ... You might have to tweak your script a bit for error ... > cscript SCRIPTNAME.VBS ...
    (microsoft.public.sms.misc)
  • Re: Perfmon script not working??
    ... I had perfmon call a bat file with (cscript ... | I'm trying to monitor free disk space using Performance Monitor. ... | free space falls below a certain value I have an email.vbs script I ... | An alert was created on Windows 2003 server using the Logical Disk ...
    (microsoft.public.win2000.general)