Sign in to follow this  
Followers 0
Stasis22

Test when no-one is logged in.

5 posts in this topic

Hi There,

I am new to AutoIt and I did some research before posting but I couldn't find the answer.

When there is no user logged in, what does @UserName return?

I am trying to have a Windows Scheduled task at a specific time run a compiled shutdown script, but I don't want to shut down the computer if someone is still logged in.

I thought I would test the @UserName to see if someone was logged in, but what does that return when no-one is logged in?

Is that the best way (for a newbie) to achieve what I am trying to do? (im sure you could do some of the advanced stuff I have read about like having it running as a service or something like that, but I am trying to learn so want something simple)

I had something like:

$temp = @UserName
if ($temp = '') Then
    Shutdown(5)  ;Force a shutdown
Else
    ;do nothing as someone is still logged in.
EndIf

but that didn't work.

Thanks.

Share this post


Link to post
Share on other sites



Stasis22,

I think you'll find that if the pc is logged out then your script won't run at all.

It seems to me the answer would be to ask the user if it's ok to shutdown. You can use a timeout with MsgBox that will give them x seconds to respond. If they fail to respond then they're not there.

As another alternative google poweroff3. This is a great small prog that can run as a service and therefore run without a user logged in. You can set a schedule for each day of the week.

Regards,

4Eyes

Share this post


Link to post
Share on other sites

Run script as a service.

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

Thanks, I will check out poweroff3

I will investigate running the script as a service, but doesn't windows task scheduler run as a service so it can call other .exe's when it is triggered?

Does @UserName return anything when no-one is logged in?

Thanks.

Share this post


Link to post
Share on other sites

Thanks, I will check out poweroff3

I will investigate running the script as a service, but doesn't windows task scheduler run as a service so it can call other .exe's when it is triggered?

Does @UserName return anything when no-one is logged in?

Thanks.

When you execute a schedule or a service, there are always an user associated. so @username will return the user that is running the scheduler or service.

execute shutdown if the user is a system user, else stay logged in.

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

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