How can I set Windows (or Visual Studio, or my application) so that when I run a console app by hitting F5 from Visual Studio 2010, I can get a 120x50 layout with my choice of font, instead of the 80x25 standard CMD/DOS window?
(even better - anyone know how I can get VS to run console apps in something like Console2 or bash instead of cmd.exe ?)
Run a program from VS as normal (ctrl-f5, or f5, or whatever) and then from the system menu (click the icon in the upper-left corner of the window), choose "Defaults". Alter your settings as you like, and save them. From then on, new windows should be launched according to those settings.
As for running your program in something other than "cmd.exe", you should be aware that "cmd.exe" is not involved at all in the window. The window is a normal console window, and "cmd.exe" didn't create it. In the same vein, "bash" wouldn't be involved, because that's a command shell, not a windowing program.
Cmd.exe and bash (and a whole host of others, including 4nt, command.com, and everything along those lines) are not windowing programs, and they don't create windows. They're console-mode programs, and Windows automatically creates special "console" windows for them to run in. Windows knows they're console-mode programs because there's a flag in the .exe file (which is a file format called PE) that specifies what type of application it is.
Console2 is a program that hosts console applications, and in theory could be used, if Console2 allows you to start it and an external program at the same time. In your project properties, under the "Debug" tab, change the "Start Action" option to "Start external program:" and type in the command line that will start Console2 and your program together.
Related
I am writing a very simple alternative shell to replace explorer.exe the shell is run on Windows 10 Enterprise. I set up the C# Windows Form application to display as the alternative shell in the registry and pointed it to the \share folder.
When Windows boots and logs me in I get a black empty screen. If I run explorer.exe through the task manager - I does not load the Shell but the folder explorer. So Windows recognises that an alternative shell is being used.
So why is the form not displaying?
There is no code to show as the form is simply a form with a single label on it saying running.
Easily solved when I thought about it.
Shells cannot be started from a Shared network folder - the executable must be on a local drive.
Is there a way in Windows to launch a .csx script directly (e.g. by double clicking the file, or from the start menu, or via an app launcher like Launchy) such that the script runs in the background without opening a command line window?
For example, say I have a simple "lowercase.csx" script which simply takes whatever text is in my clipboard, converts it to lowercase, and puts the result back in my clipboard. I want to be able to double click on that .csx file and have that run completely in the background without opening any kind of window.
Currently both ScriptCS.exe and the new csi.exe launcher that comes with VS2015 Update 1 will open a console window when running a .csx file, even if that file doesn't output anything to the console.
Note: I know that a new window isn't opened if you launch a script from a console window. What I want to to launch a script in a non-command line context and have it open no windows.
Note2: The equivalent of what I want in "CS-Script" (a ScriptCS alternative) is to launch the files using "csws.exe".
You can make your own version of csi.exe that runs without a console.
Simply create a new project, make sure the Type is set to WinForms instead of Console, then add the C# Scripting package from NuGet and copy-paste the csi.exe source code.
scriptcs does not support this.
However there is an application that solves this problem: https://gitlab.com/Lions-Open-Source/ScriptCSW
A workaround is to create your own program that launches it in the background for you, like csws.exe would.
Start by creating a console app.
public static void Main(string[] args)
{
var startInfo = new ProcessStartInfo("path to csi.exe")
{
CreateNoWindow = true,
Arguments = args[1],
RedirectStandardOutput = true,
UseShellExecute = false,
};
Process.Start(startInfo);
}
(You'll obviously want to pass the rest of the arguments and check to make sure a file was passed etc, but this should get you started. And I wrote this answer on my Mac as my Windows box is in the shop, so I can't guarantee it'll work.)
Then have the console app not show a window by changing it to a Windows application from a Console application on the project properties screen as described in this question.
Lastly, configure .csx files to always open with your application. Then you can double click them and they'll run with no window.
Create a batch file and add (in this example to csi.exe installed for VS 2019):
#echo off
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn\csi.exe" "C:\myscript.csx"
If its important to hide the command prompt then see here and here.
When developing a C# project in Visual Studio, I have three options for output type. Console Application, Windows Application, and Class Library. AFAIK, the only difference between a DLL and an EXE, is the EXE should have an entry point defined, and that is called when the file is double clicked. However, when I launch an EXE built from a Console Application, a console window is created. So obviously something is happening other than the CLR getting launched and then calling my Main method. What launches the console window? When I launch an EXE built from a Windows Application, is some other code run also, or is it just my main method?
Your portable executable file(exe) will contain the information about what kind of application it is.
Subsystem flag of the IMAGE_OPTIONAL_HEADER defines what kind of user interface the application is built with.
IMAGE_SUBSYSTEM_WINDOWS_CUI defines the console application, IMAGE_SUBSYSTEM_WINDOWS_GUI defines the windows application and so on.
For more information Peering Inside the PE: A Tour of the Win32 Portable Executable File Format
The output type is a configuration parameter for your project which tells Visual Studio what to do when you compiled. If set to Console Application, it will generate an exe file with the code to launch the console window.
The different between a dll and an exe is more than the main method. Visual Studio generated additional codes in the exe file that creates the console and invoke the main method. For details of how the exe file performs this, refer to http://en.wikipedia.org/wiki/Portable_Executable.
In this link the inquisitor added some notes which mentioned the blog post (2nd link).
Is it possible to build a Console app that does not display a console Window when double-clicked?
http://blogs.msdn.com/b/oldnewthing/archive/2009/01/01/9259142.aspx
The same content as Siram's answer https://stackoverflow.com/a/30084790/2005526 but to assist you with future searches these were the keywords used on google to locate the mentioned resources. "double click exe launches console"
I need to run a .net application c# or preferably VB that will just perform a given task then close itself.
This app will receive arguments from the command line, process calculations, write result text to a file and then end.
Currently I run it as a console app, therefore the user can see the console black window and then the windoiw vanishes.
How can I get rid of the visual element?
Also, once the project is compiled, how can I include it within another solution so that both projects will be published together with clickOnce?
I need two separate projects in the same solution because one of them (the silent one) must run in x86 mode and the other as x64.
Assuming you're using a recent version of Visual Studio, go into your project properties (Application tab) and change the "Output type" dropdown from Console Application to Windows Application.
Not sure about the click-once requirement, though... haven't been down that road, but it may warrant a separate question.
Run the app as a process and set the window style to hidden.
System.Diagnostics.ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo();
start.FileName = dir + #"\silentApp.exe";
start.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
https://msdn.microsoft.com/en-us/library/system.diagnostics.process.start%28v=vs.110%29.aspx
I recently started experimenting with Xamarin and Mono C# on my Mac. I am used to working on Windows with Visual Studio so I find it cumbersome when every time I run my console application, a new terminal window and mono compiler terminal open up. And I have to manually close them. Is there anyway to get the output of my programs from a window or pane inside the IDE ? Or is there anyway to set it up so only one terminal window shows up ?
If you open the Project Options there is a Run on external console check box in the Run - General category which controls this behaviour. If you uncheck this option when you run a console application the output will be shown in an Application Output window inside Xamarin Studio and no external console window will be opened.
For anyone else arriving at this question who can't locate 'Project Options', the item is found in a drop down menu under the Project Tab (located at the top of the screen on the app's main nav bar). When a solution/file is loaded, the item is listed with your project's actual name, ex: 'MyProject Options' or 'MyProject&Options' (–it does not literally read 'Project Options').