Soo
#echo off Turn off command echoing and don't echo the command turning it off. But how to make bat file do not call CMD at all ?
This makes so little sense. If you're asking how to stop a batch file from showing the command prompt window, you cannot.
You can however use a VBScript file to launch the batch file silently. The script would look something like:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\path-to-batch-file\batchfile.bat" & Chr(34), 0
Set WshShell = Nothing
I think what you're trying to do probably isn't a job for a batch file.
A batch file is a script, not a binary executable. A script always needs an interpreter to run. For batch scripts, the interpreter is cmd.exe, so you cannot avoid invoking cmd.exe at all. It makes no sense to run a script without its interpreter. This is true everywhere.
All you can do is hiding the console window that cmd.exe brings up when it's invoked, most easily done with the help of a VBScript:
CreateObject("Wscript.Shell").Run "C:\path\to\your.bat", 0, False
Related
Not sure where the problem is though. The task originally pointed straight to the bat file but the console window popping up got annoying so I created a vbs script to run the bat file and pointed the task at the vbs instead of the bat.
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Path\to\Clue (1985)\random.bat" & Chr(34), 0
Set WshShell = Nothing
It's supposed to run every five minutes. Task Scheduler reports "The operation completed successfully", but the bat file isn't being run. Manually running the bat gets me the desired result so the bat file itself isn't the issue.
Batch files are really not my area of expertise, and I simply copied the vbs script from something I found on Google looking up how to run the bat without the console window popping up so I know literally nothing about how vbs scripts actually work.
This is the batch file, which works fine when I run it manually:
set /a ascii=(%RANDOM% %% 3) + 65
cmd /c exit /b %ascii%
echo Clue (1985) - Ending %=ExitCodeAscii%.mkv > "Clue (1985) - Random Ending.strm"
Task is supposed to run every five minutes. I just gave it a manual time trigger to kick it off - it's also set to trigger on system start for the future. I'm the only user account on my PC, so it's running under me, with highest privileges....I think that's everything?
I have VBScript file as follows which launches multiple batch files.
Invoke.vbs
const RunbatchtLocation = "C:\Temp"
Set shell = WScript.CreateObject("WScript.Shell")
shell.run RunbatchtLocation & "\Launch.bat",1,True
Launch.bat
start cmd /k "C:\Temp\All10.bat"
start cmd /k "C:\Temp\30.bat"
C:\Temp\50.bat
The above file able will executed All10.bat , 30.bat and 50.bat which is work fine.
My problem is here in All10.bat which is as follows:
CALL "c:\temp\10-1.bat"
CALL "c:\temp\10-2.bat"
CALL "c:\temp\10-3.bat"
It starts with 10-1.bat and is able to execute all the specified files, but after it completes it stops and never executes 10-2.bat or 10-3.bat.
Will someone tell me where I am going wrong?
i need to make a batch file that have a hidden process and window for the users
i have already my batches file and want to make one of them hidden
vbs can't make that or any programming language ?
here you can find multiple ways to do this : https://stackoverflow.com/questions/28284876/what-are-the-different-ways-to-start-a-hidden-process-with-batch-file-and-what-a
Probably the best is with Win32_ProcessStartup as it returns also the pid of the started process.
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\file.bat" & Chr(34), 0
Set WshShell = Nothing
with Vbs and call the bat file this is the way
Use the start command:
start /b my.bat
Refer to: https://technet.microsoft.com/en-us/library/cc770297(v=ws.11).aspx
I am having issues getting a simple batch file (opening command prompt) to run from a vbs macro, I know this question gets asked a lot and I have tried many different suggested solutions for this without success. I am using notepad ++ to run the scripts/VB code for testing.
I have verified that the .bat file will execute correctly by itself, any suggestion on how to get this to work correctly would be greatly appreciated.
Here is my code for each instance.
VB CODE:
Sub CallBATCH()
Dim argh As Double
argh = Shell.Run "C:\Temp\cmdPrompt.bat"
End Sub
BATCH FILE:
start cmd.exe /k
EDIT: The following is the .bat file that I actually intend on calling up:
#echo OFF
title AutoCAD DWG Duplicator
color 0a
:start
set /P TemplateName=Please enter the template name you wish to copy:
set /P NumberOfCopies=Please enter how many copies you wish to make:
set Pathname="<filepath>"
cd /d %Pathname%
:init
for /L %%f in (1,1,%NumberOfCopies%) do copy %TemplateName%.dwg C:\Temp\%%f%TemplateName%.dwg
You seem to be calling a .BAT file that in turn opens a command prompt with START. I'm unclear on why you need the .BAT at all.
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe /K"
Set oShell = Nothing
The /K parameter will open the command prompt window and keep it open. You've supplied no parameters for START and no commands to execute when the command prompt opens so this should do what you are looking for. More at: Run Method (Windows Script Host)
I have a master.bat file which has...
call file1.bat
call file2.bat
call file3.bat
call file4.bat
I want to schedule it on my Windows server 2008 to run in silent/invisible mode.I'm looking for some way to run this master.bat without anything visible to the user (no window, CMD interface ,no taskbar name etc..)
I don't want to install any batch to exe software.
I tried by changing the User running the task to "SYSTEM" and it has the work done but I can't do this in actual.
I have found that Windows Script Host’s Run Method allows you to run a script in invisible mode as.....
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Batch Files\master.bat" & Chr(34), 0
Set WshShell = Nothing
but no more file please :) any other suggestion for this.
EDIT1
Considering the limited options available..it would be OK to use Windows Script Host’s Run Method,but how i can schedule master.vbs in task scheduler.. ?
For an extended view of it, check for hybrid batch / vbscript / javascript files here in stackoverflow.
Save this as master.cmd and adapt as needed.
#if (#This==#IsBatch) #then
#echo off
rem **** batch zone *********************************************************
rem Check if started from javascript part of script.
rem We are checking an environment variable set from javascript part.
if "%_run_hidden_%"=="true" (
goto startBatchWork
)
rem if not started from javascript, call javascript part to restart batch.
wscript //E:JScript "%~dpnx0"
exit /b
:startBatchWork
rem Here starts the real work of the batch file
msg %username% "Batch file running hidden"
rem End of batch area. Ensure batch ends execution before reaching
rem javascript zone
exit /b
#end
// **** Javascript zone *****************************************************
// Instantiate the needed component to interact with Shell
var shell = WScript.CreateObject('WScript.Shell');
// Set the environment variable that the batch part will check to know
// it's running hidden
shell.Environment('Process').Item('_run_hidden_')='true';
// start the batch part of the script calling %comspec% with the current
// script as parameter, hidden (0) and not waiting for it to end (false)
shell.Run('"' + shell.ExpandEnvironmentStrings('%comspec%') + '" /c "' + WScript.ScriptFullName + '"', 0, false );
// All done. Exit
WScript.Quit(0);
CMDOW is a tool that will allow the batch to run hidden.
It is flagged as a hack tool by various AV programs.