Windows command line run in background

In linux you can use command & to run command on the background, the same will continue after the shell is offline. I was wondering is there something like that for windows…

In linux you can use command & to run command on the background, the same will continue after the shell is offline. I was wondering is there something like that for windows…

Josh Withee's user avatar

Josh Withee

9,1963 gold badges40 silver badges57 bronze badges

asked Jan 9, 2014 at 21:08

Louis's user avatar

4

I believe the command you are looking for is start /b *command*

For unix, nohup represents ‘no hangup’, which is slightly different than a background job (which would be *command* &. I believe that the above command should be similar to a background job for windows.

answered Jan 9, 2014 at 21:13

Oeste's user avatar

OesteOeste

1,0012 gold badges7 silver badges13 bronze badges

3

I’m assuming what you want to do is run a command without an interface (possibly automatically?). On windows there are a number of options for what you are looking for:

  • Best: write your program as a windows service. These will start when no one logs into the server. They let you select the user account (which can be different than your own) and they will restart if they fail. These run all the time so you can automate tasks at specific times or on a regular schedule from within them. For more information on how to write a windows service you can read a tutorial online such as (http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx).

  • Better: Start the command and hide the window. Assuming the command is a DOS command you can use a VB or C# script for this. See here for more information. An example is:

    Set objShell = WScript.CreateObject("WScript.Shell")
    objShell.Run("C:yourbatch.bat"), 0, True
    

    You are still going to have to start the command manually or write a task to start the command. This is one of the biggest down falls of this strategy.

  • Worst: Start the command using the startup folder. This runs when a user logs into the computer

Hope that helps some!

Community's user avatar

answered Jan 9, 2014 at 21:14

drew_w's user avatar

drew_wdrew_w

10.2k4 gold badges28 silver badges49 bronze badges

2

Use the start command with the /b flag to run a command/application without opening a new window. For example, this runs dotnet run in the background:

start /b dotnet run

You can pass parameters to the command/application too. For example, I’m starting 3 instances of this C# project, with parameter values of x, y, and z:

enter image description here

To stop the program(s) running in the background: CTRL + BREAK

In my experience, this stops all of the background commands/programs you have started in that cmd instance.

According to the Microsoft docs:

CTRL+C handling is ignored unless the application enables CTRL+C processing. Use CTRL+BREAK to interrupt the application.

Community's user avatar

answered Oct 23, 2019 at 20:52

Josh Withee's user avatar

Josh WitheeJosh Withee

9,1963 gold badges40 silver badges57 bronze badges

You should also take a look at the at command in Windows. It will launch a program at a certain time in the background which works in this case.

Another option is to use the nssm service manager software. This will wrap whatever command you are running as a windows service.

UPDATE:

nssm isn’t very good. You should instead look at WinSW project. https://github.com/kohsuke/winsw

answered Sep 11, 2016 at 3:18

Nicholas DiPiazza's user avatar

Nicholas DiPiazzaNicholas DiPiazza

9,60511 gold badges77 silver badges143 bronze badges

If you take 5 minutes to download visual studio and make a Console Application for this, your problem is solved.

using System;
using System.Linq;
using System.Diagnostics;
using System.IO;

namespace BgRunner
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Starting: " + String.Join(" ", args));
            String arguments = String.Join(" ", args.Skip(1).ToArray());
            String command = args[0];

            Process p = new Process();
            p.StartInfo = new ProcessStartInfo(command);
            p.StartInfo.Arguments = arguments;
            p.StartInfo.WorkingDirectory = Path.GetDirectoryName(command);
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.UseShellExecute = false;
            p.Start();
        }
    }
}

Examples of usage:

BgRunner.exe php/php-cgi -b 9999
BgRunner.exe redis/redis-server --port 3000
BgRunner.exe nginx/nginx

answered Feb 14, 2021 at 3:19

Afterparty's user avatar

3

It’s unimaginable that after a decade that Windows still doesn’t have a decent way to run commands in background.

start /B command is the most given answer, but the command will be closed when the terminal closed.

