Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 05, 2016, 08:36:44 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: SOLVED: Log off & Standby in 1-Click  (Read 17638 times)

TheArt

  • Participant
  • Joined in 2011
  • *
  • Posts: 4
    • View Profile
    • Donate to Member
SOLVED: Log off & Standby in 1-Click
« on: October 27, 2011, 03:37:59 PM »
Hi all I've an idea: Create a something that makes your computer logging off and then puts it in standby mode.
In my situation this could be very convenient.
Currently to do that we have to do the following (win7): Start -> Click white arrow next to ShutDown button -> Click log off -> Wait to the main menu where all the accounts are displayed and click on the red arrow below right -> Finally click Standby.
I tried to do that creating two shortcuts on my desktop called LogOff and Sleep, and after creating a .bat file with this lines:

Quote
rundll32 shell32.dll,ShellExec_RunDLL "C:\Users\YOURNAME\Desktop\Logoff.lnk"
rundll32 shell32.dll,ShellExec_RunDLL "C:\Users\YOURNAME\Desktop\Sleep.lnk"

But as I supposed it executes only the first line, so this isn't the solution.

Thanks in advance  8)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,281
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #1 on: October 27, 2011, 06:43:46 PM »
Glad to see you made it over from Win7 Forums. :)

I suspect that as soon as you log out, there's no user with shutdown privilege. For that reason I suspect it would have to be written as a service. Since the API call uses 0 as the code for log off I'm wondering if that was done deliberately to prevent doing this.

But I don't know that for sure. I haven't written any services so perhaps someone with Windows Services experience can chime in if it's doable.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,474
    • View Profile
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #2 on: October 27, 2011, 07:59:46 PM »
You could try running the Sleep command as a Scheduled Task set to run after the user logs out.

That should run the Sleep command at the SYSTEM level - you might need to set this in the Task, (W7 you can set highest privilege).

If there isn't a specific trigger for user logoff, then look at the event log and find the specific event - you can then set that in the Task, (I do this to rerun programs that don't like being restored from Sleep/Hibernate).

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,281
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #3 on: October 27, 2011, 08:47:43 PM »
If it's set up that way won't it sleep on every logoff? Or can you tune it?

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,281
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #4 on: October 27, 2011, 09:32:36 PM »
I found this workaround:

http://www.vistax64....en-put-pc-sleep.html

Sleeps, then logs off when you restart.  Nice simple solution, if it does what you want. :)


4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,474
    • View Profile
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #5 on: October 27, 2011, 10:10:54 PM »
If it's set up that way won't it sleep on every logoff? Or can you tune it?

Yes and possibly.

You can set it to run after a period of idleness that will be aborted if any activity, (ie. no one logs in), but as to whether you can apply it to a single person or not will take a bit of experimentation.

BTW, the trigger event required is: System->Winlogon->7002

I found this workaround:

Nice find :)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,281
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #6 on: October 27, 2011, 10:36:45 PM »
Thanks for the additional info 4wd.   :Thmbsup:

magician62

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 118
    • View Profile
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #7 on: October 28, 2011, 11:14:10 AM »
Have you looked at Boot Snooze by our estemed moderator ? Boot Snooze Its a slightly different approach

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,778
    • View Profile
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #8 on: October 28, 2011, 02:01:22 PM »
Have you looked at Boot Snooze by our estemed moderator ? Boot Snooze Its a slightly different approach

That's why you're magician :Thmbsup: (at least for today ;D)

I was searching for this to suggest as the solution, but couldn't remember the name. :-[

TheArt

  • Participant
  • Joined in 2011
  • *
  • Posts: 4
    • View Profile
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #9 on: October 28, 2011, 02:04:51 PM »
Have you looked at Boot Snooze by our estemed moderator ? Boot Snooze Its a slightly different approach

Yes I've already seen that program but I don't want to reboot my computer. If only in that program the button "Restart then Standby" was substituted by "Log off then Standby" !  :D

