本文介绍了如何通过代码(在cmd中)打开(窗口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();
    }
}

这样做只有一个缺点, pc的东西像7秒,但我猜它的7的给ppl时间之前,使屏幕保护程序永久。

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中)打开(窗口7)上的屏幕保护程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 21:52