160

I want to create a .bat file so I can just click on it so it can run:

svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service

Can someone help me with the structure of the .bat file?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
  • 1
    Possible duplicate of [How can I run a program from a batch file without leaving the console open after the program start?](https://stackoverflow.com/questions/324539/how-can-i-run-a-program-from-a-batch-file-without-leaving-the-console-open-after) – phuclv Feb 27 '18 at 13:54

11 Answers11

237

To start a program and then close command prompt without waiting for program to exit:

start /d "path" file.exe
abatishchev
  • 98,240
  • 88
  • 296
  • 433
67

You can use:

start "windowTitle" fullPath/file.exe

Note: the first set of quotes must be there but you don't have to put anything in them, e.g.:

start "" fullPath/file.exe
abatishchev
  • 98,240
  • 88
  • 296
  • 433
user2075928
  • 671
  • 5
  • 2
  • 10
    The 'first set of quotes' is merely the window title and is NOT required. It is however, best to specify the startup directory using /d `start /d "fullpath" file.exe` This ensures any dependent files are, e.g. a DLL, are found and loaded. – Tom Wilson Mar 16 '15 at 16:22
46

it is very simple code for executing notepad bellow code type into a notepad and save to extension .bat Exapmle:notepad.bat

start "c:\windows\system32" notepad.exe   

(above code "c:\windows\system32" is path where you kept your .exe program and notepad.exe is your .exe program file file)

enjoy!

abatishchev
  • 98,240
  • 88
  • 296
  • 433
shinukb
  • 469
  • 4
  • 2
30

Just put that line in the bat file...

Alternatively you can even make a shortcut for svcutil.exe, then add the arguments in the 'target' window.

GavinCattell
  • 3,863
  • 20
  • 22
8

A bat file has no structure...it is how you would type it on the command line. So just open your favourite editor..copy the line of code you want to run..and save the file as whatever.bat or whatever.cmd

MBoy
  • 704
  • 1
  • 7
  • 18
8

Just stick in a file and call it "ServiceModelSamples.bat" or something.

You could add "@echo off" as line one, so the command doesn't get printed to the screen:

@echo off
svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service
myplacedk
  • 1,574
  • 2
  • 14
  • 19
  • And instead of adding an `@echo off` as first line, you could simply add `@` at beginning of line you don't want to be echoed... – MensSana Nov 01 '18 at 13:24
7

If you want to be real smart, at the command line type:

echo svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service >CreateService.cmd

Then you have CreateService.cmd that you can run whenever you want (.cmd is just another extension for .bat files)

Stephan Bauer
  • 9,120
  • 5
  • 36
  • 58
kͩeͣmͮpͥ ͩ
  • 7,783
  • 26
  • 40
6

What's stopping you?

Put this command in a text file, save it with the .bat (or .cmd) extension and double click on it...

Presuming the command executes on your system, I think that's it.

Simon
  • 78,655
  • 25
  • 88
  • 118
4

As described here, about the Start command, the following would start your application with the parameters you've specified:

start "svcutil" "svcutil.exe" "language:cs" "out:generatedProxy.cs" "config:app.config" "http://localhost:8000/ServiceModelSamples/service"
  • "svcutil", after the start command, is the name given to the CMD window upon running the application specified. This is a required parameter of the start command.

  • "svcutil.exe" is the absolute or relative path to the application you want to run. Using quotation marks allows you to have spaces in the path.

  • After the application to start has been specified, all the following parameters are interpreted as arguments sent to the application.

Gipphe
  • 179
  • 9
3

If your folders are set to "hide file extensions", you'll name the file *.bat or *.cmd and it will still be a text file (hidden .txt extension). Be sure you can properly name a file!

Mark
  • 31
  • 1
1

Well, the important point it seems here is that svcutil is not available by default from command line, you can run it from the vs xommand line shortcut but if you make a batch file normally that wont help unless you run the vcvarsall.bat file before the script. Below is a sample

"C:\Program Files\Microsoft Visual Studio *version*\VC\vcvarsall.bat"
svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service
arkoak
  • 2,437
  • 21
  • 35