Run program from console windows

How do I launch a program from command line without opening a new cmd window?

I’m trying to programmatically execute an external file from cmd using this command:

Where «filepath» is the path of my file. It opens fine but it also open a new command prompt window.

So, which is the right command for opening an external program without opening a new window?

9 Answers 9

In Windows 7+ the first quotations will be the title to the cmd window to open the program:

Formatting your command like the above will temporarily open a cmd window that goes away as fast as it comes up so you really never see it. It also allows you to open more than one program without waiting for the first one to close first.

Add /B, as documented in the command-line help for start:

Just remove the double quote, this works in Windows 7:

If you want to maximize the window, try this:

Your command START «filepath» will start a command prompt and change the command prompt title to filepath .

Try to run start /? in windows command prompt and you will get more info.

I think if you closed a program

end, so if you want to start a program that you can use

(/norma,/max/min are that process value cpu)

start «filepath»

if you want command line without openning an new window you write that

start /b «filepath»

/B is Start application without creating a new window. The application has ^C handling ignored. Unless the application enables ^C processing, ^Break is the only way to interrupt the application.

If you’re doing it via CMD as you say, then you can just enter the command like so:

which will open it within the same window. For example in C++:

will open your.exe in the current CMD window. Likewise to start with a new window, just go for:

If you go for the first option, you would have to clear your screen unless you wanted to have the command to open your.exe on the screen still.

You can use the call command.

Usage: call [drive:][path]filename [batch-parameters]

For example call «Example File/Input File/My Program.bat» [This is also capable with calling files that have a .exe, .cmd, .txt, etc.

NOTE: THIS COMMAND DOES NOT ALWAYS WORK.

Not all computers are capable to run this command, but if it does work than it is very useful, and you won’t have to open a brand new window.

how to run a winform from console application?

How do I create, execute and control a winform from within a console application?

10 Answers 10

The easiest option is to start a windows forms project, then change the output-type to Console Application. Alternatively, just add a reference to System.Windows.Forms.dll, and start coding:

The important bit is the [STAThread] on your Main() method, required for full COM support.

Exe netcoreapp3.1 true true

notice the Microsoft.NET.Sdk.WindowsDesktop and the UseWPF>true and the UseWindowsForms>true – Shaybc Aug 4 ’20 at 2:38

I recently wanted to do this and found that I was not happy with any of the answers here.

If you follow Marc’s advice and set the output-type to Console Application there are two problems:

1) If you launch the application from Explorer, you get an annoying console window behind your Form which doesn’t go away until your program exits. We can mitigate this problem by calling FreeConsole prior to showing the GUI (Application.Run). The annoyance here is that the console window still appears. It immediately goes away, but is there for a moment none-the-less.

2) If you launch it from a console, and display a GUI, the console is blocked until the GUI exits. This is because the console (cmd.exe) thinks it should launch Console apps synchronously and Windows apps asynchronously (the unix equivalent of «myprocess &»).

If you leave the output-type as Windows Application, but correctly call AttachConsole, you don’t get a second console window when invoked from a console and you don’t get the unnecessary console when invoked from Explorer. The correct way to call AttachConsole is to pass -1 to it. This causes our process to attach to the console of our parent process (the console window that launched us).

However, this has two different problems:

1) Because the console launches Windows apps in the background, it immediately displays the prompt and allows further input. On the one hand this is good news, the console is not blocked on your GUI app, but in the case where you want to dump output to the console and never show the GUI, your program’s output comes after the prompt and no new prompt is displayed when you’re done. This looks a bit confusing, not to mention that your «console app» is running in the background and the user is free to execute other commands while it’s running.

2) Stream redirection gets messed up as well, e.g. «myapp some parameters > somefile» fails to redirect. The stream redirection problem requires a significant amount of p/Invoke to fixup the standard handles, but it is solvable.

After many hours of hunting and experimenting, I’ve come to the conclusion that there is no way to do this perfectly. You simply cannot get all the benefits of both console and window without any side effects. It’s a matter of picking which side effects are least annoying for your application’s purposes.

How can I run a program from a batch file without leaving the console open after the program starts?

For the moment my batch file look like this:

The program starts but the DOS Window remains open. How can I close it?

11 Answers 11

