我们公司的BOFH设置屏幕锁定设置的时间短得离谱。这令人沮丧并且适得其反。
有没有办法防止屏幕自动锁定?我认为无法覆盖策略强制设置,但是也许有一种模仿用户活动的软件。
在设置永久鼠标滚轮之前,只问一下。(得到它?)
我们公司的BOFH设置屏幕锁定设置的时间短得离谱。这令人沮丧并且适得其反。
有没有办法防止屏幕自动锁定?我认为无法覆盖策略强制设置,但是也许有一种模仿用户活动的软件。
在设置永久鼠标滚轮之前,只问一下。(得到它?)
Answers:
我使用标题为idle.vbs的脚本:
Dim objResult
Set objShell = WScript.CreateObject("WScript.Shell")
Do While True
objResult = objShell.sendkeys("{NUMLOCK}{NUMLOCK}")
Wscript.Sleep (6000)
Loop
每六秒钟,此操作会快速切换键盘上的数字锁定,使Windows认为有人正在与键盘进行交互,从而防止屏幕锁定。它可以在普通窗口上运行,您不需要开发或脚本工具即可使用它,只需创建一个扩展名为.vbs的文本文件,然后双击它(或将其放在启动项中)即可。
编辑:您可以使用以下命令将此脚本放入启动项中
choco install IdleVbs -source https://www.myget.org/F/joshrivers-utility/
有关Choclatey(choco
)CLI安装程序的更多信息,请参见:
shell:startup
。看到这个网站获取更多信息thewindowsclub.com/startup-folder-in-windows-8
如果仍安装Windows Media Player,则可以循环播放视频并将其最小化(示例“ Wildlife”视频可以正常工作)。默认情况下,只要播放视频,屏幕就不会锁定。
另一个选择是免费软件Caffeine程序。它也免费用于商业用途。从程序的主页:
如果您的PC锁定或睡眠有问题,咖啡因将使它保持清醒状态。它每59秒模拟一次按键来工作,因此您的机器认为您仍在使用键盘,因此不会锁定屏幕或激活屏幕保护程序。
咖啡因的工作原理是每59秒模拟一次F15键启动事件。在所有可用的按键中,F15可能是侵入性最低的(我从未见过使用该按键的PC键盘!),并且极不可能干扰您的工作。
这种现成的解决方案还允许您控制何时启用和禁用它:
双击程序图标将清空咖啡壶(该图标代表该图标),并暂时禁用该程序。再次双击它会重新装满锅,这将使您的机器保持清醒状态。
您可以创建一个AutoIt脚本来连续按下一个未使用的键(例如,使其切换数字锁定,滚动锁定),睡眠一分钟左右然后重复。另外,如果您经常使用键盘,则可以使其沿任意方向移动鼠标一个像素左右。
如果您不希望它继续运行,也可以将脚本作为计划任务启动(如果有访问权限),以便在计算机不活动一段时间后启动。
如果您不想使用AutoIt语法,这是执行隐形鼠标移动的非常简单的脚本:
While True
Local $pos = MouseGetPos()
MouseMove($pos[0]-1, $pos[1]-1, 0)
MouseMove($pos[0], $pos[1], 0)
Sleep(540000)
WEnd
该脚本在左上方将鼠标光标移动一个像素,然后将其返回,然后休眠9分钟(540000
毫秒)。运行脚本时,您可以在托盘中看到AutoIt图标。您可以右键单击此图标并选择相应的选项来停止它。
要制作脚本,请安装AutoIt,右键单击任何文件夹并选择New
> AutoIt v3 Script
,命名,右键单击此新脚本,选择Edit
,粘贴上面提供的代码并保存。您甚至可以将其编译为.exe
(再次从上下文菜单中)以例如从Windows Scheduler启动。
在Visual Studio或C#Express中进行编译,然后从命令提示符下运行它(或双击它)。需要.NET 4.0或更高版本。它可以满足您的所有需求。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace ImWorkin
{
class Program
{
[FlagsAttribute]
public enum EXECUTION_STATE : uint
{
ES_SYSTEM_REQUIRED = 0x00000001,
ES_DISPLAY_REQUIRED = 0x00000002,
ES_CONTINUOUS = 0x80000000
}
public SYSTEMTIMEOUTS TimeOuts
{
get { return sysTimeouts; }
}
public struct SYSTEMTIMEOUTS
{
public int BATTERYIDLETIMEOUT;
public int EXTERNALIDLETIMEOUT;
public int WAKEUPIDLETIMEOUT;
}
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE flags);
[DllImport("user32.dll", SetLastError = true, EntryPoint ="SystemParametersInfo")]
internal static extern int SystemParametersInfo(int uiAction, int uiParam, ref int pvParam, int fWinIni);
private static System.Threading.Timer preventSleepTimer = null;
public const int SPI_GETBATTERYIDLETIMEOUT = 252;
public const int SPI_GETEXTERNALIDLETIMEOUT = 254;
public const int SPI_GETWAKEUPIDLETIMEOUT = 256;
public static int Counter = 0;
public static int timeOutinMS = 0;
public static int batteryIdleTimer;
public static int externalIdleTimer;
public static int wakeupIdleTimer;
public static SYSTEMTIMEOUTS sysTimeouts;
static void Main(string[] args)
{
Console.WriteLine("You are about to be workin!! Just a moment...I need to calculate a few values.");
string dots = string.Empty;
for (int i =2; i < 60; i++)
{
dots = "";
for (int ii = 0; ii < i; ii++)
{
dots = dots + ".";
}
Thread.Sleep(100);
Console.Clear();
Console.WriteLine("You are about to be workin!! Just a moment...I need to calculate a few values.");
Console.WriteLine(dots);
}
GetSystemTimeOuts();
if (timeOutinMS < sysTimeouts.BATTERYIDLETIMEOUT)
timeOutinMS = sysTimeouts.BATTERYIDLETIMEOUT;
if (timeOutinMS < sysTimeouts.EXTERNALIDLETIMEOUT)
timeOutinMS = sysTimeouts.EXTERNALIDLETIMEOUT;
if (timeOutinMS < sysTimeouts.WAKEUPIDLETIMEOUT)
timeOutinMS = sysTimeouts.WAKEUPIDLETIMEOUT;
if (timeOutinMS == 0)
timeOutinMS = 30;
DisableDeviceSleep();
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("OK. I have calculated your computers timeout periods and set the ");
Console.WriteLine("necessary hooks. Your computer will not shut off the monitor, will");
Console.WriteLine("show active in any chat programs,the screensaver is disabled and ");
Console.WriteLine("the computer will not lock! Anyone looking at you eaither locally ");
Console.WriteLine("or remotely will think you are hard at work.");
Console.WriteLine("");
Console.WriteLine("Now go do something fun...I got your back ;)");
Console.WriteLine("Oh yeah....if you close this window OR press `q' in this ");
Console.WriteLine("window you are going to have to actually work.");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("This text will disappear in a 30 seconds. Just in case someone comes ");
Console.WriteLine("by and reads your screen!");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("Need custom coding? Kenneth.gore@gmail.com");
while (Console.KeyAvailable == false)
{
Thread.Sleep(250);
ConsoleKeyInfo cki = Console.ReadKey(true);
if (cki.KeyChar == 'q')
break;
}
}
public static void DisableDeviceSleep()
{
SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
preventSleepTimer = new System.Threading.Timer(new TimerCallback(PokeDeviceToKeepAwake), null, 0, timeOutinMS * 1000);
}
public static void EnableDeviceSleep()
{
preventSleepTimer.Dispose();
preventSleepTimer = null;
}
private static void PokeDeviceToKeepAwake(object extra)
{
Counter++;
try
{
SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
IntPtr Handle = FindWindow("SysListView32", "FolderView");
if (Handle == IntPtr.Zero)
{
SetForegroundWindow(Handle);
SendKeys.SendWait("%1");
}
if (Counter > 1)
Console.Clear();
}
catch
{
}
}
public static void GetSystemTimeOuts()
{
sysTimeouts.BATTERYIDLETIMEOUT = -2;
sysTimeouts.EXTERNALIDLETIMEOUT = -2;
sysTimeouts.WAKEUPIDLETIMEOUT = -2;
if (SystemParametersInfo(SPI_GETBATTERYIDLETIMEOUT, 0, ref batteryIdleTimer, 0) == 1)
sysTimeouts.BATTERYIDLETIMEOUT = batteryIdleTimer;
else
sysTimeouts.BATTERYIDLETIMEOUT = -1;
if (SystemParametersInfo(SPI_GETEXTERNALIDLETIMEOUT, 0, ref externalIdleTimer, 0) == 1)
sysTimeouts.EXTERNALIDLETIMEOUT = externalIdleTimer;
else
sysTimeouts.EXTERNALIDLETIMEOUT = -1;
if (SystemParametersInfo(SPI_GETWAKEUPIDLETIMEOUT, 0, ref wakeupIdleTimer, 0) == 1)
sysTimeouts.WAKEUPIDLETIMEOUT = wakeupIdleTimer;
else
sysTimeouts.WAKEUPIDLETIMEOUT = -1;
}
}
}
有一个名为“超时阻止程序”的android应用程序,它会每隔一段时间振动一次,您可以将鼠标放在上面。它说虽然不要在工作中使用它。https://play.google.com/store/apps/details?id=com.isomerprogramming.application.timeoutblocker&hl=zh_CN
我喜欢使用简单且集成的选项(无需其他软件),例如Powershell脚本(感谢https://dmitrysotnikov.wordpress.com/2009/06/29/prevent-desktop-lock-or-screensaver-with-powershell/),将“ f15”用作成功的关键(咖啡因的有效成分。实际上干扰最小)
param($minutes = 180)
write "... screen will be awake for $minutes"
$myshell = New-Object -com "Wscript.Shell"
for ($i = 0; $i -lt $minutes; $i++) {
write "... screen will be awake for" ($minutes-$i)
Start-Sleep -Seconds 60
$myshell.sendkeys("{F15}")
}
将其放入myScriptName.ps1并通过桌面快捷方式或命令行启动它:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nop "C:\Users\myUser\Desktop\myScriptName.ps1"
更新: 也许管理员有一些更改,但这对我不起作用了现在我必须使用NBirnel的autohotkey-script:https : //github.com/nbirnel/nosleep-这项工作很完美,因为它移动鼠标(不分散任何工作)
c:\Powershell>powershell -nop myScriptName.ps1 myScriptName.ps1 : The term 'myScriptName.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + myScriptName.ps1 + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (myScriptName.ps1:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException c:\Powershell>
在我的情况下,仅用这一行就可以了:
SendKeys.Send("{CAPSLOCK}");
只需将其放在Timer_Tick
事件中并将计时器间隔设置为例如60000ms。
您应该从控制面板>电源选项>更改计划设置中禁用“屏幕锁定” /“睡眠模式”。她在单击下拉菜单中的“让计算机进入睡眠状态”,然后选择“从不”。