How to enable screensaver (windows 7) by code (in cmd)?

How to enable screensaver (windows 7) using code (in cmd)?

+7
windows command screensaver
source share
6 answers
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 - just a flaw - it is that you cannot interact with the PC for something like 7 seconds, but I think its 7 to give ppl time before making the screensaver โ€œpermanentโ€.

+2
source share

Does the following meet the requirements?

 start logon.scr /s 

While .scr is in PATH, this command should work.

EDIT: I don't know if Windows 7 logon.scr with logon.scr , make sure you test it with .scr , which is actually installed on Windows 7.

Note that it occurred to me to simply call .scr using /s from the Command line options for a sample screen :

When Windows launches your splash screen, it launches it using one of the three Line Parameters commands:

  • / s - Launch a screen saver in full screen mode.
  • / c - Show configuration options dialog box.
  • / p #### - display a preview of the splash screen using the specified window handle.

EDIT 2:

I did a few additional searches and found that you can create lock.cmd :

 @start /wait logon.scr /s & rundll32 user32.dll,LockWorkStation 

Or lock.vbs :

 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" 

None of these answers are ideal, both show the flickering of the desktop after the screen saver is turned off and immediately before the workstation locks.

Cannot reproduce the system behavior of the startup screen saver and password protection when resuming. Even the answer to Starting System Screensaver from C # Windows Form launches a screen saver, it does not password protect when resuming.

+9
source share

Combining the ideas of cmd and vbs script with the code from the response to starting the startup system Screensaver from C # Windows Form I came up with the following:

 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); [DllImport("user32.dll", EntryPoint = "LockWorkStation")] private static extern IntPtr LockWorkStation(); private const int SC_SCREENSAVE = 0xF140; private const int WM_SYSCOMMAND = 0x0112; public static void SetScreenSaverRunning() { SendMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0); LockWorkStation(); } public static void Main() { LockDesktop.SetScreenSaverRunning(); } } 

To create it, install the .NET Framework , copy and paste the above code into lock.cs , and then run:

 %SystemRoot%\Microsoft.NET\Framework\v3.5\csc.exe lock.cs 

Put the created lock.exe in your path, then enter lock to enable the customized splash screen and lock the workstation.

+5
source share

I have Windows 7. I put the line:

@ start / wait% windir% \ ExtraPath \ ScreenSaverName.scr / s and rundll32 user32.dll, LockWorkStation

in a batch (.bat) file, place it in the appropriate directory and create a shortcut pointing to it using the desired shortcut key. On this line, \ ExtraPath is the optional path in your win dir (usually \ system32), where the screen savers are located, and ScreenSaverName.scr is the name of the most requested screen saver.

It works great.

Now I can press the shortcut keys to start the screen saver and lock the computer.

Thank you very much.

+3
source share
+2
source share

It seems strange that wherever I looked, there is no answer that reflects this in O / S itself. what all these hacks just do is launch a screen saver, and then when it is stopped (interrupted), the program starts the workstation / lock desktop after the fact. The continuous effort to bring up a password-protected screen saver that, when stopping / interrupting the password, is required to return to the workstation, is what I need. It seems this is not such a high order? I will look for any programming solution that I can find, but obviously he needed to call other applications at the application level (including scripting technologies), and not be buried within O / S at the O / S level.

0
source share

All Articles