If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Rate Thread | Display Modes |
#1
|
|||
|
|||
Run batch like a Screensaver
I need to run a batch in place of a screensaver and find that the Task
Scheduler trigger settings for "When computer is idle" is incomprehensible no matter how much research I have done. The need is to have the batch initiate some actions on a time basis before locking the PC and disconnecting the LAN which both a screensaver and LockWorkStation do. There is no UnLockWorkStation command available. I hope someone can help with the various Task Scheduler settings or direct me to a simple online site that can. |
Ads |
#2
|
|||
|
|||
Run batch like a Screensaver
Zaidy036 wrote:
have the batch initiate some actions on a time basis before locking the PC and disconnecting the LAN which both a screensaver and LockWorkStation do. You can lock the workstation using a command inside a batch file. The batch file would have to run with elevated privileges. .bat files require interpretation by the command-line interpreter (cmd.exe) aka shell. Since LockWorkStation locks the current Windows account, it works with your account's permissions, and does not require elevated privileges. In the .bat file, add the following with any other commands: other commands C:\WINDOWS\system32\rundll32.exe user32.dll,LockWorkStation If you put any commands after that one, you won't see them run, and I'm not sure the .bat file will pend until you get around to unlocking the workstation. That takes care of a batch file locking the workstation. In Task Scheduler, create a new event that runs: cmd.exe /c yourbatfile If that doesn't work, check if enabling the "Run with highest privileges" option in the event allows rundll32.exe to successfully call the LockWorkStation method in the user32.dll library. However, you don't need a batch file to lock the workstation at a partiticular time, when the computer goes idle, or whatever event trigger you choose. Instead of the scheduled event calling cmd.exe to interpret the .bat file, why not just have the scheduled event directly run the rundll32.exe program? The scheduled event would simply have: C:\WINDOWS\system32\rundll32.exe user32.dll,LockWorkStation as its action (the command it runs). I don't know why you think you need to use a batch file to run the rundll32.exe program unless you omitted that you have other commands you want to run before the lock. Just be careful when defining a scheduled event's action. To define it, you specify the program to run and any parameters to give it. The above command line has both a program AND a parameter specified. So, in the event, you would define its Program/Script it runs as: C:\WINDOWS\system32\rundll32.exe and its arguments as: user32.dll,LockWorkStation No double-quoting is needed for the command (in a .bat file or as the command) because there are no space characters in the command nor in the argument. To trigger the scheduled event when the computer goes idle (there's not setting for how long to be idling, but see a bit later), create a new scheduled event or edit one, and for its trigger, select "When computer is idle" for the "Begin the task" selection. The trigger event doesn't let you specify how long to be idling before running the event's command. Go under the Conditions tab, and there is a "Start the task only if the computer is idle for" setting. So, you could have the scheduled event run immediately when the computer goes idle (yeah, try finding a definition of that detection), or you could trigger the scheduled event when the computer goes idle and has been idle from some minimum number of minutes (the list is fixed for timeout selections). If you enable the "Start the task only if the computer is idle" option, and since you're doing a one-way action (locking the workstation), you'll want to disable the sub-option "Stop if the computer ceases to be idle". You want the computer to stayed locked until YOU decide to unlock it, not because something started in the background that ceased the computer being idle. This option might be superfluous since after starting the .bat or rundll32 command, it won't still be running to be stopped later. |
#3
|
|||
|
|||
Run batch like a Screensaver
On 7/9/2020 11:20 PM, VanguardLH wrote:
Zaidy036 wrote: have the batch initiate some actions on a time basis before locking the PC and disconnecting the LAN which both a screensaver and LockWorkStation do. You can lock the workstation using a command inside a batch file. The batch file would have to run with elevated privileges. .bat files require interpretation by the command-line interpreter (cmd.exe) aka shell. Since LockWorkStation locks the current Windows account, it works with your account's permissions, and does not require elevated privileges. In the .bat file, add the following with any other commands: other commands C:\WINDOWS\system32\rundll32.exe user32.dll,LockWorkStation If you put any commands after that one, you won't see them run, and I'm not sure the .bat file will pend until you get around to unlocking the workstation. That takes care of a batch file locking the workstation. In Task Scheduler, create a new event that runs: cmd.exe /c yourbatfile If that doesn't work, check if enabling the "Run with highest privileges" option in the event allows rundll32.exe to successfully call the LockWorkStation method in the user32.dll library. However, you don't need a batch file to lock the workstation at a partiticular time, when the computer goes idle, or whatever event trigger you choose. Instead of the scheduled event calling cmd.exe to interpret the .bat file, why not just have the scheduled event directly run the rundll32.exe program? The scheduled event would simply have: C:\WINDOWS\system32\rundll32.exe user32.dll,LockWorkStation as its action (the command it runs). I don't know why you think you need to use a batch file to run the rundll32.exe program unless you omitted that you have other commands you want to run before the lock. Just be careful when defining a scheduled event's action. To define it, you specify the program to run and any parameters to give it. The above command line has both a program AND a parameter specified. So, in the event, you would define its Program/Script it runs as: C:\WINDOWS\system32\rundll32.exe and its arguments as: user32.dll,LockWorkStation No double-quoting is needed for the command (in a .bat file or as the command) because there are no space characters in the command nor in the argument. To trigger the scheduled event when the computer goes idle (there's not setting for how long to be idling, but see a bit later), create a new scheduled event or edit one, and for its trigger, select "When computer is idle" for the "Begin the task" selection. The trigger event doesn't let you specify how long to be idling before running the event's command. Go under the Conditions tab, and there is a "Start the task only if the computer is idle for" setting. So, you could have the scheduled event run immediately when the computer goes idle (yeah, try finding a definition of that detection), or you could trigger the scheduled event when the computer goes idle and has been idle from some minimum number of minutes (the list is fixed for timeout selections). If you enable the "Start the task only if the computer is idle" option, and since you're doing a one-way action (locking the workstation), you'll want to disable the sub-option "Stop if the computer ceases to be idle". You want the computer to stayed locked until YOU decide to unlock it, not because something started in the background that ceased the computer being idle. This option might be superfluous since after starting the .bat or rundll32 command, it won't still be running to be stopped later. I appreciate your effort above but maybe I was not clear in what I am trying to do. I want to run a batch after the computer is idle for a selected amount of time. I would use the batch to make a selection of what to do next. This is similar to the action of running a screensaver but would not lock the work station or run a screensaver unless the batch made that choice in its command logic. I need the batch because there is no UnLockWorkStation command in User32.dll and LockWorkStation and all screensavers also lock my LAN so I cannot access my NAS using my unattended overnight batch. I am not on a domain so I cannot use the policy editor to overcome this limitation. See: |
#4
|
|||
|
|||
Run batch like a Screensaver
Zaidy036 wrote:
[...] I appreciate your effort above but maybe I was not clear in what I am trying to do. I want to run a batch after the computer is idle for a selected amount of time. I would use the batch to make a selection of what to do next. This is similar to the action of running a screensaver but would not lock the work station or run a screensaver unless the batch made that choice in its command logic. I need the batch because there is no UnLockWorkStation command in User32.dll and LockWorkStation and all screensavers also lock my LAN so I cannot access my NAS using my unattended overnight batch. I am not on a domain so I cannot use the policy editor to overcome this limitation. See: Running a task after the computer is idle for a selected amount of time is a setting on the 'Conditions' tab of a Task Scheduler task. IMO opinion, you've still not explained - also not in the previous thread - why you 'need' a screensaver instead of just letting the display blank ('turn off') after a timeout. You said you couldn't see the messages from the batch after unblanking the display, but that hasn't been a problem for decades, so I still don't see what the/your *actual* problem is. So: - Can you run a task after the computer is idle for a selected amount of time? Yes or no? If no, why not? - Can you blank ('Turn off display after ... minutes') the display? Yes or no? If no, why not? - Can you read the messages from the batch after unblanking the display? Yes or no? If no, why not? - Why do you - think - you need a screensaver (instead of just turning off the display after ... minutes)? |
#5
|
|||
|
|||
Run batch like a Screensaver
Zaidy036 wrote:
On 7/9/2020 11:20 PM, VanguardLH wrote: Zaidy036 wrote: have the batch initiate some actions on a time basis before locking the PC and disconnecting the LAN which both a screensaver and LockWorkStation do. You can lock the workstation using a command inside a batch file. The batch file would have to run with elevated privileges. .bat files require interpretation by the command-line interpreter (cmd.exe) aka shell. Since LockWorkStation locks the current Windows account, it works with your account's permissions, and does not require elevated privileges. In the .bat file, add the following with any other commands: other commands C:\WINDOWS\system32\rundll32.exe user32.dll,LockWorkStation If you put any commands after that one, you won't see them run, and I'm not sure the .bat file will pend until you get around to unlocking the workstation. That takes care of a batch file locking the workstation. In Task Scheduler, create a new event that runs: cmd.exe /c yourbatfile If that doesn't work, check if enabling the "Run with highest privileges" option in the event allows rundll32.exe to successfully call the LockWorkStation method in the user32.dll library. However, you don't need a batch file to lock the workstation at a partiticular time, when the computer goes idle, or whatever event trigger you choose. Instead of the scheduled event calling cmd.exe to interpret the .bat file, why not just have the scheduled event directly run the rundll32.exe program? The scheduled event would simply have: C:\WINDOWS\system32\rundll32.exe user32.dll,LockWorkStation as its action (the command it runs). I don't know why you think you need to use a batch file to run the rundll32.exe program unless you omitted that you have other commands you want to run before the lock. Just be careful when defining a scheduled event's action. To define it, you specify the program to run and any parameters to give it. The above command line has both a program AND a parameter specified. So, in the event, you would define its Program/Script it runs as: C:\WINDOWS\system32\rundll32.exe and its arguments as: user32.dll,LockWorkStation No double-quoting is needed for the command (in a .bat file or as the command) because there are no space characters in the command nor in the argument. To trigger the scheduled event when the computer goes idle (there's not setting for how long to be idling, but see a bit later), create a new scheduled event or edit one, and for its trigger, select "When computer is idle" for the "Begin the task" selection. The trigger event doesn't let you specify how long to be idling before running the event's command. Go under the Conditions tab, and there is a "Start the task only if the computer is idle for" setting. So, you could have the scheduled event run immediately when the computer goes idle (yeah, try finding a definition of that detection), or you could trigger the scheduled event when the computer goes idle and has been idle from some minimum number of minutes (the list is fixed for timeout selections). If you enable the "Start the task only if the computer is idle" option, and since you're doing a one-way action (locking the workstation), you'll want to disable the sub-option "Stop if the computer ceases to be idle". You want the computer to stayed locked until YOU decide to unlock it, not because something started in the background that ceased the computer being idle. This option might be superfluous since after starting the .bat or rundll32 command, it won't still be running to be stopped later. I appreciate your effort above but maybe I was not clear in what I am trying to do. I want to run a batch after the computer is idle for a selected amount of time. Scheduled event triggers on computer going idle but with condition that the event not run until the computer had been idle for awhile. I would use the batch to make a selection of what to do next. This is similar to the action of running a screensaver but would not lock the work station or run a screensaver unless the batch made that choice in its command logic. The rundll32.exe program gets run in the batch script based on what you code in the script. I need the batch because there is no UnLockWorkStation command in User32.dll and LockWorkStation and all screensavers also lock my LAN so I cannot access my NAS using my unattended overnight batch. So, the problem is the computer is getting locked before the scheduled time to run your batch script? There's an option in the scheduled event for its Conditions to wake the computer, so the action for the event can get performed. Most of my user-defined scheduled events have the "Wake computer" option enabled to ensure they can run at the scheduled time. I am not on a domain so I cannot use the policy editor to overcome this limitation. See: All policies are registry entries. Anyone using regedit.exe can define the policies. The problem is knowing where are the registry entries, and to what you set them. Microsoft provides a spreadsheet of policy settings and their registry entries, at: https://www.microsoft.com/en-us/down....aspx?id=56946 https://www.microsoft.com/en-us/down....aspx?id=25250 The only registry entries you cannot enter using regedit.exe are those that have a hash generated for them. For example, some Software Restriction Policies (SRPs) are hashed, and you can't create the hash. |
#6
|
|||
|
|||
Run batch like a Screensaver
On 7/10/2020 4:08 PM, VanguardLH wrote:
Zaidy036 wrote: On 7/9/2020 11:20 PM, VanguardLH wrote: Zaidy036 wrote: have the batch initiate some actions on a time basis before locking the PC and disconnecting the LAN which both a screensaver and LockWorkStation do. You can lock the workstation using a command inside a batch file. The batch file would have to run with elevated privileges. .bat files require interpretation by the command-line interpreter (cmd.exe) aka shell. Since LockWorkStation locks the current Windows account, it works with your account's permissions, and does not require elevated privileges. In the .bat file, add the following with any other commands: other commands C:\WINDOWS\system32\rundll32.exe user32.dll,LockWorkStation If you put any commands after that one, you won't see them run, and I'm not sure the .bat file will pend until you get around to unlocking the workstation. That takes care of a batch file locking the workstation. In Task Scheduler, create a new event that runs: cmd.exe /c yourbatfile If that doesn't work, check if enabling the "Run with highest privileges" option in the event allows rundll32.exe to successfully call the LockWorkStation method in the user32.dll library. However, you don't need a batch file to lock the workstation at a partiticular time, when the computer goes idle, or whatever event trigger you choose. Instead of the scheduled event calling cmd.exe to interpret the .bat file, why not just have the scheduled event directly run the rundll32.exe program? The scheduled event would simply have: C:\WINDOWS\system32\rundll32.exe user32.dll,LockWorkStation as its action (the command it runs). I don't know why you think you need to use a batch file to run the rundll32.exe program unless you omitted that you have other commands you want to run before the lock. Just be careful when defining a scheduled event's action. To define it, you specify the program to run and any parameters to give it. The above command line has both a program AND a parameter specified. So, in the event, you would define its Program/Script it runs as: C:\WINDOWS\system32\rundll32.exe and its arguments as: user32.dll,LockWorkStation No double-quoting is needed for the command (in a .bat file or as the command) because there are no space characters in the command nor in the argument. To trigger the scheduled event when the computer goes idle (there's not setting for how long to be idling, but see a bit later), create a new scheduled event or edit one, and for its trigger, select "When computer is idle" for the "Begin the task" selection. The trigger event doesn't let you specify how long to be idling before running the event's command. Go under the Conditions tab, and there is a "Start the task only if the computer is idle for" setting. So, you could have the scheduled event run immediately when the computer goes idle (yeah, try finding a definition of that detection), or you could trigger the scheduled event when the computer goes idle and has been idle from some minimum number of minutes (the list is fixed for timeout selections). If you enable the "Start the task only if the computer is idle" option, and since you're doing a one-way action (locking the workstation), you'll want to disable the sub-option "Stop if the computer ceases to be idle". You want the computer to stayed locked until YOU decide to unlock it, not because something started in the background that ceased the computer being idle. This option might be superfluous since after starting the .bat or rundll32 command, it won't still be running to be stopped later. I appreciate your effort above but maybe I was not clear in what I am trying to do. I want to run a batch after the computer is idle for a selected amount of time. Scheduled event triggers on computer going idle but with condition that the event not run until the computer had been idle for awhile. I would use the batch to make a selection of what to do next. This is similar to the action of running a screensaver but would not lock the work station or run a screensaver unless the batch made that choice in its command logic. The rundll32.exe program gets run in the batch script based on what you code in the script. I need the batch because there is no UnLockWorkStation command in User32.dll and LockWorkStation and all screensavers also lock my LAN so I cannot access my NAS using my unattended overnight batch. So, the problem is the computer is getting locked before the scheduled time to run your batch script? There's an option in the scheduled event for its Conditions to wake the computer, so the action for the event can get performed. Most of my user-defined scheduled events have the "Wake computer" option enabled to ensure they can run at the scheduled time. I am not on a domain so I cannot use the policy editor to overcome this limitation. See: All policies are registry entries. Anyone using regedit.exe can define the policies. The problem is knowing where are the registry entries, and to what you set them. Microsoft provides a spreadsheet of policy settings and their registry entries, at: https://www.microsoft.com/en-us/down....aspx?id=56946 https://www.microsoft.com/en-us/down....aspx?id=25250 The only registry entries you cannot enter using regedit.exe are those that have a hash generated for them. For example, some Software Restriction Policies (SRPs) are hashed, and you can't create the hash. My experience is that screensavers and LockWorkstation cause a LAN disconnect so that when either is active one cannot run batch commands successfully if they include reading or writing to an NAS. My batch includes making copies of files and folders to my NAS using RoboCopy and also writes images to the NAS using Acronis. I have now found a solution using the temporary unlock feature of PTFBpro, an advanced "button pusher". PTFB is capable of unlocking the workstation and once a read or write starts then Window's holds the "pipe" open until completion. There is no visible screen indication that an unlock is in effect and I expect that security (login password) is maintained at all times. |
#7
|
|||
|
|||
Run batch like a Screensaver
Zaidy036 wrote:
My experience is that screensavers and LockWorkstation cause a LAN disconnect so that when either is active one cannot run batch commands successfully if they include reading or writing to an NAS. My batch includes making copies of files and folders to my NAS using RoboCopy and also writes images to the NAS using Acronis. I have now found a solution using the temporary unlock feature of PTFBpro, an advanced "button pusher". PTFB is capable of unlocking the workstation and once a read or write starts then Window's holds the "pipe" open until completion. There is no visible screen indication that an unlock is in effect and I expect that security (login password) is maintained at all times. That's why I mentioned the "wake computer" option for a scheduled event. Many backup programs can not only save an image file to an internal or external drive, but also save a copy using FTP to some other host. If networking were disabled, the backup program couldn't use FTP. Every backup program that I've used that uses Task Scheduler (instead of their own backgrounded scheduler process) enables the "wake computer" option. Some download managers can retrieve files on a schedule, and they, too, would need a working network connection when they ran on a schedule. In Windows, you need to ensure the wake timers are enabled. Control Panel - Hardware and Sound - Power Options, scroll down to Sleep, expand Allow wake timers, make sure they are enabled. But how will you ensure the /other/ host is awake, so it has network connectivity? Have you disabled all sleep, hibernate, screen saver, or lock workstation settings over there? Have you gone into its BIOS/UEFI power management settings to ensure "Wake on LAN" is enabled? I don't remember LockWorkstation disabling the NIC (network interface controller). Its description only mentions locking the display to protect from accidental or unauthorized use. Not even the mouse or keyboard are locked, because those are used to awaken and allow password input. More likely your NIC driver or software is not enabled for "Wake on LAN". Go into Device Manager (devmgmt.msc), open the Network Adapter tree node, double-click your NIC to see its properties, and go under the Advanced tab. Scroll down to see if "Wake on Magic Packet" is enabled. The "Wake computer" option for the scheduled event on your computer should allow the action for that event to run. You need the BIOS on the other computer to have "Wake on LAN" enabled, and ensure the other computer's NIC is configured for "Wake on Magic Packet". In addition, as insurance on the computer where the scheduled event will run, go into the NIC's properties, Power Management tab, and disable the "Allow the computer to turn off this device to save power". I have encountered some poorly coded NIC drivers that would not reset the NIC on resuming out of low-power mode to ensure the NIC was in a known or initial state. Not being initialized means the device or driver may not know how to accept further operational requests. A NIC that doesn't initialize upon wake up is a ****ed device or driver, and not the fault of the OS. The OS can only issue a reset on all devices, not force them to initialize. When you boot Windows, that flash of the keyboard LEDs indicates when a reset was sent to all devices to initialize them to a known state. The device or driver might not honor the reset request. I've seen DSP modems that wouldn't reset on a wake, so dial-up failed thereafter until you rebooted the computer (which makes the CPU send a reset). |
#8
|
|||
|
|||
Run batch like a Screensaver
On 7/13/2020 7:09 PM, VanguardLH wrote:
Zaidy036 wrote: My experience is that screensavers and LockWorkstation cause a LAN disconnect so that when either is active one cannot run batch commands successfully if they include reading or writing to an NAS. My batch includes making copies of files and folders to my NAS using RoboCopy and also writes images to the NAS using Acronis. I have now found a solution using the temporary unlock feature of PTFBpro, an advanced "button pusher". PTFB is capable of unlocking the workstation and once a read or write starts then Window's holds the "pipe" open until completion. There is no visible screen indication that an unlock is in effect and I expect that security (login password) is maintained at all times. That's why I mentioned the "wake computer" option for a scheduled event. Many backup programs can not only save an image file to an internal or external drive, but also save a copy using FTP to some other host. If networking were disabled, the backup program couldn't use FTP. Every backup program that I've used that uses Task Scheduler (instead of their own backgrounded scheduler process) enables the "wake computer" option. Some download managers can retrieve files on a schedule, and they, too, would need a working network connection when they ran on a schedule. In Windows, you need to ensure the wake timers are enabled. Control Panel - Hardware and Sound - Power Options, scroll down to Sleep, expand Allow wake timers, make sure they are enabled. But how will you ensure the /other/ host is awake, so it has network connectivity? Have you disabled all sleep, hibernate, screen saver, or lock workstation settings over there? Have you gone into its BIOS/UEFI power management settings to ensure "Wake on LAN" is enabled? I don't remember LockWorkstation disabling the NIC (network interface controller). Its description only mentions locking the display to protect from accidental or unauthorized use. Not even the mouse or keyboard are locked, because those are used to awaken and allow password input. More likely your NIC driver or software is not enabled for "Wake on LAN". Go into Device Manager (devmgmt.msc), open the Network Adapter tree node, double-click your NIC to see its properties, and go under the Advanced tab. Scroll down to see if "Wake on Magic Packet" is enabled. The "Wake computer" option for the scheduled event on your computer should allow the action for that event to run. You need the BIOS on the other computer to have "Wake on LAN" enabled, and ensure the other computer's NIC is configured for "Wake on Magic Packet". In addition, as insurance on the computer where the scheduled event will run, go into the NIC's properties, Power Management tab, and disable the "Allow the computer to turn off this device to save power". I have encountered some poorly coded NIC drivers that would not reset the NIC on resuming out of low-power mode to ensure the NIC was in a known or initial state. Not being initialized means the device or driver may not know how to accept further operational requests. A NIC that doesn't initialize upon wake up is a ****ed device or driver, and not the fault of the OS. The OS can only issue a reset on all devices, not force them to initialize. When you boot Windows, that flash of the keyboard LEDs indicates when a reset was sent to all devices to initialize them to a known state. The device or driver might not honor the reset request. I've seen DSP modems that wouldn't reset on a wake, so dial-up failed thereafter until you rebooted the computer (which makes the CPU send a reset). I investigated everything, and even more, that you mentioned before asking in this newsgroup. I have been looking for alternatives and thought a batch might work. All the settings are as you describe and I have also installed and set to eliminate the extra hidden sleep that MS does not announce. https://appuals.com/windows-10-sleeps-after-1-4-minutes-of-inactivity/. I just think the FTP and other programs are unlocking in the background just like PTFBpro does. |
Thread Tools | |
Display Modes | Rate This Thread |
|
|