Sign in to follow this  
Followers 0
Guest wayneywoo

Detecting a logged on PC

7 posts in this topic

Hi all,

I've been scouring the net trying to find an answer to this and have drawn a blank so hopefully someone on here can point me in the right direction.

I need to detect if a PC is logged on to a network and then do something.

The something I've got sorted so I won't bore you with the details but what is happening is that whether a PC is logged on or not, the something is still happening.

I've tried using @LogonDomain to check if this equals the domain for the network that the PC should be logged on to and then if it does "equal" the domain in question then do the something but again, PC logged on or not, the something happens.

The something is a scheduled task. Is there a way to use SCHTASKS so that the task only runs if a PC is logged on to a network?

Thanks for the help!!

Share this post


Link to post
Share on other sites



Welcome to the forums!

Possibly a small syntax glitch? Could you please post your AutoIt code?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for the welcome LxP and hope to help others where I can!

Here's the first script that places the necessary scheduled task in to the scheduler:

RunWait("schtasks /create /tn TestLogon /tr ""C:\Windows\testlogon.exe"" /sc DAILY /st 21:58:30 /ru ""bellgas\zLocalAdmin"" /rp ""rtr3dnrd!""", "C:\Windows", @SW_HIDE)

Here's the code from the program testlogon.exe that actually tests to see if the PC is logged on?....

If @LogonDomain = "BELLGAS" Then

RunWait("schtasks /create /tn RebootNotification /tr ""c:\windows\blat.exe c:\windows\blatbody.txt -subject PC_Left_Logged_In -to SupportIT@coronaenergy.co.uk -server bell_appserver -f " & @ComputerName & """ /sc DAILY /st 21:59:00 /ru ""bellgas\zLocalAdmin"" /rp ""rtr3dnrd!""", "C:\Windows", @SW_HIDE)

EndIf

Thanks!

Edited by wayneywoo

Share this post


Link to post
Share on other sites

There doesn't appear to be a problem with the code itself. Have you tried switching the second RunWait() with a MsgBox() for debugging purposes?

Share this post


Link to post
Share on other sites

Yeah and I get BELLGAS appear.

Is there some other function in AutoIT that can be used to check if a PC is logged on?

I understand that scheduled tasks run regardless of a PC being logged on or not. That's my problem. I need to check, at the point the scheduled task runs, that the PC is logged on. I think my problem with the code above (testlogon.exe) is that @LogonDomain will equal BELLGAS whether the PC is logged on or not because the PC is already a member of the domain even though it's not logged on?....

Share this post


Link to post
Share on other sites

While $WantToDoAction
If ping("Bellgas") then
 ;do the action
WEND

(not tested)

J


If I am too verbose, just say so. You don't need to run on and on.

Share this post


Link to post
Share on other sites

I think the @logondomain relies on a registry entry which is set at the last logon and remains after logoff, so even if the PC is not logged on but just turned on that value will remain.

You could try using a mapped drive as your check, if that suits your enviroment.

Check "DriveMapGet", it could work


CheersNobby

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0