Now, Windows 10 have a built-in(you have to install it mannually though) ssh server. you can run

ssh username@localhost "my_backgroud_command --params"

and then CTRL C, close the terminal, the command will continue to run in background.

This is the most decent way I have found so far.
Although not decent enough, because you have to install and configure the ssh server first.

answered Jan 28, 2022 at 4:44

Gary Allen's user avatar

Gary AllenGary Allen

3013 silver badges11 bronze badges

1

An option I use frequently when I need to run a simple command, or set of commands, in the background and then log off, is to script the command(s) (BAT, CMD, PowerShell, et al. … all work fine) and then execute the script using Windows native Task Scheduler. Jobs that are executed from the Task Scheduler do not die when you log off. Task Scheduler jobs can be configured to run as «hidden» i.e. the command prompt window will not be displayed. This script + Task Scheduler is a great alternative rather than developing an executable (e.g. yadda.exe) in your favorite development environment (e.g. Visual Studio) when the task at hand is simple and writing a console application to execute a simple command or two would be «overkill» i.e. more work than it’s worth.

Just my two cents.

Cheers!

answered Jul 21, 2022 at 21:06

InTech97's user avatar

On a windows server here, use a title (in double brackets) , otherwise it will not «release» :

start «» «chrome.exe —parameters» && echo truc

answered Nov 7, 2022 at 15:48

Bastien Gallienne's user avatar

How can I execute a windows command line in the background, without it interacting with the active user?

slhck's user avatar

slhck

219k68 gold badges591 silver badges578 bronze badges

asked Oct 12, 2010 at 6:09

Mohammad AL-Rawabdeh's user avatar

3

Your question is pretty vague, but there is a post on ServerFault which may contain the information you need. The answer there describes how to run a batch file window hidden:

You could run it silently using a Windows Script file instead. The Run
Method allows you running a script in invisible mode. Create a .vbs
file like this one

Dim WinScriptHost
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "C:Scheduled Jobsmybat.bat" & Chr(34), 0
Set WinScriptHost = Nothing

and schedule it. The second argument in this example sets the window
style. 0 means «hide the window.»

Tobias Kienzler's user avatar

answered Oct 12, 2010 at 6:30

nhinkle's user avatar

2

This is a little late but I just ran across this question while searching for the answer myself and I found this:

START /B program

which, on Windows, is the closest to the Linux command:

program &

From the console HELP system:

C:>HELP START

Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
      [command/program] [parameters]

    "title"     Title to display in window title bar.
    path        Starting directory.
    B           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.

One problem I saw with it is that you have more than one program writing to the console window, it gets a little confusing and jumbled.

To make it not interact with the user, you can redirect the output to a file:

START /B program > somefile.txt

answered May 3, 2013 at 14:28

Novicaine's user avatar

NovicaineNovicaine

3,7012 gold badges11 silver badges2 bronze badges

11

I suspect you mean: Run something in the background and get the command line back immediately with the launched program continuing.

START "" program

Which is the Unix equivalent of

program &

slhck's user avatar

slhck

219k68 gold badges591 silver badges578 bronze badges

answered Sep 30, 2011 at 11:44

Paul Douglas's user avatar

8

START /MIN program 

the above one is pretty closer with its Unix counterpart program &

answered Sep 13, 2012 at 6:55

Siva Sankaran's user avatar

You can use this (commented!) PowerShell script:

# Create the .NET objects
$psi = New-Object System.Diagnostics.ProcessStartInfo
$newproc = New-Object System.Diagnostics.Process
# Basic stuff, process name and arguments
$psi.FileName = $args[0]
$psi.Arguments = $args[1]
# Hide any window it might try to create
$psi.CreateNoWindow = $true
$psi.WindowStyle = 'Hidden'
# Set up and start the process
$newproc.StartInfo = $psi
$newproc.Start()
# Return the process object to the caller
$newproc

Save it as a .ps1 file. After enabling script execution (see Enabling Scripts in the PowerShell tag wiki), you can pass it one or two strings: the name of the executable and optionally the arguments line. For example:

