Batch file run through windows Task Scheduler - batch-file

I have created a Task Scheduler in windows to run a batch file. This batch file in turn is calling a cmd file. The cmd file is expecting some user input. Could you please let me know how I can provide input to this automatic process?
The message being shown is as follows:
[input] Where is your product view ?

... how I can provide input to this automatic process?
Suppose myCmd.cmd contains next line:
set /p "input=[input] Where is your product view ?"
Create file myInput.txt with appropriate answer as follows:
here is my product view
and in your batch file use < redirection as follows:
call myCmd.cmd<myInput.txt

I guess you're doing it like this:
ECHO Where is your product view ?
SET /p input=
So then you could simply set the input variable from a parameter instead:
SET input=%*
This would get the parameters when calling the BATCH-file. file.bat "Here is my product view."

Related

batch file to exe to auto run when computer start

I am a new programmer, i have created a batch file to open a website but i want that batch file to run when the computer starts.
Here's the code:
#echo off
:top
start iexplore.exe http://www.website.com
timeout 3
goto top
While i do think Arescet's answer will work, i am more in favor of using Windows' Task Scheduler.
Simply create a new task :
Assign it's trigger to be At Startup :
and add a new action to Start a program giving it the path to your batch file:
I believe this is a cleaner approach which also provides you with logging and history should you decide to do more things in your batch file later on
Type run into windows search, type shell:startup in the prompt, press enter, Then, create a shortcut of your program, and move the shortcut into the startUp folder.
On note of your code, the start command should have a blank title as "", and quotes around the application name and parameters passed, like:
start "" "iexplore.exe" "http://www.website.com"

Batch file invoked file details

I invoke a batch file from my own extension file type.In batch file i will show the details of invoking file. I know by passing parameters when invokation we will pass it and we will get by "%~sn1" OR "%1" OR "%~nx1". But i need without passing parameters.
Sample Example
My batch file code looks like this(main.bat)
#ECHO on
set modelname=(here i want help)
java -Djava.library.path="C:\Program Files\Internet Explorer" -Xms1024m -Xmx1024m -jar dist/XYZ.jar -models %modelname%
exit
If i click "Kitchen.xyz" then it'll invoke my batch file "main.bat". Now i want set "modelname" as "Kitchen.xyz". If i click "LivingRoom.xyz" ,:modelname" set as "LivingRoom.xyz".
Can anyone help please...
Thanks
You will need to change the Windows Registry associated with the file type of .xyz
[HKEY_CLASSES_ROOT\.xyz\shell]
[HKEY_CLASSES_ROOT\.xyz\shell\Name Of Your Command]
#="&Name Of Your Command"
[HKEY_CLASSES_ROOT\.xyz\shell\Name Of Your Command\command]
#="\"C:\\Path\\To\\Your\\Batch\\File\\main.bat\" \"%1\""
Save that text in a .reg file and execute it to apply the registry changes. Then when you right click .xyz files, "Name Of Your Command" will be one of the options and possibly the default option which would run when double clicked.
Then your main.bat still needs to accept one parameter and assign it to modelname.
You could also do that programatically with the REG command, but regardless of which method you use to set things up, something needs to be run to setup each machine you want to do this on.

Is it possible to create a batch file that will call another batch file at some point and also supply it with a sequence of inputs

I have a batch file (lets say "test.bat"). Now when we run this test.bat it asks for user inputs during it's execution, For ex. user credentials and then shows a menu. The user can choose an option from the menu by entering a value after which the script will ask him for a lot more product specific details.
Question:
I need to call this test.bat inside another batch file and whenever test.bat requires user inputs my batch script should be able to provide a some inputs (a known sequence of menu options and inputs).
Is there anyway I can achieve this?
To call another batch file, I refer this link:
Several ways to call a windows batch file from another one or from prompt. Which one in which case?
To get user inputs:
Echo off
set /p x=path name:
echo path is %x%
pause

create a Batch file with a file path as an input argument

I need to create a batch file which will run a program (which has been created in C#.Net) and also take a path of a text file as an input.
Not quite sure, how to achieve this.
So far, I have the below command working,
C:\>Folder Path to executable>xxxx.exe -console
-console is my predefined command argument to run this program in console mode.
The part until running the program from the console, with -console, works perfectly fine with a hard coded file path. However, I want to give the functionality to the user to give the file path as they want and create a batch file for the same command. Everytime user can update the batch file with new text file path and simply run it.
Thanks,
Are you just wanting to use the -console parameter? Are there any other parameters you wanted to pass in?
If wanting just what you have in your snippet, Save the following into a batch file. (e.g. StartMyProgram.bat)
start "C:\Folder path to executable\xxxx.exe" -console
See start /? for help and more options.
You need to add %~1 to your script: C:\Path\to\executable\xxxx.exe -console %~1
Now you can call it like this: StartMyApp.cmd C:\Docs\readme.txt
%~1 contains the full path of the text-file. You could also ensure that only text-files are passed to your application:
if "%~x1"==".txt" (
C:\Path\to\executable\xxxx.exe -console %~1
) else (
echo Not a textfile! & pause
)

DOS batch files: How to write to the prompt and stay in the same line to input text

I like to know if there is a way to read the user input inside a batch file, because i have a file named: "fif.bat" that recives two parameters (just call them paramA and paramB) so i execute the file like this:
fif paramA paramB
I have to change paramA every month, but i call this file lot of times so i like to open a console and have printed this:
fif paramA
So i only have to write paramB and change paramA when i want it.
PD: paramA is very large so it's very helpful if i can have it there instead of writing every time. And i don't want to make another batch file to call fif whit paramA.
I think this might be what you're looking for:
#ECHO OFF
SET /p paramA=Parameter A:
ECHO you typed %paramA%
PAUSE
Line one stops commands in batch file from being echoed to the console
Line two prompts the user with "Parameter A:" and waits for user to enter a value and press enter. The value goes into a variable called paramA.
Line three echoes the value of the variable paramA to the console
Line four waits for the user to hit any key.
Note that the SET /p command does not work on every version of windows, I beleive it was introduced in 2000, but I could be wrong on the version.
You can prompt for user input in a batch file using SET /P for example:
SET /P paramB="Prompt String: "

Resources