You can use the exit keyword. Here is an example from one of my batch files:

Читайте также:  Start with python windows

Use the start command to prevent the batch file from waiting for the program. Just remember to put a empty double quote in front of the program you want to run after «Start». For example, if you want to run Visual Studio 2012 from a batch command:

notice the double quote after start.

– Kruug Sep 25 ’13 at 20:37

Look at the START command, you can do this:

For instance, this batch-file will wait until notepad exits:

However, this won’t:

works if you start the program from an existing DOS session.

If not, call a vb script

  • intWindowStyle : 0 means «invisible windows»
  • bWaitOnReturn : false means your first script does not need to wait for your second script to finish

Here is invis.vbs:

This is the only thing that worked for me when I tried to run a java class from a batch file:

start «cmdWindowTitle» /B «javaw» -cp . testprojectpak.MainForm

You can customize the start command as you want for your project, by following the proper syntax:

You should try this. It starts the program with no window. It actually flashes up for a second but goes away fairly quickly.

How to solve «space problem» and local dependencies:

Loads of answers for this question already, but I am posting this to clarify something important, though this might not always be the case:

Might cause issues in some windows versions as Start actually expects the first set of quotation marks to be a windows title. So it is best practice to first double quote a comment, or a blank comment:

My solution to do this from the GUI:

Create a shortcut to the program you want to run;

Edit the shortcut’s properties;

Change the TARGET field to %COMSPEC% /C «START «» «PROGRAMNAME»» ;

Change the RUN field to minimized.

Ready! See how you like it.

PS: Program parameters can be inserted in between the two final quotation marks; the PROGRAMNAME string can be either a filename, a relative or an absolute path — if you put in an absolute path and erase the drive letter and semicolon, then this will work in a thumbdrive no matter what letter the host computer assigns to it. (also, if you place the shortcut in the same folder and precede the program filename in PROGRAMNAME with the %CD% variable, paths will always match; same trick can be used in START IN field).

How do I run a Java program from the command line on Windows?

I’m trying to execute a Java program from the command line in Windows. Here is my code:

I’m not sure how to execute the program — any help? Is this possible on Windows? Why is it different than another environment (I thought JVM was write once, run anywhere)?

12 Answers 12

Let’s say your file is in C:\mywork\

Run Command Prompt

This makes C:\mywork the current directory.

This displays the directory contents. You should see filenamehere.java among the files.

This tells the system where to find JDK programs.

This runs javac.exe, the compiler. You should see nothing but the next system prompt.

javac has created the filenamehere.class file. You should see filenamehere.java and filenamehere.class among the files.

This runs the Java interpreter. You should then see your program output.

If the system cannot find javac, check the set path command. If javac runs but you get errors, check your Java text. If the program compiles but you get an exception, check the spelling and capitalization in the file name and the class name and the java HelloWorld command. Java is case-sensitive!

To complete the answer :

Compile the Java File to a *.class file

  • This will create a TheJavaFile.class file

Execution of the Java File

Creation of an executable *.jar file

You’ve got two options here —

With an external manifest file :

Create the manifest file say — MANIFEST.mf

The MANIFEST file is nothing but an explicit entry of the Main Class

jar -cvfm TheJavaFile.jar MANIFEST.mf TheJavaFile.class

Executable by Entry Point:

To run the Jar File

In case your Java class is in some package. Suppose your Java class named ABC.java is present in com.hello.programs , then you need to run it with the package name.

Compile it in the usual way:

But to run it, you need to give the package name and then your java class name:

Complile a Java file to generate a class:

Execute the generated class:

Assuming the file is called «CopyFile.java», do the following:

The first line compiles the source code into executable byte code. The second line executes it, first adding the current directory to the class path (just in case).

Since Java 11, java command line tool has been able to run a single-file source-code directly. e.g.

This was an enhancement with JEP 330: https://openjdk.java.net/jeps/330

For the details of the usage and the limitations, see the manual of your Java implementation such as one provided by Oracle: https://docs.oracle.com/en/java/javase/11/tools/java.html

It is easy. If you have saved your file as A.text first thing you should do is save it as A.java. Now it is a Java file.

Now you need to open cmd and set path to you A.java file before compile it. you can refer this for that.

Then you can compile your file using command