.hideproc.ps1 'sc' 'stop SomeService'

I confirm that this works on Windows 10.

Tobias Kienzler's user avatar

answered Sep 1, 2016 at 22:20

Ben N's user avatar

Ben NBen N

39.4k17 gold badges137 silver badges174 bronze badges

2

This is how my PHP internal server goes into background. So technically it should work for all.

start /B "" php -S 0.0.0.0:8000 &

Thanks

answered Jul 9, 2018 at 4:30

Suyash Jain's user avatar

Suyash JainSuyash Jain

2763 silver badges9 bronze badges

A related answer, with 2 examples:

  1. Below opens calc.exe:

call START /B «my calc» «calc.exe»

  1. Sometimes foreground is not desireable, then you run minimized as below:

call start /min «n» «notepad.exe»

call START /MIN «my mongod» «%ProgramFiles%MongoDBServer3.4binmongod.exe»

Hope that helps.

Community's user avatar

answered Aug 9, 2017 at 5:08

Manohar Reddy Poreddy's user avatar

7

If you want the command-line program to run without the user even knowing about it, define it as a Windows Service and it will run on a schedule.

answered Sep 30, 2011 at 14:00

CarlF's user avatar

CarlFCarlF

8,8163 gold badges24 silver badges40 bronze badges

2

I did this in a batch file:
by starting the apps and sending them to the background. Not exact to the spec, but it worked and I could see them start.

rem   Work Start Batch Job from Desktop
rem   Launchs All Work Apps
@echo off
start "Start OneDrive" "C:UsersusernameAppDataLocalMicrosoftOneDriveOneDrive.exe"
start  "Start Google Sync" "C:Program FilesGoogleDriveGoogleDriveSync.exe"
start skype
start "Start Teams" "C:UsersusernameAppDataLocalMicrosoftTeamscurrentTeams.exe"
start Slack
start Zoom
sleep 10
taskkill /IM "explorer.exe"
taskkill /IM "teams.exe"
taskkill /IM "skype.exe"
taskkill /IM "slack.exe"
taskkill /IM "zoom.exe"
taskkill /IM "cmd.exe"
@echo on

killing explorer kills all explorer windows, I run this batch file after start up, so killing explorer is no issue for me.
You can seemingly have multiple explorer processes and kill them individually but I could not get it to work.
killing cmd.exe is to close the CMD window which starts because of the bad apps erroring.

answered Apr 10, 2021 at 10:22

TheArchitecta's user avatar

2

You can use my utility. I think the source code should be self explanatory. Basically CreateProcess with CREATE_NO_WINDOW flag.

answered Aug 17, 2022 at 15:19

ScienceDiscoverer's user avatar

just came across this thread
windows 7 , using power shell, runs executable’s in the background , exact same as unix filename &

example: start -NoNewWindow filename

help start

NAME
Start-Process

SYNTAX
Start-Process [-FilePath] [[-ArgumentList] ] [-Credential ] [-WorkingDirectory
] [-LoadUserProfile] [-NoNewWindow] [-PassThru] [-RedirectStandardError ] [-RedirectStandardInput
] [-RedirectStandardOutput ] [-Wait] [-WindowStyle {Normal | Hidden |
Minimized | Maximized}] [-UseNewEnvironment] []

Start-Process [-FilePath] <string> [[-ArgumentList] <string[]>] [-WorkingDirectory <string>] [-PassThru] [-Verb
<string>] [-Wait] [-WindowStyle <ProcessWindowStyle> {Normal | Hidden | Minimized | Maximized}]
[<CommonParameters>]

ALIASES
saps
start

answered Jul 13, 2015 at 23:29

jerry's user avatar

1

Unfortunately I do not think that this is possible.

You can do this in a Windows Scripting Host script, with something like:

Set oShell = WScript.CreateObject("WScript.Shell")
Set oProc = oShell.Run "<your command here>",0,True

