简体   繁体   English

C#控制台程序无法从命令提示符下执行

[英]C# Console Program Won't Execute from Command Prompt

I have made a very simple program in C#. 我用C#编写了一个非常简单的程序。 When I double click the compiled exe, it executes and works. 当我双击已编译的exe时,它将执行并运行。 When I run the exe from the command prompt, it does absolutely nothing. 当我从命令提示符运行exe时,它绝对不执行任何操作。 I have tried executing it from an Administrator command prompt also. 我也尝试从管理员命令提示符下执行它。 I am on Windows 7. This is very frustrating. 我在Windows 7上。这非常令人沮丧。

The only command the program executes when ran is 程序在运行时执行的唯一命令是

SendMessageW(Process.GetCurrentProcess().MainWindowHandle, WM_APPCOMMAND, Process.GetCurrentProcess().MainWindowHandle, (IntPtr)APPCOMMAND_VOLUME_MUTE);

A console program may have no message loop or main window. 控制台程序可能没有消息循环或主窗口。 So SendMessageW() does not work. 因此,SendMessageW()不起作用。

Not sure what you are trying to accomplish, but this little program 不确定您要完成什么,但是这个小程序

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(Process.GetCurrentProcess().MainWindowHandle);
        Console.ReadKey();
    }
}

may help you troubleshoot your problem. 可以帮助您解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM