Start – Start a program – Windows CMD –

Errorlevels

If the command is successfully started ERRORLEVEL =unchanged, typically this will be 0 but if a previous command set an errorlevel, that will be preserved (this is a bug).
If the command fails to start then ERRORLEVEL = 9059
START /WAIT batch_file – will return the ERRORLEVEL specified by EXIT

Examples

Run a minimised Login script: START “My Login Script” /Min Login.cmd

Start a program and wait for it to complete before continuing: START “” /wait autocad.exe

Open a file with a particular program:START “” “C:Program FilesMicrosoft OfficeWinword.exe” “D:Docsdemo.txt”

Open Windows Explorer and list the files in the current folder (.) :C:anyolddirectory> START .

For parameters

The FOR command creates parameter variables which are identified with a letter rather than a number (e.g. %%G).
The Parameter Expansions described above can also be applied to these.
To avoid confusion between the two sets of letters, avoid using the letters (a, d, f, n, p, s, t, x, z) as FOR parameters or just choose a FOR parameter letter that is UPPER case.
So for example in a reference like %%~fG the %%G is the FOR parameter, and the ~f is the Parameter Expansion.

Examples:

Pass parameters from one batch to another:

 MyBatch.cmd SMITH 100

Or as part of a CALL :

 CALL MyBatch.cmd SMITH 100

Get the file size of C:demosample.xlsx using the %~z parameter extension:

How do i run a java program from the command line on windows?

Let’s say your file is in C:mywork

Run Command Prompt

C:> cd mywork

This makes C:mywork the current directory.

C:mywork> dir

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

C:mywork> set path=%path%;C:Program FilesJavajdk1.5.0_09bin

This tells the system where to find JDK programs.

C:mywork> javac filenamehere.java

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

C:mywork> dir

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

C:mywork> java filenamehere

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!

Install a windows service using a windows command prompt?

Open Visual studio and select new project by selecting Windows Service template in Windows Desktop tab. Than copy following code into your service_name.cs file.

using System.Diagnostics;
using System.ServiceProcess;
namespace TimerService
{ public partial class Timer_Service : ServiceBase { public Timer_Service() { InitializeComponent(); } static void Main() { if (System.Diagnostics.Debugger.IsAttached) { Timer_Service service = new Timer_Service(); service.OnStart(null); } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Timer_Service() }; ServiceBase.Run(ServicesToRun); } } protected override void OnStart(string[] args) { EventLog.WriteEvent("Timer_Service", new EventInstance(0, 0, EventLogEntryType.Information), new string[] { "Service start successfully." }); } protected override void OnStop() { EventLog.WriteEvent("Timer_Service", new EventInstance(0, 0, EventLogEntryType.Information), new string[] { "Service stop successfully." }); } }
}

Right-Click on service_name.cs file and open designer of service. than right-click and select Add Installer. than right-click on serviceProcessInstaller1 and change its property value of Account from User to Local System.

Remove static void main method from Program.cs file.
Than save and Build your project.

NOTE: goto binDdebug folder of your project folder. Than open Properties of your service_name.exe file. Than goto Compatibility tab. Than click on Change Settings For All Users.

Select option Run this program as an administrator.

Now, You have to open CommandPromt as Administrator.
After open, set directory to where your InstallUtil.exe file is placed.
for ex: C:WindowsMicrosoft.NETFramework64v4.0.30319.
now write the following command:

C:WindowsMicrosoft.NETFramework64v4.0.30319>InstallUtil.exe -i C:TimerServiceTimerServicebinDebugTimerService.exe

Note: -i is for install he service and -u for Unsinstall.

:/>  Как узнать сколько слотов оперативной памяти на компьютере на windows 7

after -i set the write the path where you want to install your service.

now write the command in CommandPromt as follows:

C:TimerServiceTimerServicebinDebug>net start service_name

Note: use stop for stop the Service.

Now, open ViewEventLog.exe. Select Windows Logs>Application. There you can check your Service’s log by start and stop the service.

Maximum line length

The maximum length of any command line (or variable) within CMD is 8191 characters.

Multiprocessor systems

Processor affinity is assigned as a hex number but calculated from the binary positions (similar to NODRIVES)

Hex Binary        Processors
 1 00000001 Proc 1 
 3 00000011 Proc 1 2
 7 00000111 Proc 1 2 3
 C 00001100 Proc 3 4 etc

