Set objShell = CreateObject("Wscript.Shell")
' The "True" argument will make the script wait for the screensaver to exit
returnVal = objShell.Run("logon.scr", 1, True)
' Then call the lock functionality
objShell.Run "rundll32.exe user32.dll,LockWorkStation"
Set objShell = CreateObject("Wscript.Shell")
' The "True" argument will make the script wait for the screensaver to exit
returnVal = objShell.Run("logon.scr", 1, True)
' Then call the lock functionality
objShell.Run "rundll32.exe user32.dll,LockWorkStation"
Neither of these answers is perfect, both reveal a flicker of the desktop after the screen saver is disabled and just prior to the workstation being locked.
It may not be possible to reproduce the system behaviour of starting the screen saver and password protecting on resume. Even the answer to Launch System Screensaver from C# Windows Form only starts the screen saver, it does not password protect on resume.
using System;
using System.Runtime.InteropServices;
public static class LockDesktop
{
[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
private static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
private const int SC_SCREENSAVE = 0xF140;
private const int WM_SYSCOMMAND = 0x0112;
public static void SetScreenSaverRunning()
{
SendMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0);
}
public static void Main()
{
LockDesktop.SetScreenSaverRunning();
}
}
This works - only downside is that u cant interact with pc for something like 7 sec, but i guess its 7's to give ppl time before making screensaver 'permanent'.
in a batch (.bat) file, place it in a appropriate dir, and created a shortcut pointing to this, with the desired shortcut key.
In this line, \ExtraPath is the additional path under your win dir (usually this is \system32) where the screen savers are located, and ScreenSaverName.scr is the name of the desired screen saver itself.
It works perfectly.
Now I can press the shortcut keys to run the screen saver and lock the pc.
发布评论
评论(5)
以下是否满足您的要求?
只要
.scr
位于 PATH 上,上述命令就应该有效。编辑:我不知道 Windows 7 是否附带
logon.scr
,请确保您使用 Windows 7 中实际安装的.scr
对其进行测试。注意我想到了用 屏幕保护程序示例命令行选项:
编辑2:
我做了一些额外的搜索,发现你可以创建
lock.cmd
:或
lock.vbs
:这些答案都不完美,都揭示了闪烁屏幕保护程序被禁用之后、工作站被锁定之前的桌面。
可能无法重现启动屏幕保护程序和恢复时密码保护的系统行为。即使从 C# Windows 窗体启动系统屏幕保护程序的答案也只会启动屏幕保护程序,它不会在恢复时提供密码保护。
Does the following meet your requirements?
As long as the
.scr
is on the PATH the above command should work.EDIT: I don't know if Windows 7 comes with
logon.scr
, make sure you're testing it with a.scr
that is actually installed in Windows 7.Note that I got the idea of just invoking the
.scr
with/s
from Screensaver Sample Command Line Options:EDIT 2:
I did some additional searching and found that you could create
lock.cmd
:Or
lock.vbs
:Neither of these answers is perfect, both reveal a flicker of the desktop after the screen saver is disabled and just prior to the workstation being locked.
It may not be possible to reproduce the system behaviour of starting the screen saver and password protecting on resume. Even the answer to Launch System Screensaver from C# Windows Form only starts the screen saver, it does not password protect on resume.
将
cmd
和vbs
脚本想法与代码来自 从 C# Windows 窗体启动系统屏幕保护程序的答案 我想出了以下内容:要构建它,< a href="http://smallestdotnet.com/" rel="nofollow noreferrer">安装.NET Framework,将上述代码复制粘贴到
lock.cs
中,然后运行:将创建的
lock.exe
放入您的路径中,然后输入lock
应启用配置的屏幕保护程序并锁定您的工作站。Putting together the
cmd
andvbs
script ideas with the code from the answer to Launch System Screensaver from C# Windows Form I came up with the following:To build it, install the .NET Framework, copy and paste the above code into
lock.cs
, then run:Put the created
lock.exe
in your path, after that, typinglock
should engage the configured screen saver and lock your workstation.这个有效 - 唯一的缺点是你不能与电脑交互大约 7 秒,但我猜它 7 秒是为了让人们在使屏幕保护程序“永久”之前有时间。
This works - only downside is that u cant interact with pc for something like 7 sec, but i guess its 7's to give ppl time before making screensaver 'permanent'.
我有 Windows 7。我将行:放在
批处理 (.bat) 文件中,将其放在适当的目录中,并使用所需的快捷键创建指向此的快捷方式。
在此行中,
\ExtraPath
是屏幕保护程序所在 win 目录下的附加路径(通常是\system32
),ScreenSaverName.scr 是屏幕保护程序的名称所需的屏幕保护程序本身。它工作完美。
现在我可以按快捷键来运行屏幕保护程序并锁定电脑。
I have Windows 7. I placed the line:
in a batch (.bat) file, place it in a appropriate dir, and created a shortcut pointing to this, with the desired shortcut key.
In this line,
\ExtraPath
is the additional path under your win dir (usually this is\system32
) where the screen savers are located, and ScreenSaverName.scr is the name of the desired screen saver itself.It works perfectly.
Now I can press the shortcut keys to run the screen saver and lock the pc.
您可以尝试Powershell脚本启动随机屏幕保护程序。
You could try Powershell Script To Start A Random Screen Saver.