Jump to content

Detecting a logged on PC


Guest wayneywoo
 Share

Recommended Posts

Guest wayneywoo

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!!

Link to comment
Share on other sites

Guest wayneywoo

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
Link to comment
Share on other sites

Guest wayneywoo

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?....

Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...