my batch file asking for input y/n. i run that batch file using CreateProcess() method. If i run my batch file with /y as commnad line, it not ask for input. e.g
run.bat /y
i want to run my batch file using CreateProcess() with command line /y,as above e.g, i don't know how to do this using CreateProcess() an i don't want to modify my batch file.
::CreateProcess(L"run.bat",NULL,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&startInfo,&procInfo )
, i also try this
::CreateProcess(L"run.bat",L"/y",NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&startInfo,&procInfo )
but,it not works. If anyone know how to do this,plz let me know.
::CreateProcess(L"run.bat",L"/y",NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&startInfo,&procInfo ) this works fine. it's my mistake i change in if part and my flow goes in else part. and i always change in my if part. thanks for quick reply.
Try this
::CreateProcess(L"cmd.exe", L"/c run.bat /y", NULL, NULL, TRUE, CREATE_NEW_CONSOLE,
NULL, NULL, &startInfo, &procInfo )
As it says on MSDN
To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the following arguments: /c plus the name of the batch file.
Related
in Windows 7 x64 SP1 I need to create a batch file (.bat) which keeps the cmd.exe console window open and has a specific title:
#ECHO OFF
title notepadtest
#ECHO ON
start "" /WAIT notepad
But this batch file keeps opening an infinite number of cmd.exe console windows in an unstoppable loop!
How can I create a batch file (.bat) which creates only ONE cmd.exe console window and keeps it open and has a specific title?
Please ensure that your batchfile is not named notepad.cmd or notepad.bat or anything like any system or external command. Name it something like mynotepad.cmd instead., then try this one please:
#echo off
title notepadtest
start "" /w notepad.exe
cmdline and batch files typically works like this. When a command is issued, it first checks the local path, where the script was launched from for the command, if not found, it will check your environment and system environment. So if you name a batchfile notepad.bat your batch is actually starting itself over and over, instead of finding notepad.exe in the environment variables.
Always name batch files something unique and not system/external command related.
Always use full executable name in a batch, like start "" /w notepad.exe and not start "" /w notepad
I have a windows batch file which i want to execute as a service. I have found app like alwaysRun but i want to use windows in-build app for this purpose. Can anyone please suggest.
My Use Case is : - I have a batch file which will be executing after every 10 secs. So i have created a normal batch file which calls this bat file and sleeps for 10 secs. So i want to make this second bat file as a service. So that it is called once and when the windows reboots.
This file should be called as a service.
#echo off
:begin
CALL dummyfile.bat
timeout /t 1
goto begin
Please suggest.
I would not do that. You could run the first batch file from a scheduled task.
OR
If you want it to run at startup,
As an example, on Windows 8 you could
Create a VBS file that will completely hide your batch file.
hideme.vbs
Set MyScript = CreateObject("WScript.Shell")
MyScript.Run "C:\wherever\script\is\batch.cmd", 0, False
It can be launched as cscript hideme.vbs
Then open Start / Run and type shell:startup and press enter. Paste a shortcut of the VBS file here.
This will let VBS file call the second batch file in hidden mode each time the PC starts up.
EDIT
In order to kill it, you need to create another batchfile which you can run to find the cmd.exe that is running in the background.
In your original batch file, create a title at the very beginning after #echo off
#echo off
title LOOP
:begin
CALL dummyfile.bat
timeout /t 1
goto begin
Now in your new batchfile, let's call it killLOOP.cmd you add this:
taskkill /F /FI "WindowTitle eq LOOP" /T
This will search for a process with Window title LOOP, then kill it. Just run it when you want to close it.
now in your
I executed batch file as a service, but it didn't work.
NSSM package resolved my problem. here are the steps to follow:
1- Download NSSM package
2- Add NSSM Directory path in Environment Variables Path
3- Execute command like:
nssm install Service_Name
3.1 After executing command mentioned in step 3, it will show a popup to provide
program file path. provide batch file path like "C:/Test/test.bat"
3.2 Click on install and now batch file will be executed as a window Service.
have you ever looked at the native Windows program called sc.exe ? It allows you to run a program as a service.
Here's some Microsoft documentation on it: https://support.microsoft.com/en-us/help/251192/how-to-create-a-windows-service-by-using-sc-exe
sc [Servername] Command Servicename [Optionname= Optionvalue...]
In particular, you could use the Create Command to create a new service:
Create
Creates a service (adds it to the registry).
So the simplest syntax would be something like:
sc Create myservice binPath=C:\some\path\to\myservice.bat
Okay, I have such a batchfile:
#title RUBY ;)
#set PATH=D:\Programming\Ruby22-x64\bin;%PATH%
#call cmd /K cd /D E:\RubyProgramming
that I use to facilitate running scripts without the need to navigate to the folder each time. The thing is that I usually run the very same command for hundreds of times for a given program that I am working on at any given time. For instance:
ruby rubyprogram.rb inputfile.txt outputfile.xml miscargument
Is there a way to make such a batch file that types in a command when you run it? Not executes, just type in, so that I press Enter to execute it and use ↑ up arrow to use it again in the cmd? I haven't been able to find a command that would allow this anywhere, but it would be useful if there was one.
The simplest would be to just create a new batch-file that executes that specific command:
#echo off
title RUBY ;)
set PATH=D:\Programming\Ruby22-x64\bin;%PATH%
cd /D E:\RubyProgramming
rubyprogram.rb inputfile.txt outputfile.xml miscargument
Alternatively, you could get the batch file to repeatedly ask for the command to run
#echo off
title RUBY ;)
set PATH=D:\Programming\Ruby22-x64\bin;%PATH%
cd /D E:\RubyProgramming
set RUBYCMD=rubyprogram.rb inputfile.txt outputfile.xml miscargument
:loop
echo.
REM line below ends with a space for neatness
set /p RUBYCMD=Enter ruby command (or 'Q' to exit) [%RUBYCMD%]:
if /i "%RUBYCMD%" == "q" goto :eof
%RUBYCMD%
goto :loop
No, batch files can't type or click anything. However, you can call scripts from a batch file which are written in other languages. For example, you cold write a VB or an AutoIt script, call it from your batch and make the new script "type" the command.
Take a look at this VB script:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%\notepad.exe"
WshShell.AppActivate "Notepad"
WshShell.SendKeys "hello world"
This will open notepad, focus the new window and type hello world. This way you can also start a new console or get the focus of an already started one and type your command. This code can be saved in a separate vb script file and called from your batch.
I have a registry key that calls a vbscript file as below.It will be triggered on selecting a Change Cursor option from right click on .cur file
"C:\Program Files\Cursor Manager\CustomCursor.vbs" "%1" 2
Below is the vbs file(CustomCursor.vbs)
Set objArgs = WScript.Arguments ' Create object.
CusorValue=objArgs(1)
Path=objArgs(0)
MsgBox CusorValue
MsgBox Path
But its not working.Its not showing any message
Its working when i am calling the script from command prompt like below.
"C:\Program Files\Cursor Manager\CustomCursor.vbs" "E:\new\CM v5\cursors new\more\Arrow.cur" 2
If the registry value is batch file its working
"C:\Program Files\Cursor Manager\CustomCursor.cmd" "%1" 2
Below is batch file(CustomCursor.cmd)
echo %1
echo %2
pause
But i can use batch file as it will show a command window,as it will show command window while executing script.
Please tell me a way to execute the vbs file from registry or atleast a way to run batch file in background.
Thank you
Change your registry to
"%windir%\system32\wscript.exe" "C:\Program Files\Cursor Manager\CustomCursor.vbs" "%1" 2
The problem is that invoking directly the script file makes windows search for the program to execute it and call the asociated executable with the script as argument, but in this process the rest of the arguments are discarded. Call yourself the script host with all the needed arguments.
I just need to write a simple batch file just to run a vbscript. Both the vbscript and the batch file are in the same folder and is in the SysWOW64 directory as the vbscript can only be execute in that directory. Currently my batch file is as follows:
#echo off
%WINDIR%\SysWOW64\cmd.exe
cscript necdaily.vbs
But the vbscript wasn't executed and just the command prompt is open. Can anyone tell me how can i execute the vbscript when i run this batch file?
You can use %~dp0 to get the path of the currently running batch file.
Edited to change directory to the VBS location before running
If you want the VBS to synchronously run in the same window, then
#echo off
pushd %~dp0
cscript necdaily.vbs
If you want the VBS to synchronously run in a new window, then
#echo off
pushd %~dp0
start /wait "" cmd /c cscript necdaily.vbs
If you want the VBS to asynchronously run in the same window, then
#echo off
pushd %~dp0
start /b "" cscript necdaily.vbs
If you want the VBS to asynchronously run in a new window, then
#echo off
pushd %~dp0
start "" cmd /c cscript necdaily.vbs
This is the command for the batch file and it can run the vbscript.
C:\Windows\SysWOW64\cmd.exe /c cscript C:\Windows\SysWOW64\...\necdaily.vbs
Just try this code:
start "" "C:\Users\DiPesh\Desktop\vbscript\welcome.vbs"
and save as .bat, it works for me
Batch files are processed row by row and terminate whenever you call an executable directly.
- To make the batch file wait for the process to terminate and continue, put call in front of it.
- To make the batch file continue without waiting, put start "" in front of it.
I recommend using this single line script to accomplish your goal:
#call cscript "%~dp0necdaily.vbs"
(because this is a single line, you can use # instead of #echo off)
If you believe your script can only be called from the SysWOW64 versions of cmd.exe, you might try:
#%WINDIR%\SysWOW64\cmd.exe /c call cscript "%~dp0necdaily.vbs"
If you need the window to remain, you can replace /c with /k
Well i am trying to open a .vbs within a batch file without having to click open but the answer to this question is ...
SET APPDATA=%CD%
start (your file here without the brackets with a .vbs if it is a vbd file)
You should put your .bat file in the same folder as your .vbs file and call the following code inside the .bat file.
start cscript C:\filePath\File.vbs