Specifying /NODE allows processes to be created in a way that leverages memory locality on NUMA systems. For example, two processes that communicate with each other heavily through shared memory can be created to share the same preferred NUMA node in order to minimize memory latencies. They allocate memory from the same NUMA node when possible, and they are free to run on processors outside the specified node.

start /NODE 1 app1.exe
start /NODE 1 app2.exe

These two processes can be further constrained to run on specific processors within the same NUMA node.

In the following example, app1 runs on the low-order two processors of the node, while app2 runs on the next two processors of the node. This example assumes the specified node has at least four logical processors. Note that the node number can be changed to any valid node number for that computer without having to change the affinity mask.

start /NODE 1 /AFFINITY 0x3 app1.exe
start /NODE 1 /AFFINITY 0xc app2.exe

Parameter extensions

When an argument is used to supply a filename then the following
extended syntax can be applied:

we are using the variable %1 (but this works for any parameter)

%~f1 Expand %1 to a Fully qualified path name – C:utilsMyFile.txt

%~d1
Expand %1 to a Drive letter only – C:

%~p1 Expand %1 to a Path only e.g. utils this includes a trailing which will be interpreted as an escape character by some commands.

%~n1 Expand %1 to a file Name without file extension or path – MyFile
or if only a path is present, with no trailing backslash, the last folder
in that path.

%~x1 Expand %1 to a file eXtension only – .txt

%~s1 Change the meaning of f, n, s and x to reference the Short 8.3 name (if it exists.)

%~1   Expand %1 removing any surrounding quotes (“)

%~a1 Display the file attributes of %1

%~t1 Display the date/time of %1

%~z1 Display the file size of %1

%~$PATH:1 Search the PATH environment variable and expand %1 to the fully qualified name of the first match found.


The modifiers above can be combined:

%~dp1 Expand %1 to a drive letter and path only

%~sp1 Expand %1 to a path shortened to 8.3 characters

%~nx2 Expand %2 to a file name and extension only

Passing an argument to cmd.exe

I am attempting to ping a local computer from my C# program. To accomplish this, I’m using the following code.

System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo();
proc.FileName = @"C:windowssystem32cmd.exe";
proc.Arguments = @"""ping 10.2.2.125""";
System.Diagnostics.Process.Start(proc);

This opens a command-line window, but ping is not invoked. What is the reason?

:/>  Расширение isz, чем открыть окна 7 и 8, способы показать расширение файла и включить отображение формата в окнах 10

Passing by reference

In addition to passing numeric or string values on the command line, it is also possible to pass a variable name and then use the variable to transfer data between scripts or subroutines. Passing by reference is a slightly more advanced technique but can be particularly useful when the string contains characters that are CMD delimiters or quotes.

Run exe from bat file with command line arguments

the cmd line arguments are available to you in the form %0, %1, %2. With %~d0 in your current code, you are pulling the letter drive from argument %0.

This MS page can probably help you.

Weirdly enough, the link works if I click it, but does not for some users. Here’s the path if you’d like to copy paste it in your preferred browser. As you can see in the link, this is pulled from WindowsXP documentation, that may explain why the link is flaky at best.

https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true

EditIt seems like you want to call a program and pass that program a parameter as you are calling it. And you wish to start the program from a bat file. This is different than how I read your title.

Lets start with some basics… For reference sake, we’ll say the program I am using today is called GetToWork.exe

The program I am using GetToWork.exe offers me the ability to start it many different ways.

  • I can double click the exe which launches the program in a form
  • I can call the exe from CMD line and pass it parameters so it can do automated things without me having to do anything.
    1. I can pass the parameter --DontAskMeAnything if I want the program to do everything on its own.
    2. I can pass the parameter --AskMeForNewFile if I want the program to ask me before doing something to what it will consider to be a new file.
    3. I can pass it the parameter --DoItThisWayInstead if I want the parameter to do it a different way.

Now, I’m not the one who decided what parameters I can pass, nor what their result is going to be. In fact, the parameters were defined by the programmer who created the program. When he made the program, he decided that those were going to be the allowed parameters, and the actions related to them were going to be the actions that he decided. The programmer documented the parameters, and now I just want to use them because they make my life easier.

