如何通过代码(在cmd中)打开屏幕保护程序(Windows 7)? [英] How to turn screensaver on (windows 7) by a code (in cmd)?

查看:15
本文介绍了如何通过代码(在cmd中)打开屏幕保护程序(Windows 7)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过代码(在 cmd 中)打开屏幕保护程序(Windows 7)?

How to turn screensaver on (windows 7) by a code (in cmd)?

推荐答案

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();
    }
}

这行得通 - 唯一的缺点是你不能与电脑交互 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'.

这篇关于如何通过代码(在cmd中)打开屏幕保护程序(Windows 7)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