I'm using the following code to verify the status of computers. The problem
is that each time a command prompt is launched the focus is changed... Is
there a way to make the process invisible to the user?


**************
Set objShell = CreateObject("WScript.Shell")
Set objWshScriptExec = objShell.Exec("ping " & strComputer & " -n 1")
Set objStdOut = objWshScriptExec.StdOut
For j = 1 To 3
strLine = objStdOut.ReadLine
Next
strLine = objStdOut.ReadLine
**************

Thank you for the help,

Daniel

Re: CreateObject("WScript.Shell") by DiGiTAL

DiGiTAL
Thu Dec 01 10:36:44 CST 2005

Sorry, but no. The sell.exec will always pop up a window for as long as
it takes the command to run.
If you need to run a command silently, you might try running it with
WshShell and piping the output to a temp file and then reading that
file.


---
Life is all about ass; you're either covering it, laughing it off,
kicking it, kissing it, busting it, trying to get a piece of it,
behaving like one, or living with one!

*** Sent via Developersdex http://www.developersdex.com ***

Re: CreateObject("WScript.Shell") by James

James
Thu Dec 01 11:55:35 CST 2005

"Daniel" <Daniel@discussions.microsoft.com> wrote in message
news:13BF8A87-964E-423E-9BB6-A36AFA6FA7DD@microsoft.com...
> I'm using the following code to verify the status of computers. The
problem
> is that each time a command prompt is launched the focus is changed... Is
> there a way to make the process invisible to the user?
>
>
> **************
> Set objShell = CreateObject("WScript.Shell")
> Set objWshScriptExec = objShell.Exec("ping " & strComputer & " -n 1")
> Set objStdOut = objWshScriptExec.StdOut
> For j = 1 To 3
> strLine = objStdOut.ReadLine
> Next
> strLine = objStdOut.ReadLine
> **************

There are a few options you could consider. If you launch the script from
a command window using cscript.exe, it will not pop a new window for the
'Exec' commands, they will remain confined to the command window. You could
using something like, "cscript.exe myscript.exe". You could also use the
'Run' method and check the return code. Something like this (watch for
wrapping):

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set objShell = CreateObject("WScript.Shell")
iPing = objShell.Run("%comspec% /c ping " & strComputer & " -n 1", 0, True)
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

No command window or focus change will take place. In the above example,
'iPing' will contain "0" if ping succeeds and non-zero (most likely "1") if
ping fails.

The last (and most kludgy) option would be to relaunch your entire script
using the 'Run' method and hide the window. When you do this, 'Exec' windows
will not be seen. Just add something like this to the top of your code
(watch for wrapping):

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If WScript.Arguments.Count = 0 Then
CreateObject("WScript.Shell").Run _
"cscript.exe """ & WScript.ScriptFullName & """ Silent", 0, False
WScript.Quit
End If
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In the last example, be aware that 'WScript.Echo' will be invisible.
However, 'MsgBox' will still produce a visible GUI box.



Re: CreateObject("WScript.Shell") by Mo

Mo
Sun Dec 04 10:41:05 CST 2005

James Whitlow wrote:

> "Daniel" <Daniel@discussions.microsoft.com> wrote in message
> news:13BF8A87-964E-423E-9BB6-A36AFA6FA7DD@microsoft.com...
> > I'm using the following code to verify the status of computers. The
> problem
> > is that each time a command prompt is launched the focus is
> > changed... Is there a way to make the process invisible to the
> > user?

You could use WMi to ping but the PC must bea Windows XP PC

IPing("SomeComputer")

Function IPing(Target)


Set PingResults =
GetObject("winmgmts://./root/cimv2").ExecQuery("SELECT * FROM
Win32_PingStatus WHERE Address = '" & Target & "'")

For Each PingResult In PingResults

If PingResult.StatusCode = 0 then
IPing = True
else
Iping = "red"
end if
Next


End Function

--
Mo