Then run it using

So that is how you compile and run a java program in cmd. You can also go through these material that is Java in depth lessons. Lot of things you need to understand in Java is covered there for beginners.

You can compile any java source using javac in command line ; eg, javac CopyFile.java. To run : java CopyFile. You can also compile all java files using javac *.java as long as they’re in the same directory

If you’re having an issue resulting with «could not find or load main class» you may not have jre in your path. Have a look at this question: Could not find or load main class

On Windows 7 I had to do the following:

quick way

  1. Install JDK http://www.oracle.com/technetwork/java/javase/downloads
  2. in windows, browse into «C:\Program Files\Java\jdk1.8.0_91\bin» (or wherever the latest version of JDK is installed), hold down shift and right click on a blank area within the window and do «open command window here» and this will give you a command line and access to all the BIN tools. «javac» is not by default in the windows system PATH environment variable.
  3. Follow comments above about how to compile the file («javac MyFile.java» then «java MyFile») https://stackoverflow.com/a/33149828/194872
Читайте также:  Windows не удалось найти http

long way

  1. Install JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html
  2. After installing, in edits the Windows PATH environment variable and adds the following to the path C:\ProgramData\Oracle\Java\javapath. Within this folder are symbolic links to a handful of java executables but «javac» is NOT one of them so when trying to run «javac» from Windows command line it throws an error.
  3. I edited the path: Control Panel -> System -> Advanced tab -> «Environment Variables. » button -> scroll down to «Path», highlight and edit -> replaced the «C:\ProgramData\Oracle\Java\javapath» with a direct path to the java BIN folder «C:\Program Files\Java\jdk1.8.0_91\bin».

This likely breaks when you upgrade your JDK installation but you have access to all the command line tools now.

Useful Run Commands Every Windows User Should Know

A quick-and-easy keyboard-only way to run Windows’ wealth of tools is through the “Run” command. If you know the corresponding Run command of a tool or task, then you know the quickest way to access said tool or task.

The following is a list of our favorite Run commands to help you be more productive.

Note: Press Win + R on your keyboard to open the Run dialog box, and enter any of the below commands to access the respective tool.

List of Run Commands

1. services.msc – When you enter “services.msc” and press the Enter button, it will open the Windows Services app where you can easily start, stop and configure other settings for each and every service individually. It’s quite helpful when you want to toggle a service.

2. mstsc – Entering “mstsc” into the Run dialog box opens the Remote Desktop Connection app which allows you to connect to another Windows computers over the local network or through the Internet. This helps you use the host computer as your own.

3. msinfo32 – If you want to quickly get your system information, then the “msinfo32” command is the way to go. At a glance it will display all the system details including the hardware resources and software environment.

4. sdclt – This command opens the Backup and Restore window that allows you to quickly set a backup schedule or restore any of your previous backups.

5. compmgmt.msc – The Computer Management app is where you can access almost all the advanced Windows modules like Event Viewer, Shared Folder, System Tools, etc.

6. cleanmgr – This command allows you to open the Windows Disk Cleanup utility. Once opened, simply select the drive your want to clean up and click the “OK” button.

7. eventvwr.msc – Windows Event Viewer is where Windows stores all the monitoring and troubleshooting messages. You can use this command to quickly access the Event Viewer application.

8. control – Every Windows user knows a thing or two about the Windows Control Panel, and using this command you can quickly access the Control Panel with some stumbling around.

9. mmc – Microsoft Management Console (MMC) is an advanced Windows module that is mainly aimed at system administrators and power users, as it sports all the tools required for configuring and monitoring a Windows system.

10. resmon – Whenever you want to check how your system resources are being utilized, simply use this Run command, and it displays everything from your CPU to Dist to Network.

11. \ – This is one of the lesser-known Run commands. Just enter the backslash into the Run dialog box, and it will open up the C drive. It is one of the quickest ways to access the C drive.

12. . – This is yet another lesser-known Run command. When executed, it opens the current user’s home folder which hosts all the other local folders like the Downloads, Documents, Desktop, Pictures, etc.

13. .. – When you execute these two dots in the Run dialog box, it will open up the Users folder which is located directly in the C drive.

14. calc – If you want to quickly open the built-in Windows calculator app, typing calc in the Run dialog box is the easiest way to do it.

