Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Process.Start(ProcessStartInfo)不';t向屏幕保护程序发送命令行(.scr文件)_C#_Command Line Arguments_Screensaver - Fatal编程技术网

C# Process.Start(ProcessStartInfo)不';t向屏幕保护程序发送命令行(.scr文件)

C# Process.Start(ProcessStartInfo)不';t向屏幕保护程序发送命令行(.scr文件),c#,command-line-arguments,screensaver,C#,Command Line Arguments,Screensaver,我目前正在编写一个应用程序,在Windows 10上启动屏幕保护程序,并显示屏幕而不是黑色背景。因此,气泡和相关对象可以像旧版操作系统那样工作 这是我的全部代码: using Microsoft.Win32; using System; using System.Diagnostics; using System.IO; using System.Windows.Forms; public class DrawOverMyScreen { public static void Main(s

我目前正在编写一个应用程序,在Windows 10上启动屏幕保护程序,并显示屏幕而不是黑色背景。因此,气泡和相关对象可以像旧版操作系统那样工作

这是我的全部代码:

using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;

public class DrawOverMyScreen {
  public static void Main(string[] CommandLine) {
    switch (CommandLine[0]) {
      case "/c":
        DialogResult Answer = MessageBox.Show("What do you want to do?\n\n - Press \"Yes\" to configure the screensaver\n - Press \"No\" to change the screensaver\n - Press \"Cancel\" to do nothing", "DrawOverMyScreen Configuration", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
        switch (Answer) {
          case DialogResult.Yes:
            Screensaver("/c");
            break;

          case DialogResult.No:
            throw new NotImplementedException();
            break;

          default:
            break;
        }
        break;

      default:
        Screensaver("/s");
        break;
    }
  }

  public static void Screensaver(string CommandLine) {
    RegistryKey Settings = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\DrawOverMyScreen");
    if (Settings != null) {
      string ScreensaverLocation = Settings.GetValue("Screensaver", string.Empty).ToString();
      if (!string.IsNullOrEmpty(ScreensaverLocation) && File.Exists(ScreensaverLocation)) {
        Process Screensaver = Process.Start(new ProcessStartInfo(ScreensaverLocation, CommandLine));
        Screensaver.WaitForExit();
      }
    }
  }
}
注意
屏幕保护程序
方法。它使用
Process.Start(新的ProcessStartInfo(屏幕保护位置,命令行))
启动屏幕保护程序。但每当我做
Screensaver(“/c”)
要运行屏幕保护程序的配置实用程序,我只会得到普通的屏幕保护程序视图(在一段时间后空闲时得到的视图)。使用如下运行提示符:
C:\Windows\SysWOW64\SCREEN~1.SCR/C
也会给出相同的结果,但命令行提示符实际上会打开配置实用程序


为什么它不起作用,我怎样才能使它起作用呢?

仅从您提供的信息来看,我无法告诉您为什么它不起作用。我没有一个屏幕保护程序来测试(据我所知)。但我可以通过记事本打开一个文本文件来完成这四个步骤:

单独处理StartInfo

     ProcessStartInfo procInfo = new ProcessStartInfo("notepad.exe", "c:\\test.txt");
     Process proc = Process.Start(procInfo);
     proc.WaitForExit();
     Process proc = Process.Start(new ProcessStartInfo("notepad.exe", "c:\\test.txt"));
     proc.WaitForExit();
使用属性分离ProcessStartInfo

     ProcessStartInfo procInfo = new ProcessStartInfo();
     procInfo.Arguments = "c:\\test.txt";
     procInfo.FileName = "notepad.exe";
     Process proc = Process.Start(procInfo);
     proc.WaitForExit();
     Process proc = Process.Start("notepad.exe", "c:\\test.txt");
     proc.WaitForExit();
内联处理StartInfo

     ProcessStartInfo procInfo = new ProcessStartInfo("notepad.exe", "c:\\test.txt");
     Process proc = Process.Start(procInfo);
     proc.WaitForExit();
     Process proc = Process.Start(new ProcessStartInfo("notepad.exe", "c:\\test.txt"));
     proc.WaitForExit();
没有PSI,只需处理

     ProcessStartInfo procInfo = new ProcessStartInfo();
     procInfo.Arguments = "c:\\test.txt";
     procInfo.FileName = "notepad.exe";
     Process proc = Process.Start(procInfo);
     proc.WaitForExit();
     Process proc = Process.Start("notepad.exe", "c:\\test.txt");
     proc.WaitForExit();
您可能希望使用第一个,这样您就可以在“Process proc…”行上设置断点,并检查
procInfo
的属性。
Arguments
属性应该显示第二个值(在我的例子中是
c:\\test.txt
),而
FileName
属性应该是执行的路径(我的是
notepad.exe

编辑:我添加了带有属性的单独设置,这样您就可以真正看到显式设置

配置屏幕保护程序 我使用3D文本屏幕保护程序制作了一个示例:

     string scrPath = @"C:\Windows\System32\ssText3d.scr";
     ProcessStartInfo procInfo = new ProcessStartInfo();
     procInfo.FileName = scrPath;
     procInfo.Verb = "config";
     procInfo.UseShellExecute = false;
     Process proc = Process.Start(procInfo);
     proc.WaitForExit();
我没有使用
参数
。相反,我使用了
动词
。这需要将
UseShellExecute
设置为
false
。我得到了预期的配置对话框,而不是运行屏幕保护程序

关于动词的更多信息

     ProcessStartInfo procInfo = new ProcessStartInfo();
     procInfo.Arguments = "c:\\test.txt";
     procInfo.FileName = "notepad.exe";
     Process proc = Process.Start(procInfo);
     proc.WaitForExit();
     Process proc = Process.Start("notepad.exe", "c:\\test.txt");
     proc.WaitForExit();
这是动词用于屏幕保护程序的地方。


您还可以定义自定义谓词:

您的第一个代码块使用记事本,但不使用
ProcessStartInfo procInfo=new ProcessStartInfo(“C:\\Windows\\SysWOW64\\ScreenSmelter.scr”,“/C”)
(带来了屏幕保护程序)似乎确实与文件扩展名
.scr
有关,因为
ProcessStartInfo procInfo=new ProcessStartInfo(“C:\\Users\\Charles\\Desktop\\ScreenSmelter.exe”,“/C”)工作得非常好(它带来了配置工具而不是屏幕保护程序)。我将重新命名这个问题,指定它带有一个屏幕保护程序。与此相关,但这里提供的答案是肮脏的黑客,我希望避免。在更糟糕的情况下,我将使用它并隐藏以编程方式弹出的命令提示符。是的,这很难看。我不知道为什么Windows没有让它与
进程
协同工作,因为它可以以其他方式执行(命令行等)。至少它很容易实现。我添加了一个配置屏幕保护程序的部分。我不知道它是否适用于您的特定屏幕保护程序,但我决定使用哪个动词的方法是在行上放置一个断点,然后检查“动词”集合。对于ssText3d.scr,它们是
config
install
open
。也许这会引导你朝更好的方向走。@charles.milette我忘了提及你,以防它不会触发通知。但是,请参见上文。