Anyway is my request possible with Task Scheduler? I'm not a guru on using computer  :-[

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,281
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #10 on: October 28, 2011, 03:50:59 PM »
The 2 approaches would be, Task Scheduler, or writing a program and using a utility that runs it as a service.

I would ask on this thread:

http://www.autoitscr...rvice__fromsearch__1

The library is already there to install a compiled AutoIt3 as a service. Basically the service would be running and waiting for notification by a client that it should perform the log off and sleep.  The author of the function may help you since the service would just have to do that in addition to the required service functions such as Start, Stop etc..

To write a program I need to be able to test it.  But I never put my machines into sleep or hibernate. Certain system settings I won't change for testing scripts.

If the author's Run As Service function really works then your request should serve(pun intended) as an easy example program.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,281
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #11 on: October 28, 2011, 05:07:50 PM »
btw 4wd's approach is likely the quick way to accomplish what you want. Having a mechanism to do similar things may be a reason to try the Run As Service approach.

I think I hosed Task Scheduler on my PCs when I was killing off a whole bunch of MS info gathering that I didn't want.  Windows 7 seemed to work for a while with a Calendar program, but after a bit it kept complaining something or other was corrupted(probably means the MS stuff is killed off. If I won't run theirs, they won't run mine.) :)

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,778
    • View Profile
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #12 on: October 28, 2011, 05:32:02 PM »
Certain system settings I won't change for testing scripts.
That's what a virtual test-system is good for :)

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,474
    • View Profile
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #13 on: October 28, 2011, 05:54:25 PM »
The library is already there to install a compiled AutoIt3 as a service. Basically the service would be running and waiting for notification by a client that it should perform the log off and sleep.

Having already tried to get a service working in AutoIt, (see this thread), and having no luck with notification after a user logs off - I wouldn't hold your breath  ;)

Admittedly I didn't ask in that thread specifically but there was enough information throughout the entire forum for me to try pretty much every way I could - AutoIt is not geared towards running when no user is logged in.

I'll have a look at a Scheduled Task but it won't be this weekend - long weekend - I'm going bush :D

ADDENDUM: OK, took 5 minutes so I've got it working. :)

@TheArt: Sorry if I'm quick, I'm expecting pick up soon, someone might be able to fill in any blanks you have over the next 3-4 days.

Prerequisites: Password on the user account, you might also need the power button set to put the system to Sleep rather than Off.

1) Open Task Scheduler and select Create Task (right side of window).
2) Give the task a name, set to run whether user is logged on or not, run with highest privileges - you'll need to enter your account password before leaving this page.

2011-10-29_10-03-07.jpg

3) Edit the Trigger as follows:
2011-10-29_10-03-15.jpg

4) Create an Action as follows:
2011-10-29_10-03-33.jpg
The complete arguments line is: powrprof.dll,SetSuspendState

5) Set the Conditions as follows:
2011-10-29_10-03-43.jpg

6) OK out of all the windows, you Task should now be listed in the Task Scheduler window.

To test it:
1) Log off :)

If all goes well, 30 seconds after logging off the computer should go to sleep.

BTW, if you don't want to have it do it all the time then under the Conditions tab you might try setting Computer Idle timeouts and to stop it if it ceases to be idle.
« Last Edit: October 28, 2011, 06:20:45 PM by 4wd »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,281
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #14 on: October 29, 2011, 12:59:51 AM »
I think the hurdle is just getting a batch or program to run as System.

You can experiment with schtasks.exe to see if you can create a task that's just a .cmd file with commands to log off, then go into standby.  If that approach won't work you can do the logoff trigger.  But using schtasks you should be able to run the task on demand.

See these pages and try it if you like:

http://msdn.microsof...736357(v=VS.85).aspx

http://technet.micro...ibrary/cc748879.aspx

