How can you tell if a script (vbs) was started by a user or by scheduled
task and no user logged on? If a user starts it someway I want to write to a
message box. If no one is logged on and task scheduler started it I want to
write to a log file.

thanks
ljb

Re: who started script? by Torgeir

Torgeir
Fri Oct 29 13:03:01 CDT 2004

ljb wrote:

> How can you tell if a script (vbs) was started by a user or by
> scheduled task and no user logged on? If a user starts it someway
> I want to write to a message box. If no one is logged on and task
> scheduler started it I want to write to a log file.
Hi

I solve this type of problem by adding a command line parameter
to the script, and then let the script check is this parameter
is there or not.

So you could then start your scheduled script e.g. like this:

wscript.exe "c:\scripts\some.vbs" scheduled


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: who started script? by Michael

Michael
Fri Oct 29 19:24:16 CDT 2004

> I solve this type of problem by adding a command line parameter
> to the script, and then let the script check is this parameter
> is there or not.
>
> So you could then start your scheduled script e.g. like this:
>
> wscript.exe "c:\scripts\some.vbs" scheduled

You can also use the //B (batch) host switch for the scheduled version.

wscript.exe //B "c:\scripts\some.vbs"

When //B is used WScript.Interactive returns false.

The downside is that //B suppresses all wscript.echo output, so it wouldm't
be appropriate if the command line used %comspec% and > stdout redirection.
A workaround in that case is to use wscript.stdout.writeline which isn't
suppressd by //B.

--
Michael Harris
Microsoft.MVP.Scripting
Sammamish WA US


Re: who started script? by Torgeir

Torgeir
Sat Oct 30 04:34:09 CDT 2004

Michael Harris (MVP) wrote:

>>I solve this type of problem by adding a command line parameter
>>to the script, and then let the script check is this parameter
>>is there or not.
>>
>>So you could then start your scheduled script e.g. like this:
>>
>>wscript.exe "c:\scripts\some.vbs" scheduled
>
>
> You can also use the //B (batch) host switch for the scheduled version.
>
> wscript.exe //B "c:\scripts\some.vbs"
>
> When //B is used WScript.Interactive returns false.
>
> The downside is that //B suppresses all wscript.echo output, so it wouldm't
> be appropriate if the command line used %comspec% and > stdout redirection.
> A workaround in that case is to use wscript.stdout.writeline which isn't
> suppressd by //B.
>

Very good tip, Michael :-)


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx