Sorry, couldn't think of a better title.

I have this script intended to see if somebody is logged onto a remote PC.
If so (under certain circumstances), I open up a reminder prompt on that PC.
I am using what I take to be a standard generic method, and it -did- work.
Problem is that now, it shows that nobody is logged in, even when they are.
It works OK when I query my machine and the other machines in my office, but
not the remote machines. I am wondering if it involves some obscure network
setting or something.

The guts of the routine are below.
=======================

strComputer = "whs147"
On Error Resume Next

Dim strUser
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

strUser = "NA"
For Each objComputer in colComputer
If cstr(objComputer.UserName) <> "null" Then
strUser = cstr(objComputer.UserName)
End If
Next
If strUser <> "NA" Then
MsgBox "User logged on: " & strUser
Else
MsgBox "Nobody logged on"
End If

Re: Why does this fail sometimes? by Ruskin

Ruskin
Mon Jul 19 18:27:02 CDT 2004

Have you tried taking off your error statement, so that the script fails, if
there is an error... Just a thought, as you may get an error 70, during the
ExecQuery, if the user running the script doesn't have the necessary
permissions to get the WMI services from the 'whs147' machine...



"Skip" <SorryDontLikeSpam@none.null> wrote in message
news:eTgLOMebEHA.1004@TK2MSFTNGP11.phx.gbl...
> Sorry, couldn't think of a better title.
>
> I have this script intended to see if somebody is logged onto a remote PC.
> If so (under certain circumstances), I open up a reminder prompt on that
PC.
> I am using what I take to be a standard generic method, and it -did- work.
> Problem is that now, it shows that nobody is logged in, even when they
are.
> It works OK when I query my machine and the other machines in my office,
but
> not the remote machines. I am wondering if it involves some obscure
network
> setting or something.
>
> The guts of the routine are below.
> =======================
>
> strComputer = "whs147"
> On Error Resume Next
>
> Dim strUser
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set colComputer = objWMIService.ExecQuery _
> ("Select * from Win32_ComputerSystem")
>
> strUser = "NA"
> For Each objComputer in colComputer
> If cstr(objComputer.UserName) <> "null" Then
> strUser = cstr(objComputer.UserName)
> End If
> Next
> If strUser <> "NA" Then
> MsgBox "User logged on: " & strUser
> Else
> MsgBox "Nobody logged on"
> End If
>
>



Re: Why does this fail sometimes? by Skip

Skip
Tue Jul 20 09:38:14 CDT 2004

Thanks for your reply. I did try taking the 'on error' statement off. The
only UserName found is "null" (when somebody is logged in). If I use the
third party tool psLoggedOn from psTools, it does give the correct
information (i.e. the username of the person on the computer).

I would use the psLoggedOn utility (even though I would have to pipe the
results to a text file, then read the text file), however, it appears to
report the last person logged in, even after he logs out<?>. So, in this
case my program would think somebody is logged in even if they are not (as
opposed to the original method which reports that nobody is logged in, even
if they are).

PS: I want to pop-up a reminder message if the user forgets to perform a
manual operation. I would just send the command without worrying if anybody
is logged in, but I discovered that in this case, the pop-up executes the
next time somebody logs in on that pc. Having the pop-up appear at an
inappropriate time could cause confusion and create more problems than it
prevents.


"Ruskin" <ruhardie@nospam.xtra.com> wrote in message
news:bNYKc.2340$N77.204391@news.xtra.co.nz...
> Have you tried taking off your error statement, so that the script fails,
if
> there is an error... Just a thought, as you may get an error 70, during
the
> ExecQuery, if the user running the script doesn't have the necessary
> permissions to get the WMI services from the 'whs147' machine...
>
>
>
> "Skip" <SorryDontLikeSpam@none.null> wrote in message
> news:eTgLOMebEHA.1004@TK2MSFTNGP11.phx.gbl...
> > Sorry, couldn't think of a better title.
> >
> > I have this script intended to see if somebody is logged onto a remote
PC.
> > If so (under certain circumstances), I open up a reminder prompt on that
> PC.
> > I am using what I take to be a standard generic method, and it -did-
work.
> > Problem is that now, it shows that nobody is logged in, even when they
> are.
> > It works OK when I query my machine and the other machines in my office,
> but
> > not the remote machines. I am wondering if it involves some obscure
> network
> > setting or something.
> >
> > The guts of the routine are below.
> > =======================
> >
> > strComputer = "whs147"
> > On Error Resume Next
> >
> > Dim strUser
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
> > Set colComputer = objWMIService.ExecQuery _
> > ("Select * from Win32_ComputerSystem")
> >
> > strUser = "NA"
> > For Each objComputer in colComputer
> > If cstr(objComputer.UserName) <> "null" Then
> > strUser = cstr(objComputer.UserName)
> > End If
> > Next
> > If strUser <> "NA" Then
> > MsgBox "User logged on: " & strUser
> > Else
> > MsgBox "Nobody logged on"
> > End If
> >
> >
>
>



Re: Why does this fail sometimes? by Torgeir

Torgeir
Tue Jul 20 09:49:31 CDT 2004

Skip wrote:
> Sorry, couldn't think of a better title.
>
> I have this script intended to see if somebody is logged onto a remote PC.
> If so (under certain circumstances), I open up a reminder prompt on that PC.
> I am using what I take to be a standard generic method, and it -did- work.
> Problem is that now, it shows that nobody is logged in, even when they are.
> It works OK when I query my machine and the other machines in my office, but
> not the remote machines. I am wondering if it involves some obscure network
> setting or something.
>
> The guts of the routine are below.
> =======================
>
> strComputer = "whs147"
> On Error Resume Next
>
> Dim strUser
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set colComputer = objWMIService.ExecQuery _
> ("Select * from Win32_ComputerSystem")
>
> strUser = "NA"
> For Each objComputer in colComputer
> If cstr(objComputer.UserName) <> "null" Then
> strUser = cstr(objComputer.UserName)
> End If
> Next
> If strUser <> "NA" Then
> MsgBox "User logged on: " & strUser
> Else
> MsgBox "Nobody logged on"
> End If
Hi

Most likely because the user on the remote computer is
not a local admin (this is an known issue)...

--
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: Why does this fail sometimes? by Skip

Skip
Tue Jul 20 11:57:01 CDT 2004


"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:ekiIHkmbEHA.4092@TK2MSFTNGP10.phx.gbl...
> Skip wrote:
> > Sorry, couldn't think of a better title.
> >
> > I have this script intended to see if somebody is logged onto a remote
PC.
> > If so (under certain circumstances), I open up a reminder prompt on that
PC.
> > I am using what I take to be a standard generic method, and it -did-
work.
> > Problem is that now, it shows that nobody is logged in, even when they
are.
> > It works OK when I query my machine and the other machines in my office,
but
> > not the remote machines. I am wondering if it involves some obscure
network
> > setting or something.
> >
....snip...

>
> Most likely because the user on the remote computer is
> not a local admin (this is an known issue)...
>

Yeah, further experiments indicate this. It works if the remote PC has
somebody with higher access, but reports nobody logged in if a lower access
user is logged in.