http://technet.micro...ibrary/cc766529.aspx

http://technet.micro...ibrary/cc721884.aspx


MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,281
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #15 on: October 29, 2011, 01:15:34 AM »
At this point the simplest method would be to use 4wd's task as he set it up.  Use schtasks.exe in a .cmd to /DISABLE it and put a shortcut to that batch in All Users StartUp folder. (usually C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup.)

In your "IWantToLogOffAndStandby" batch, just enable the task using the /ENABLE parameter, then log off.  The log off should trigger the task to go into standby.  When you log in, the task gets hit with /DISABLE.

That way it only goes into Standby when you log off via the special batch. The Standby task is disabled at logon no matter who logs in if you have the shortcut in All Users Startup. Pin the "IWantToLogOffAndStandby" shortcut to TaskBar or use something like Standalone Stacks 2 to have it accessible.





« Last Edit: October 29, 2011, 01:25:29 AM by MilesAhead »

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,778
    • View Profile
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #16 on: October 29, 2011, 04:44:23 AM »
OK, took 5 minutes so I've got it working. :)
Kudo's, 4wd :Thmbsup:

I'll be testing this later today, looks like fun 8)

TheArt

  • Participant
  • Joined in 2011
  • *
  • Posts: 4
    • View Profile
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #17 on: October 29, 2011, 01:07:57 PM »
@4wd Thanks man you've almost done what I want!
But there are two little problems:

1) I've done anything you had shown me in Task Scheduler but when I log off, after 30sec it HIBERNATES. I tried to disable hybernation but it didn't helped.

2) I noticed that if I log off from my account and my brother wants to use his one immediately, he logs on but the task isn't stopped and so it hibernates. I guess that must be added something like that: "Disable the task when a LogOn is performed".
Unfortunately I don't know how to do it.

Anyway you found a way to do the Logoff&Standby without any program which is made by someone!

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,281
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #18 on: October 29, 2011, 01:39:03 PM »
Here's the command to put in All Users Startup folder

(change "test" to whatever you named the task)

You can make a batch to run commands with any text editor.
Save the file as Command.cmd with "Command" as whatever you want to name it.  Example: save the line below as file DisableStandby.cmd

schtasks /Change /TN "test" /DISABLE

Put a shortcut to it in the All Users Startup folder(see my post above for location.)

Make a .cmd file LogoffAndStandby.cmd
with these 2 lines:


schtasks /Change /TN "test" /ENABLE
shutdown /l /t 10

Make a shortcut to it that you can double click to logoff and standby in one shot.


MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,281
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #19 on: October 29, 2011, 01:44:34 PM »
This link may also be of interest:

http://hardforum.com...thread.php?t=1538805

TheArt

  • Participant
  • Joined in 2011
  • *
  • Posts: 4
    • View Profile
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #20 on: October 30, 2011, 06:26:35 AM »
Yes! Now all is working fine! Thanks you MilesAhead and 4wd  ;D

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,281
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #21 on: October 30, 2011, 02:05:24 PM »
Cool. Glad you got it to work.
Thanks 4wd for the scheduled task set up.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,474
    • View Profile
    • Donate to Member
Re: SOLVED: Log off & Standby in 1-Click
« Reply #22 on: October 31, 2011, 04:29:04 AM »
Back again - ah yes, I forgot the Hibernate thing since I disabled that ages ago.

Re. the cancelling of the Task when someone logs on within the 30 second timeout, that's why I mentioned the following:

BTW, if you don't want to have it do it all the time then under the Conditions tab you might try setting Computer Idle timeouts and to stop it if it ceases to be idle.

Set the Task to run after the computer had been idle for x and cancel it if someone causes activity, eg. logs on.  Setting an idle timeout here probably means you should remove the 30 second timeout under the Trigger tab.

But anyway, glad it all worked out for you  :D
« Last Edit: October 31, 2011, 04:34:33 AM by 4wd »