Take the 2-minute tour ×

I have made a very simple program in C#. When I double click the compiled exe, it executes and works. When I run the exe from the command prompt, it does absolutely nothing. I have tried executing it from an Administrator command prompt also. I am on Windows 7. This is very frustrating.

The only command the program executes when ran is

SendMessageW(Process.GetCurrentProcess().MainWindowHandle, WM_APPCOMMAND, Process.GetCurrentProcess().MainWindowHandle, (IntPtr)APPCOMMAND_VOLUME_MUTE);
share|improve this question
Without some examples from the offending code and some context surrounding the code you do provide, we cannot provide any solution. –  IAbstract Sep 8 '12 at 3:01
The program is a simple program that is supposed to mute the windows system volume. It works just fine when ran from visual studio, or if the exe is DOUBLE CLICKED on. When ran from the COMMAND PROMPT, the program does NOTHING. That is my problem. –  mtear Sep 8 '12 at 4:22
Please edit your question and add the code. :) –  IAbstract Sep 8 '12 at 4:40

2 Answers 2

up vote 2 down vote accepted

Not sure what you are trying to accomplish, but this little program

class Program
    static void Main(string[] args)

may help you troubleshoot your problem.

share|improve this answer
Why is the output as "0" when executed from the command line? )= –  mtear Sep 8 '12 at 4:31
It's a magic ))) But it means that current process does not have main window handle thus it's NULL which is 0 for MS Windows API –  aiodintsov Sep 8 '12 at 4:52
Thank you sir. I solved the issue by making invisible Windows forms that execute the same code and it worked perfectly. Any suggestions on how I'd make a console application be able to work also? –  mtear Sep 8 '12 at 5:07
your approach works and essentialy does the same thing you would otherwise have to do from code. –  aiodintsov Sep 8 '12 at 5:18

A console program may have no message loop or main window. So SendMessageW() does not work.

share|improve this answer
But the program works just fine in visual studio. It works just fine when the exe is compiled and you double click on the exe file. But when you type the exe from the command prompt, it acts like it executed and then does nothing. It only fails when ran from the command prompt window. –  mtear Sep 8 '12 at 4:19

Your Answer