Where the «0» states that the resulting window should be hidden (for other options, see the documentation at http://msdn.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx) and the «true» states that you want to wait for the command to complete before your script carries on.

It would be a simple exercise to wrap this up in a generic «run this command hidden» script that you could use from the command line.

If you have Microsoft’s new new PowerShell installed, then there may be an easier way to do this (I’ve not worked with PowerShell yet).

If you are happy to have the window minimised then you can do that with the «start» command that other mention. Unfortunately the «/B» option (which sounds like it is what you want) is only for commands and it doesn’t stop windowed applications appearing on screen.

Note: which ever of the above you use to you start a program with a hidden/minimised main window, there is nothing to stop it creating new windows that are visible, or bringing the main window up and into focus, once it is running.

If we want to run a Windows command line task in background, like UNIX’s «&» do, we can do the following from the Windows command line,


start /B cmd /C call program [arg1 [...]]

We explain each part as follows,

  • /B is the command line option to the start command. The documentation of the command start states the following,

    • /B. 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.
  • cmd is the program to run from the command line, i.e., C:WindowsSystem32cmd.exe
  • /C is the command line option given to cmd. The manual states,

    • /C. Carries out the command specified by string and then terminates
  • call is a command to cmd, it is to «call one batch program from another.» The program does not have to be batch program, and can be any executable file.
  • program is the program to be called by the call command.
  • arg1 [...] are optional one or more command line arguments given to program.

For example, if we’d like to to run a Java program HelloWorld from the command line in background, we would do,


start /B cmd /C call java HelloWord

A Unix equivalent of this command would be java HelloWorld &.

    Table of contents

  • Execute a gui application from the command line and send it to the background
  • Can I run a GUI program in the background on the windows command-line?
  • Run GUI program in background in Windows 10
  • Run Linux GUI apps on the Windows Subsystem for Linux
  • How to run a command in the background on Windows?
  • Do GUI based application execute shell commands in the background?
  • How to cleanly launch a GUI app via the Terminal?

Execute a gui application from the command line and send it to the background

People also askHow do I run a program in the background while running?How do I run a program in the background while running?Use CTRL+BREAK to interrupt the application. You should also take a look at the at command in Windows. It will launch a program at a certain time in the background which works in this case. Another option is to use the nssm service manager software. This will wrap whatever command you are running as a windows service.cmd — How to run a command in the background on Windows

#!/bin/bash

nohup $1 > /dev/null 2>&1 &
gedit &
disown %1
alias gnome-run=<path>/my-awesome-script.sh
xdg-open /usr/share/applications/gedit.desktop

Can I run a GUI program in the background on the windows command-line?

The program is started as a separate task that can be run in the foreground or background. Unfortunately I do not think that this is possible. You can do this in a Windows Scripting Host script, with something like: Set oShell = WScript.CreateObject («WScript.Shell») Set oProc = oShell.Run «<your command here>»,0,True.

emacs foo.txt &
Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/AFFINITY <hex affinity>] [/WAIT] [/B] [command/program]
      [parameters]

    "title"     Title to display in  window title bar.
    path        Starting directory
    B           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
    I           The new environment will be the original environment passed
                to the cmd.exe and not the current environment.
    MIN         Start window minimized
    MAX         Start window maximized
    SEPARATE    Start 16-bit Windows program in separate memory space
    SHARED      Start 16-bit Windows program in shared memory space
    LOW         Start application in the IDLE priority class
    NORMAL      Start application in the NORMAL priority class
    HIGH        Start application in the HIGH priority class
    REALTIME    Start application in the REALTIME priority class
    ABOVENORMAL Start application in the ABOVENORMAL priority class
    BELOWNORMAL Start application in the BELOWNORMAL priority class
    AFFINITY    The new application will have the specified processor
                affinity mask, expressed as a hexadecimal number.
    WAIT        Start application and wait for it to terminate
start emacs foo.txt
start  /B "" "D:devsublime3Sublime Text 3subl.exe" "-s" "%USERPROFILE%Dropboxdevapis*.markdown" 
run window+R->taskschd.msc->add a task
Set oShell = WScript.CreateObject("WScript.Shell")
Set oProc = oShell.Run "<your command here>",0,True
sc create ngrok "cmd /c "c:tmpngrok.exe" http 80" type=own type=interactive