15. cmd – Even Windows users have to deal with the command line sometimes. With this command you can quickly open the command prompt without administrator privileges.

16. powershell – If the command prompt is too old for you, then you may want to try PowerShell. Just type this command in the Run dialog box, and you will have your PowerShell opened without administrator privileges.

17. netplwiz – The general user accounts option is available through the Control Panel, but if you want to mess with the advanced user account options, then use this command to open the Advanced User Accounts window. If you want to deal with the Authorization Manager, then use the Run command azman.msc .

18. gpedit.msc – Group Policy Editor in Windows allows you to set and edit different Windows policies of a local or remote computer. Since Group Policy Editor is an advanced tool, it is buried deep inside Windows, and this Run command is the easiest way to access it.

19. lusrmgr.msc – Using this command, you can open the Local Users and Groups Manager where you can edit several properties of all the users and groups.

20. mrt – Every month Windows releases a newer version of Microsoft Windows Malicious Software Removal Tool through the Windows Update. This free tool helps you in cleaning some of the most popular malicious software from your Windows computer. This tool runs silently in the background, but if you want to run it manually, then use this Run command.

21. ncpa.cpl – Being an Internet user means that you have to deal with occasional (if not daily) network problems, and one way to troubleshoot your network connection is by accessing your Network Adapters. To access all your Network Adapters, you can use this Run command.

22. perfmon.msc – If you want to monitor the performance of your Windows computer and effects of the programs you run, running Performance Monitor will provide ample data. You can access the Performance Monitor using this command.

23. powercfg.cpl – Windows hosts a wide range of power options to deal with your computer’s power usage, and you can access all those Power Options using this command.

24. appwiz.cpl – Using this command you can quickly access the Programs and Features window where you can quickly uninstall your installed programs.

25. devmgmt.msc – Windows Device Manager is where you can manage all your hardware devices, and you can use this Run command to quickly access it. Alternatively, you can also use the command “hdwwiz.cpl.”

26. regedit – Regedit Run command can be used to access the Windows Registry, which is a hierarchical database that hosts all the configurations and settings of an operating system and the installed programs.

27. msconfig – Windows System Configuration is where you can edit different things like the boot options, startup options, services, etc. You can use this Run command to access the System Configuration window.

28. sysdm.cpl – If you ever want to access the System Properties window, then using this Run command opens it right up.

29. firewall.cpl – If you want to manage or configure your Windows firewall, then you can use this Run command to quickly access the Firewall window.

30. wuapp – Last but not least, you can use this command to check, manage and configure all your Windows update settings.

More Run Commands

Can’t get enough of the Run command? Here we have compiled a big list of all the Run commands available in Windows.

