Batch file/command to start a program through command line - windows

I have a program which I want to start using the command prompt and at the same time I want to pass 2 parameters to it.
So, for example, when I wanted to start my program I would open the command prompt (in XP: start > run, type cmd, press return) and then type:
c:\rand\anotherfolder\myprogram.exe 10 20
Since I know nothing about batch files, I'm asking two things:
Can I create a batch file to automatize this process?
If yes, how :D?

I'll edit this if you respond to my comment but if you want to simply execute this command via a batch file (and you know nothing about batch files):
Open a text editor (e.g.Notepad)
Type in your command (e.g. c:\rand\aotherfolder\myprogram.exe 10 20)
Save the file as mybatchfile.cmd
Double click the file (in Windows Explorer etc.)

Related

Use batch file to input letter to perform action in cmd

I have an .exe that runs in command prompt, it then asks me to press a letter to perform a task. I want a batch file that runs the .exe file and presses y to perform the action. This is what I have so far:
start cmd.exe /k ""C:\Users\mayes\Documents\Utilities\Macros\Second Keyboard Macros\Intercept\intercept\intercept.exe""
All what it does is open the .exe file. I need it to press y also.
Demonstration of what I want the batch file to do:
https://media.giphy.com/media/Ujsia9OeUqJuo/giphy.gif
So there is another much easier way, the program has built in arguments,
C:\Stack\intercept>intercept.exe /help
*** Keyboard Remapper v. 1
*** Based on Oblitum Interception http://oblita.com/Interception.html
Use /help for help on command-line options
Command line parameters:
/ini path oile.ini specify alternate config file (optional)
/apply non-interactive, apply filters on startup (optional)
C:\Stack\intercept>
if you type /help so just make a shortcut with a /apply and you're GOLDEN! it's a useful tip to check console applications for built in arguments and options by typing /help.
you can send keys with vb script witch can be run from batch.
Try this:
set shell = CreateObject("WScript.Shell")
shell.run"C:\Users\mayes\Documents\Utilities\Macros\Second Keyboard Macros\Intercept\intercept\intercept.exe"
WScript.Sleep 1500
shell.SendKeys"{Y}"
shell.SendKeys"{ENTER}"
save it as .vbs, and it you want to run it from batch you can use:
cscipt "nameoffile".vbs
hope it works for you!

WinSCP script file works in Windows 10 but not in Windows 7

I want to automate really simple ftp transfers with WinSCP (Example script file shown below. The real file would handle many files, but all simple stuff.)
open ftp://username:password#ftp.site.com/
option confirm off
cd remotedirectory
get file.csv
close
exit
A batch file containing:
winscp.com /script="staging get.txt"
opens a command prompt window and executes correctly in Windows 10, but in Windows 7 the command window opens and then immediately closes, and no files are transferred. WinSCP is in the path in both environments. I assume that a parameter or command is missing from one or the other file, but I don't know what it would be.
I was making a couple of small syntax errors. I couldn't see them because the command prompt window closed almost immediately, but the log file showed me what was happening and it was easy to fix. The lesson is - always create a log file.

Why does a program started by a batch file using command start not run while it runs via Windows Explorer?

::Checks if there is a JRE installed
start "%USERPROFILE%\Downloads\ConfCompiler\Tools\CheckJre.exe"
When I copy and paste the file location above into Windows Explorer it works fine. But the program does not run from the batch file I have created.
The purpose of CheckJre.exe is to create new keys inside of HKEY_CURRENT_USER.
The keys are created when I simply run it from Windows Explorer. But the keys are NOT created when running it from the batch file. The batch file just results in displaying a command prompt window with showing CheckJre.exe with full path in title bar.
Does anyone have a hint why?
Command start interprets the first double quoted string as title for the command line window to open. For all options of command start enter in a command prompt window either start /? or help start.
You need to explicitly specify a title in your batch file because of the double quoted string to run CheckJre.exe.
Use in batch file:
start "Check JRE" "%USERPROFILE%\Downloads\ConfCompiler\Tools\CheckJre.exe"

Is it possible to make a batch file launch a separate batch file

I have a elevated batch file and I want it to execute a different batch file in a separate window I need to know if it is possible and how to do it. Can any one help.
Yes, if you want to launch a file, say sample.bat, you can use
start "Title" cmd /c sample.bat
Title is the title text I want to display for the new window.
You can see the details in Documentation
Enter a START command in an existing command shell, and specify CMD as the command to execute.

How to use a batch file so that results remain visible on completion

I run batch files and they exit immediately. I dont want that to happen so that i can see my output. Can someone tell me how to make this happen ?
I use windows 7.
Put this on the very last line of the Batch:
cmd /k
Adding pause is a good answer. Here are some other ways as well..
Rather than double-clicking on them to execute you can run from a command line:
Press the windows key + r (this opens the "run" window)
Type: cmd into the text input and press enter (or click ok)
Change to the directory that contains the batch file, e.g: cd c:\scripts\foo
Execute the batch file by typing it's name and pressing enter, e.g: somename.bat
If there is a lot of output and it scrolls off the screen you can direct the output to a text file instead like so:
somename.bat > output_filename.txt
Then you can open the 'output_filename.txt' file in any text editor to view/search all of the output. This is better than pause when there more output than what is available in the scrollback.
Add the pause command at the end of your batch file. This waits for you to key something in.
(The nice thing is that if you're running the batch file from a non-interactive process, such as a automated build system or scheduled task, the pause is simply skipped.)
The help message for pause is:
C:\>help pause
Suspends processing of a batch program and displays the message
Press any key to continue . . .
If there is lots of output and you can't scroll far enough back, adjust the screen buffer height of the command window. This can be done via right-click on the c:\ icon go to properties -> layout:

Resources