Run GUI program in background in Windows 10

Batch files execute commands line by line. The execution of each command must complete before the next command can be executed. Your executable is still running so the exit command will not execute in the batch file. The work around is to use the START command in your batch file. start «Title» «C:path to programfoo.exe».

@echo off
"C:UserskiliaAppDataRoamingMicrosoftWindowsStart MenuProgramsStartupdpclat.exe"
exit
Start "" "C:UserskiliaAppDataRoamingMicrosoftWindowsStart MenuProgramsStartupdpclat.exe"
nircmd exec hide X:PathToBat

Can I run a GUI program in the background on the windows command-line? – Server Fault

The best answers to the question “Can I run a GUI program in the background on the windows command-line?” in the category Server Fault. QUESTION: For example, in Bash, I can do this: The command to launch programs from the command-line in Windows is “start”

emacs foo.txt &
start emacs foo.txt
Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/AFFINITY <hex affinity>] [/WAIT] [/B] [command/program]
      [parameters]

    "title"     Title to display in  window title bar.
    path        Starting directory
    B           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
    I           The new environment will be the original environment passed
                to the cmd.exe and not the current environment.
    MIN         Start window minimized
    MAX         Start window maximized
    SEPARATE    Start 16-bit Windows program in separate memory space
    SHARED      Start 16-bit Windows program in shared memory space
    LOW         Start application in the IDLE priority class
    NORMAL      Start application in the NORMAL priority class
    HIGH        Start application in the HIGH priority class
    REALTIME    Start application in the REALTIME priority class
    ABOVENORMAL Start application in the ABOVENORMAL priority class
    BELOWNORMAL Start application in the BELOWNORMAL priority class
    AFFINITY    The new application will have the specified processor
                affinity mask, expressed as a hexadecimal number.
    WAIT        Start application and wait for it to terminate
start  /B "" "D:devsublime3Sublime Text 3subl.exe" "-s" "%USERPROFILE%Dropboxdevapis*.markdown" 
run window+R->taskschd.msc->add a task

Run Linux GUI apps on the Windows Subsystem for Linux

Select Start, type PowerShell, right-click Windows PowerShell, and then select Run as administrator. Enter the WSL update command: PowerShell. Copy. wsl —update. You will need to restart WSL for the update to take effect. You can restart WSL by running the shutdown command in PowerShell. PowerShell. Copy.

wsl --install -d Ubuntu
wsl --update
wsl --shutdown
sudo apt update
sudo apt install gedit -y
sudo apt install gimp -y
sudo apt install nautilus -y
sudo apt install vlc -y
sudo apt install x11-apps -y

How to run a command in the background on Windows?

Worst: Start the command using the startup folder. This runs when a user logs into the computer; Hope that helps some! Use the start command with the /b flag to run a command/application without opening a new window. For example, this runs dotnet run in the background: start /b dotnet run You can pass parameters to the command/application too.

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("C:yourbatch.bat"), 0, True
start /b dotnet run

Do GUI based application execute shell commands in the background?

Do these GUI-based applications also execute the same command in the background? Yes and no. They write to the dconf database of settings, but they could be using different ways to do so. Programs written in Python will likely use the gi.repository.Gio module (I know because I use it a lot) or they can instead use gsettings as an external command by calling …

gsettings set com.canonical.Unity.Launcher launcher-position Bottom
$ ls 
dconf watch /
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import subprocess

key = ["com.canonical.Unity.Launcher", "launcher-position"]

