Re: output to test file/command window

From: Joe Fawcett (joefawcett_at_hotmail.com)
Date: 01/12/05


Date: Wed, 12 Jan 2005 15:44:16 -0000

If you use WScript.echo rather than MsgBox then output goes to StdOut
(console) when run from CScript.exe.

-- 
Joe (MVP)
"fred" <anonymous@discussions.microsoft.com> wrote in message
news:051b01c4f8b0$1d6a6120$a401280a@phx.gbl...
> Thanks for the advice. Though it doesn't seem to work, the
> script itself calls the message box. Any suggestions on
> how to alter the script ?
>
>
> >-----Original Message-----
> >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: Retrieving changes to AD via VBS
    ... The script runs every 15 minutes and takes less than a ... > have recording thr highestCommittedUSN and comparing it to the current ... > MsgBox "highestCommittedUSN written to file" ... > Set objConnection = CreateObject ...
    (microsoft.public.win2000.active_directory)
  • Re: Err values from MapNetworkDrive failures
    ... msgbox Err.description ... '// I switched to run so I can ensure this command ... '// this turns error handling off ... that allows me to see where the script stops. ...
    (microsoft.public.windows.server.scripting)
  • Re: MessageBox questions
    ... than MsgBox since that is a function in the VBScript ... > script was from AWK about a hundred years ago - whew! ... >>reference to JScript and MessageBox that seemed even remotely like it ... >>work for me since I need to tie it to a web service response. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Camera automation under Vista
    ... I am trying the get the following script to work under Vista: ... Dim Command, Name, Description, Icon, EventID, DeviceID, i ... MsgBox "Registering Event Handler" ... MsgBox "Unregistering Event Handler" ...
    (microsoft.public.scripting.vbscript)
  • Re: output to test file/command window
    ... I can get the script to ... > display the results in a msgbox. ... > output the results to the command window or a text file ... start your script from command line with cscript ...
    (microsoft.public.scripting.wsh)