Task Name Run Command
About Windows winver
Add a Device devicepairingwizard
Add Hardware Wizard hdwwiz
Advanced User Accounts netplwiz
Authorization Manager azman
Backup and Restore sdclt
Bluetooth File Transfer fsquirt
Calculator calc
Certificates certmgr
Change Computer Performance Settings systempropertiesperformance
Change Data Execution Prevention Settings systempropertiesdataexecutionprevention
Change Printer Settings printui
Character Map charmap
ClearType Tuner cttune
Color Management colorcpl
Command Prompt cmd
Component Services comexp
Component Services dcomcnfg
Computer Management compmgmt
Computer Management compmgmtlauncher
Connect to a Network Projector netproj
Connect to a Projector displayswitch
Control Panel control
Create A Shared Folder Wizard shrpubw
Create a System Repair Disc recdisc
Credential Backup and Restore Wizard credwiz
Data Execution Prevention systempropertiesdataexecutionprevention
Default Location locationnotifications
Device Manager devmgmt
Device Pairing Wizard devicepairingwizard
Diagnostics Troubleshooting Wizard msdt
Digitizer Calibration Tool tabcal
DirectX Diagnostic Tool dxdiag
Disk Cleanup cleanmgr
Disk Defragmenter dfrgui
Disk Management diskmgmt
Display dpiscaling
Display Color Calibration dccw
Display Switch displayswitch
DPAPI Key Migration Wizard dpapimig
Driver Verifier Manager verifier
Ease of Access Center utilman
Encrypting File System Wizard rekeywiz
Event Viewer eventvwr
Fax Cover Page Editor fxscover
File Signature Verification sigverif
Getting Started gettingstarted
IExpress Wizard iexpress
Import to Windows Contacts wabmig*
iSCSI Initiator Configuration Tool iscsicpl
iSCSI Initiator Properties iscsicpl
Language Pack Installer lpksetup
Local Group Policy Editor gpedit
Local Security Policy secpol
Local Users and Groups lusrmgr
Location Activity locationnotifications
Magnifier magnify
Malicious Software Removal Tool mrt
Manage Your File Encryption Certificates rekeywiz
Math Input Panel mip*
Microsoft Management Console mmc
Microsoft Support Diagnostic Tool msdt
NAP Client Configuration napclcfg
Narrator narrator
New Scan Wizard wiaacmgr
Notepad notepad
ODBC Data Source Administrator odbcad32
ODBC Driver Configuration odbcconf
On-Screen Keyboard osk
Paint mspaint
Performance Monitor perfmon
Performance Options systempropertiesperformance
Phone Dialer dialer
Presentation Settings presentationsettings
Print Management printmanagement
Printer Migration printbrmui
Printer User Interface printui
Private Character Editor eudcedit
Problem Steps Recorder psr
Protected Content Migration dpapimig
Registry Editor regedit
Remote Access Phonebook rasphone
Remote Desktop Connection mstsc
Resource Monitor resmon
Resultant Set of Policy rsop
Securing the Windows Account Database syskey
Services services
Set Program Access and Computer Defaults computerdefaults
Share Creation Wizard shrpubw
Shared Folders fsmgmt
Snipping Tool snippingtool
Sound Recorder soundrecorder
SQL Server Client Network Utility cliconfg
Sticky Notes stikynot
Stored User Names and Passwords credwiz
Sync Center mobsync
System Configuration msconfig
System Configuration Editor sysedit (This command doesn’t work in the 64-bit version of Windows.)
System Information msinfo32
System Properties (Advanced Tab) systempropertiesadvanced
System Properties (Computer Name Tab) systempropertiescomputername
System Properties (Hardware Tab) systempropertieshardware
System Properties (Remote Tab) systempropertiesremote
System Properties (System Protection Tab) systempropertiesprotection
System Restore rstrui
Tablet PC Input Panel tabtip*
Task Manager taskmgr
Task Scheduler taskschd
Trusted Platform Module (TPM) Management tpm
User Account Control Settings useraccountcontrolsettings
Utility Manager utilman
Version Reporter Applet winver
Volume Mixer sndvol
Windows Activation Client slui
Windows Anytime Upgrade Results windowsanytimeupgraderesults
Windows Contacts wab*
Windows Disc Image Burning Tool isoburn
Windows DVD Maker dvdmaker*
Windows Easy Transfer migwiz*
Windows Explorer explorer
Windows Fax and Scan wfs
Windows Features optionalfeatures
Windows Firewall with Advanced Security wf
Windows Help and Support winhlp32
Windows Journal journal*
Windows Media Player wmplayer*
Windows Memory Diagnostic Scheduler mdsched
Windows Mobility Center mblctr
Windows Picture Acquisition Wizard wiaacmgr
Windows PowerShell powershell*
Windows PowerShell ISE powershell_ise*
Windows Remote Assistance msra
Windows Repair Disc recdisc
Windows Script Host wscript
Windows Update wuapp
Windows Update Standalone Installer wusa
WMI Management wmimgmt
WMI Tester wbemtest
WordPad write
XPS Viewer xpsrchvw
Access Screen Resolution page desk.cpl
Access Mouse properties main.cpl
Access Windows Action Center wscui.cpl
Access Network Adapters ncpa.cpl
Access Power Option powercfg.cpl
Access the Programs and Features Window appwiz.cpl
Access the System Properties sysdm.cpl
Access the Windows Firewall firewall.cpl
*You cannot run these commands from a command prompt or the search box.

As you can see, the Windows Run command is one of the best utilities you can find in Windows. Besides the commands shared above that first come to mind, there are many other commands to access different parts of Windows. So if you think that we missed any of your favorite Run commands, do share them in the comments below.

Оцените статью
Adblock
detector