class ToggleWin(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Toggle")
        button = Gtk.Button("Toggle launcherposition")
        button.connect("clicked", self.toggle)
        self.add(button)

    def toggle(self, *args):
        # read the current setting on launcher position
        current = subprocess.check_output([
            "gsettings", "get", key[0], key[1]
            ]).decode("utf-8").strip()
        # toggle to the other option
        new = "'Left'" if current == "'Bottom'" else "'Bottom'"
        subprocess.Popen([
            "gsettings", "set", key[0], key[1], new
            ])

def delete_actions(*args):
    Gtk.main_quit()
    
def miniwindow():
    window = ToggleWin()
    window.connect("destroy", delete_actions)
    window.show_all()
    Gtk.main()

miniwindow()
  python3 /path/to/file.py
[Desktop Entry]
Name=Set launcherposition
Exec=zenity --info --text="Right- click to set launcher position"
Type=Application
StartupNotify=False
Icon=preferences-system

Actions=Launcher to bottom;Launcher on the left;

[Desktop Action Launcher to bottom]
Name=Launcher to bottom
# right click option to set launcher to bottom
Exec=gsettings set com.canonical.Unity.Launcher launcher-position Bottom

[Desktop Action Launcher on the left]
Name=Launcher on the left
# right click option to set launcher to left
Exec=gsettings set com.canonical.Unity.Launcher launcher-position Left

How to cleanly launch a GUI app via the Terminal?

Program already running Disown: disown -h is the way to go if you want to do that with an already running program (i.e. if you forgot to nohup it). You first have to stop it using Ctrl+Z. Then you can put in in the background using bg [jobId] (e.g. bg 1). You get a list of running jobs with their jobId using jobs.

$ gedit 
^Z
[1]+  Stopped                 gedit
$ jobs
[1]+  Stopped                 gedit
$ bg 1
[1]+ gedit &
$ disown -h %1
$ exit
nohup gedit &
$ (geany >/dev/null 2>&1 &)
echo './myprogram myoption1 myoption2' | at now
firefox &!
some-program </dev/null &>/dev/null &
# &>file is bash for 1>file 2>&1
#!/bin/bash
[ $# -eq 0 ] && {  # $# is number of args
  echo "$(basename $0): missing command" >&2
  exit 1
}
prog="$(which "$1")"  # see below
[ -z "$prog" ] && {
  echo "$(basename $0): unknown command: $1" >&2
  exit 1
}
shift  # remove $1, now $prog, from args
tty -s && exec </dev/null      # if stdin is a terminal, redirect from null
tty -s <&1 && exec >/dev/null  # if stdout is a terminal, redirect to null
tty -s <&2 && exec 2>&1        # stderr to stdout (which might not be null)
"$prog" "[email protected]" &  # [email protected] is all args
nohup gedit something
 $ xdg-open .
 $ xdg-open foo.pdf
$ xdg-open www.google.com
$ (nohup gedit 2>/dev/null &)
nohup gedit & exit
bash -i >/dev/null 2>&1 <<<'nohup gedit &'
$ (some-program &) &>/dev/null

# Examples:
$ (gedit &) &>/dev/null
$ (google-chrome &) &>/dev/null

Next Lesson PHP Tutorial

Download PC Repair Tool to quickly find & fix Windows errors automatically

Even though batch files are like vintage when it comes to operating systems, they are one of the best ways to get things done. If you are in a kind of work that asks you to run some pre-defined commands every day, the console windows are annoying, especially when you are sure they are perfect and will not make any mistake. This guide will learn how you can run Batch Files silently in background mode and hide the Console Window.

If you have a simple batch (.BAT) file that you want to run, you can create another batch file and type in the command mentioned below:

START /MIN CMD.EXE /C mysecondbatchfile.bat

There are two ways to execute it.

  • Run it from within the command prompt.
  • Create a shortcut on your desktop, and point it towards the bat file. Make sure to change the Properties of the shortcut as Start minimized.

Run batch files silently using a Scheduled Task

Windows has tons of features that are not used. The Task Scheduler is one of them. This feature allows you to run tasks in the background, periodically or every day. You can easily schedule a Batch file to run automatically using Scheduled Task with options available out of the box.

Here is the procedure to use it.

  • Type “Task Scheduler” in the Cortana box, and you should see the app listed. You can also choose to type “taskschd.msc” into the Run prompt (Win + R) to open it.
  • On the last pane on the right-hand side, look for an option that says Create Basic Task. Click on it to open.
  • It launches a wizard which will ask you
    • Name of Task with a description
    • When do you want to start the task? You can choose between Daily, Weekly, Monthly, OneTime, When the computer starts and so on.
    • Next, select a program, and it will offer to choose a program or script, add arguments, start in details, and so on.
  • Using this, you can add everything a bat file would need. In the end, select open properties window for further configuration.Run Batch Files silently
  • In the properties window, you can choose to run the program even when is the user is logged out to make sure your program is working round the clock. Make sure to choose Hidden.
  • Add admin privilege permission by selecting the “Run with highest privileges” box. Click OK when done,
  • To test, the task works exactly as you need it to, right-click and selecting Run.

Task Scheduler Properties for Batch File

Run Batch Files silently & hide the console window using freeware

1] Hidden Start or HStart

