【问题标题】:Exe program that shutdown Windows?关闭Windows的exe程序?
【发布时间】:2020-03-31 14:28:55
【问题描述】:

我想制作一个关闭 Windows 的 exe 应用程序。它是从 McMyAdmin 2 开始的。我该怎么做? (我已经尝试过制作这个应用程序 (Shutdown Visual Studio Project and EXE),但我收到了这个错误:

The system cannot find the file specified
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at McMyAdmin.TimedEvents.DoExec(String EventData, Boolean SendToConsole, String Args)

你能帮帮我吗? 谢谢! 哈维尔

【问题讨论】:

  • 您真的需要编写自己的应用程序,还是只需要一个 .exe 文件来执行 McMyAdmin 的任何操作?如果是后者,正如两个答案所引用的那样,有内置的 Windows 可执行文件shutdown.exe,您可以使用它通过shutdown /s 关闭计算机。此外,任何人都不必从第三方服务器下载即将到期的.rar 文件来查看您的代码。请在问题本身中提供相关部分,否则无法诊断您的错误消息。

标签: c# visual-studio minecraft windows-server-2019 system-shutdown


【解决方案1】:
"I want to make an exe app that shutdown Windows."  

这些代码示例(Linux Windows。)是来自下面链接的简单示例。您将不得不考虑程序需要以足够的权限执行,以及其他一些事情才能让它们按您的意愿工作......

在 Windows 中:

EDIT(标签从C更改为C#

C# - 您可以将其与任何 Windows 实用程序 exe 一起使用:

Process.Start("application.exe", "param1 param2");

例如。

Process.Start("c:\\windows\\system32\\shutdown.exe", "/s");

对于 ANSI C -

#include <stdio.h> 
#include <stdlib.h> 

int main(void) 
{ 
  system("c:\\windows\\system32\\shutdown /s"); //simple shutdown
  return 0; 
} 

其他命令:

system("c:\\windows\\system32\\shutdown /i"); //shutdown with GUI
system("c:\\windows\\system32\\shutdown /r"); //Restart  
system("c:\\windows\\system32\\shutdown /l"); //Logoff
Note: These Windows shutdown commands may bring up a dialog
box requiring user to enter PC name.  If you want to automate   
populating the dialog box, command switches will help:
  Open a cmd prompt in Windows and type "help shutdown" to get this information

更多信息here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    • 2012-03-14
    • 2021-12-21
    • 1970-01-01
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多