In order to trigger the parameter behaviors, I need to supply the said parameters to the program when I run it.

  • If I wanted to trigger --DontAskMeAnything I would write this command:

    GetToWork.exe –DontAskMeAnything

  • If I wanted to trigger --AskMeForNewFile, then I would write this command:

    GetToWork.exe –AskMeForNewFile

  • If GetToWork.exe allows multiple parameters, I would maybe write something like this:

    GetToWork.exe –AskMeForNewFile –DoItThisWayInstead

Now… back to you and your program. You are using a program called 10th-f-Downsampling.exe. We, I, don’t know that program. We, I, don’t know what the possible parameters are for that program. In order for you to know what you should pass, you’ll have to look up the documentation of that program. Sometimes just calling the exe with a /? is enough to get the parameter list. Again, this is dependant on the programmer who made the program as /? would simply be another parameter allowed by the programmer. And the result of the /? is usually to spit out the available parameters…

:/>  Ошибка Stop 0x0000007b: причины, пошаговая инструкция по исправлению

Lets break down your current code

xcopy %~d0dir-filesrecord*.* "%~dp0input" /Y
  • Here, the program you are calling is xcopy
  • The first parameter you are passing to xcopy is %~d0dir-filesrecord*.*
  • The second parameter you are passing is "%~dp0input"
  • The third parameter you are passing is /Y

If you were to go into command prompt and run this command xcopy /?, you’d get a chunk of text showing you how to call the program, along with a list of parameters that can be passed. Although parameters are often recognized by name… their name has little meaning because once in the program, the programmer may have coded it so that only parameter position matters, or position and name, or whatever other cocktail of business rules he obliged by. Though it’s important to follow the directions if directions are provided in the documentation.

Running cmd.exe with arguments from c#

You do not need to run cmd.exe as a process. All you need to do is run “c:tempdes.exe” with the arguments of “XXXX input.abcd output.zip”.

System.Diagnostics.Process.Start("c:tempdes.exe", "XXXX input.abcd output.zip"); 

Be sure to give your arguments the correct full-paths as well if they are different from the temp dir.

Running executable (.exe) files

When a file that contains a .exe header, is invoked from a CMD prompt or batch file (with or without START), it will be opened as an executable file. The filename extension does not have to be .EXE. The file header of executable files start with the ‘magic sequence’ of ASCII characters ‘MZ’ (0x4D, 0x5A) The ‘MZ’ being the initials of Mark Zibowski, a Microsoft employee at the time the file format was designed.

Terminology: command-line argument or parameter?

In mathematical terms a parameter is “a numerical or other measurable factor” so typically a number.

In programming terminology:
A parameter represents a value that the procedure expects you to pass when you call it.
An argument represents the actual value that you pass to a procedure.

In practice the phrases argument and parameter tend to be used interchangeably, CMD batch files do not perform any type checking.

Tokenization

Tokenization of the command line arguments is not always done by the cmd.exe shell. Most often the tokenization is done by the newly formed processes’ runtime, at the OS level, Windows passes a command line untokenized as a single string to the new process. You can read more about the low-level details of the batch language/cmd escaping from the excellent answers by jeb and dbenham on this StackOverflow question.

Use %~a1 to display the extended attributes of a file.

FOR’s %%~aI recognizes 9 NTFS file attributes. The expansion of a file attribute produces a series of 9 dashes, with each recognized attribute replacing a dash with a letter. A file with no recognized attributes or with none set will expand to 9 dashes like this: ———

 Attribute Expansion FILE_ATTRIBUTE_DIRECTORY d-------- FILE_ATTRIBUTE_READONLY -r------- FILE_ATTRIBUTE_ARCHIVE --a------ FILE_ATTRIBUTE_HIDDEN ---h----- FILE_ATTRIBUTE_SYSTEM ----s---- FILE_ATTRIBUTE_COMPRESSED -----c--- FILE_ATTRIBUTE_OFFLINE ------o-- FILE_ATTRIBUTE_TEMPORARY -------t- FILE_ATTRIBUTE_REPARSE_POINT --------l FILE_ATTRIBUTE_NORMAL --------- 

Other NTFS attributes not recognised by %%~aI can be read using FSUTIL usn command:
FILE_ATTRIBUTE_ENCRYPTED
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
FILE_ATTRIBUTE_SPARSE_FILE

Example: Expansion of a file with the Hidden and System attributes:
—hs—-