Hstart UI to run batch files silently

It’s a lightweight command-line utility that allows you to run console applications and batch files without any window, in the background. It can even handle UAC privilege elevation and also run multiple commands in parallel or in sync. The program offers a user interface that makes it easy to set things.

  • Drag, and drop the batch file onto the interface.
  • Choose options including hiding console windows, UAC, and so on.
  • You can also test it using test mode.
  • You can also add command-line options if needed.
  • Directly created shortcut and autostart entry from the interface

You can download it from here from ntwind.com

2] SilentCMD

If you are comfortable with the command line, i.e., typing and using a command prompt, SilentCMD offers tons of features and does our job as well. You can type in SilentCMD [path to .bat file] [arguments], and it gets the job done, quietly. Additionally, you can log in the output and errors into a text file.

SilentCMD [BatchFile [BatchArguments]] [Options]

Options:
    /LOG:file :: output status to LOG file (overwrite existing log)
   /LOG+:file :: output status to LOG file (append to existing log)
   /DELAY:seconds :: delay the execution of batch file by x seconds

You can download it from Github.

How to Make an executable file from a Batch Script?

Executables are probably the best way to run batch files along with an option to hide your script from everyone else. There are many options available to make an executable file from a Batch Script and making an EXE is very simple.  However, if your antivirus catches it, make sure to mark it safe as you are only using it for personal use.

Check out our detailed posts on the following subjects:

  • How to convert BAT to EXE file
  • You can script batch programs and compile them into an EXE file with Batch Compiler.
  • Convert VBS to EXE using an Online tool or VBScript converter software.

Incidentally, Slimm Bat To Exe Converter offers three types of modes including express, windowless, and custom.  You can download it from Softpedia.

These should be enough for you to create and run Batch Files silently on your Windows 11/10 PC. However, always test it before making them run quietly. You never want to lose your data because you didn’t test something properly.

What is @echo in a batch file?

Echo is the command that can display or suppress the output of commands that are executed from the BAT file. When you plan to run a natch file silently, use @echo off at the start of the file. You can also use it o display a message using echo <message>

Do BAT files need admin permission to execute?

BAT files only process or run commands; they do not need admin permission. However, if any of the commands that it tries to run requires admin permission, it will prompt you with UAC. That said, if you run the BAT file with admin permission, all the subsequent commands should execute with the same permission.

Ezoic

Ashish is a veteran Windows and Xbox user who excels in writing tips, tricks, and features on it to improve your day-to-day experience with your devices. He has been a Microsoft MVP (2008-2010).

Solution 1:

The command to launch programs from the command-line in Windows is «start»

Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/AFFINITY <hex affinity>] [/WAIT] [/B] [command/program]
      [parameters]

    "title"     Title to display in  window title bar.
    path        Starting directory
    B           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
    I           The new environment will be the original environment passed
                to the cmd.exe and not the current environment.
    MIN         Start window minimized
    MAX         Start window maximized
    SEPARATE    Start 16-bit Windows program in separate memory space
    SHARED      Start 16-bit Windows program in shared memory space
    LOW         Start application in the IDLE priority class
    NORMAL      Start application in the NORMAL priority class
    HIGH        Start application in the HIGH priority class
    REALTIME    Start application in the REALTIME priority class
    ABOVENORMAL Start application in the ABOVENORMAL priority class
    BELOWNORMAL Start application in the BELOWNORMAL priority class
    AFFINITY    The new application will have the specified processor
                affinity mask, expressed as a hexadecimal number.
    WAIT        Start application and wait for it to terminate

You may want to use the MIN option to start a program minimized

Solution 2:

I don’t know if it will be sufficient, but try

start emacs foo.txt

It will not go into background but it will rather start separate cmd.exe window for the command.


Solution 3:

HaHa,I successed ,To use sublime text3 as a server of markdown preview is my propose,after I closed sublime text’s window,i won’t work.
I’d try many methods,at last it works.
first,you should create a bat to start this program.

start  /B "" "D:devsublime3Sublime Text 3subl.exe" "-s" "%USERPROFILE%Dropboxdevapis*.markdown" 

sencond,run this bat by schedule task.

run window+R->taskschd.msc->add a task

add a trigger to run this bat according this schedule

add this bat as a operation to execute

This result is that it works to avoid to show sublime text window.and it work conflict with sublime text normally opened.

Maybe you had guessed ,I use OmniMarkupPreviewer plugin to preview markdown.I had fixed this bug(or not perfect feature) that it uses different view id every time.

on September 25, 2011

Start command can be used to run a command/batch file in another command window or to launch an application from command line.  Below you can find the command’s syntax and some examples.

Launch another command window:

start cmd

This command opens a new command prompt window.
Run a command in a separate window

Start command

This command opens a new command window and also runs the specified command. If the command is of a GUI application, the application will be launched with out any new command window.

Examples:
Launch new command window and run dir command.:

Start dir

Run a command in another window and terminate after command execution:

start cmd /c command

For example, to run a batch file in another command window and to close the window after batch file execution completes, the command will be:

Start cmd /c  C:mybatchfile.bat

Run the command in the same window:

Start /b command

Run a command in the background like we do using ‘&’ in Linux:

In Windows, we can do similar thing by using start command. But here it does not run in background. A new command window will be executing the specified command and the current window will be back to prompt to take the next command.

Start command
(or)
Start batchfile.bat

Launch a GUI application:

Start  application

For example, to launch internet explorer, we can use the below command.

Start iexplore

Open windows explorer in the current directory:

start .

If you like programming shell scripts for Windows, you might want to run your command prompt scripts in the background silently without actually opening the command prompt windows. This easily possible with a few lines of vbscript.

Why Run It Silently?

A silent prompt is great for scheduled tasks that won’t annoy you with a prompt or even prevent you from running 3D applications such as games. It’s also a great way for administrators to run some tasks in the background or hide activity regular users are not supposed to see. There are a bunch of reasons why they are necessary at times.

Want to own ultra-rare NFTs? Join Ultra.io For Rare NFTs and Play-to-Earn Games

Running command prompt in background silently

Using VBScript To Run CMD Script Silently

Here’s a little snippet of one of my command prompt scripts:


rundll32.exe %SystemRoot%system32shell32.dll,Control_RunDLL %SystemRoot%system32desk.cpl desk,@Themes /Action:OpenTheme /file:"C:WindowsResourcesThemeslandscapes.theme"

Let’s say you don’t want Windows 7 to open a command prompt window and run it silently, you can write a vbscript for that:

1. Step Open a notepad editor

2. Step Insert the following code:


Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN("E:scripts/themescript.bat", 0, True)
Set WshShell = Nothing

The 0 makes the shell script run silently.

3. Step Save your notepad file. When you save it add the extension .vbs and select All files from the dropdown as seen below:
Save VBScript

4. Step You can now schedule that cmd script and it will not open a command prompt window

This is very handy if you don’t want to be annoyed with dozens of command prompt windows when your scheduled tasks are running.

You might also want to know how to open the command prompt in Windows 8

Понравилась статья? Поделить с друзьями:
  • Windows command kill process command line
  • Windows com stopcode что это такое
  • Windows com stopcode что это значит
  • Windows com stopcode что делать код остановки
  • Windows com stopcode что делать bad system config info