I'm trying to learn how to run Javascript (instead of VBScript) using CScript.exe, but when I try, I get an error:
cscript temp.js
Input Error: There is no script engine for file extension ".js".
I thought this is possible -- any idea what's wrong?
Setting the registry with regsvr32 did not work for me. Also, I don't want it, since I want my .js to be linked with a plain text editor.
But there is a command line option //E for cscript which makes the job:
cscript //E:jscript hello.js
A very simple fix: use assoc.
c:\>assoc .js=JSFile
(Mine had become associated with a text editor at some point.)
It's worth to mention that rplantiko's solution works even if the
extension of the filename is not .js. This allows for putting .js code
into a .cmd file and running as a batch, forming a single-file
solution that is fully portable without preliminary steps (like
assoc).
For example, if you create a test.cmd file with the following content,
you'll be able to run it by simply clicking on it in Explorer,
or by drag&drop another file over its icon:
#if (#CodeSection == #Batch) #then
#cscript //Nologo //E:jscript "%~f0" "test arg" %* & pause & goto :eof
#end
WScript.Echo("hello world");
for (var i = 0, n = WScript.Arguments.Length, args = []; i < n; ++i)
args.push(WScript.Arguments(i));
WScript.Echo("arguments: " + args.join(","));
The lines between #then ... #end are batch commands interpreted by cmd.exe. The last command is goto :eof to skip the rest of the file. The lines after #end are interpreted by cscript.exe.
It turns out that the .js extension wasn't associated with JSFile in the registry. Doing so fixed the problem.
assoc .js=JSfile
ftype jsfile=C:\Windows\System32\Cscript.exe "%1" %*
Had this problem, too, and I solved ...
1.- locate wsh.inf, the installation file for windows scripting host in %windir%\inf
2.- right-click on wsh.inf and choose install.
You should be able to run this command to fix the error:
regsvr32 %systemroot%\system32\vbscript.dll
Related
There are many reasons to want to 'convert' a .bat to .exe - to hide/obfuscate implementation, passwords, path to resources , to create a service from batch file ... and mainly to make your work to look more complicated and important than it really is.
There are also many reasons to not want to use third party tools.
So what if you want to 'convert' a batch file to .exe without external software?
(convert is in quotes because I don't think there's really way to compile a batch file to executable. There are too many abusive twisty techniques and bugs used extensively and all the tools that I know in fact create a temporary .bat file and then call it )
One very obvious approach is to use IEXPRESS - the ancient built-in tool that creates self-extracting packages and is capable to execute post extraction commands.
So here's IEXPRESS sed-directive/.bat file that creates a self-extracting .exe with packed .bat.
It accepts two arguments - the .bat file you want to convert and the target executable:
;#echo off
; rem https://github.com/npocmaka/batch.scripts/edit/master/hybrids/iexpress/bat2exeIEXP.bat
;if "%~2" equ "" (
; echo usage: %~nx0 batFile.bat target.Exe
;)
;set "target.exe=%__cd__%%~2"
;set "batch_file=%~f1"
;set "bat_name=%~nx1"
;set "bat_dir=%~dp1"
;copy /y "%~f0" "%temp%\2exe.sed" >nul
;(echo()>>"%temp%\2exe.sed"
;(echo(AppLaunched=cmd.exe /c "%bat_name%")>>"%temp%\2exe.sed"
;(echo(TargetName=%target.exe%)>>"%temp%\2exe.sed"
;(echo(FILE0="%bat_name%")>>"%temp%\2exe.sed"
;(echo([SourceFiles])>>"%temp%\2exe.sed"
;(echo(SourceFiles0=%bat_dir%)>>"%temp%\2exe.sed"
;(echo([SourceFiles0])>>"%temp%\2exe.sed"
;(echo(%%FILE0%%=)>>"%temp%\2exe.sed"
;iexpress /n /q /m %temp%\2exe.sed
;del /q /f "%temp%\2exe.sed"
;exit /b 0
[Version]
Class=IEXPRESS
SEDVersion=3
[Options]
PackagePurpose=InstallApp
ShowInstallProgramWindow=0
HideExtractAnimation=1
UseLongFileName=1
InsideCompressed=0
CAB_FixedSize=0
CAB_ResvCodeSigning=0
RebootMode=N
InstallPrompt=%InstallPrompt%
DisplayLicense=%DisplayLicense%
FinishMessage=%FinishMessage%
TargetName=%TargetName%
FriendlyName=%FriendlyName%
AppLaunched=%AppLaunched%
PostInstallCmd=%PostInstallCmd%
AdminQuietInstCmd=%AdminQuietInstCmd%
UserQuietInstCmd=%UserQuietInstCmd%
SourceFiles=SourceFiles
[Strings]
InstallPrompt=
DisplayLicense=
FinishMessage=
FriendlyName=-
PostInstallCmd=<None>
AdminQuietInstCmd=
UserQuietInstCmd=
example:
bat2exeIEXP.bat myBatFile.bat MyExecutable.exe
This should work practically on every Windows machine out there but has one major limitation - you cannot pass arguments to the created .exe file
So one other possible approach is to look at the .NET compilers (again should be available on almost every win machine).I've choose Jscript.net .
This is a hybrid jscript.net/.bat script that will read the .batch file content.Will create another jscript.net with the .bat file content and after the compilation will create a new bat file int the temp folder and will call it.And will accept command line arguments.(explained might look complex but in fact it's simple):
#if (#X)==(#Y) #end /* JScript comment
#echo off
setlocal
del %~n0.exe /q /s >nul 2>nul
for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do (
set "jsc=%%v"
)
if not exist "%~n0.exe" (
"%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0"
)
%~n0.exe "%jsc%" %*
del /q /f %~n0.exe 1>nul 2>nul
endlocal & exit /b %errorlevel%
*/
//https://github.com/npocmaka/batch.scripts/blob/master/hybrids/.net/bat2exe.bat
import System;
import System;
import System.IO;
import System.Diagnostics;
var arguments:String[] = Environment.GetCommandLineArgs();
if (arguments.length<3){
Console.WriteLine("Path to cmd\bat file not given");
Environment.Exit(1);
}
var binName=Path.GetFileName(arguments[2])+".exe";
if(arguments.length>3){
binName=Path.GetFileName(arguments[3]);
}
var batchContent:byte[]= File.ReadAllBytes(arguments[2]);
var compilerLoc=arguments[1];
var content="["
for (var i=0;i<batchContent.length-1;i++){
content=content+batchContent[i]+","
}
content=content+batchContent[batchContent.length-1]+"]";
var temp=Path.GetTempPath();
var dt=(new Date()).getTime();
var tempJS=temp+"\\2exe"+dt+".js";
var toCompile="\r\n\
import System;\r\n\
import System.IO;\r\n\
import System.Diagnostics;\r\n\
var batCommandLine:String='';\r\n\
//Remove the executable name from the command line\r\n\
try{\r\n\
var arguments:String[] = Environment.GetCommandLineArgs();\r\n\
batCommandLine=Environment.CommandLine.substring(arguments[0].length,Environment.CommandLine.length);\r\n\
}catch(e){}\r\n\
var content2:byte[]="+content+";\r\n\
var dt=(new Date()).getTime();\r\n\
var temp=Path.GetTempPath();\r\n\
var nm=Process.GetCurrentProcess().ProcessName.substring(0,Process.GetCurrentProcess().ProcessName.length-3);\r\n\
var tempBatPath=Path.Combine(temp,nm+dt+'.bat');\r\n\
File.WriteAllBytes(tempBatPath,content2);\r\n\
var pr=System.Diagnostics.Process.Start('cmd.exe','/c '+' '+tempBatPath+' '+batCommandLine);\r\n\
pr.WaitForExit();\r\n\
File.Delete(tempBatPath);\r\n\
";
File.WriteAllText(tempJS,toCompile);
var pr=System.Diagnostics.Process.Start(compilerLoc,'/nologo /out:"'+binName+'" "'+tempJS+'"');
pr.WaitForExit();
File.Delete(tempJS);
It's rather a POC , but .NET System.Diagnostics and System.IO libraries are powerful enough to add features like hidden start , enctiption and etc.You can check also jsc.exe compiling options to see what else is capable of (like adding resources).
I promise an upvote to every improvement over the .NET method :-)
UPDATE: the second script has been changed and now the exe from the converted bat file can be started with double click.It uses the same interface as previous script:
bat2exejs.bat example.bat example.exe
I do know how to convert bat/cmd to exe manually, make sure the bat/cmd filename contains just letters, and numbers. Open 'IExpress Wizard' as admin.
Select 'Create new Self Extraction Directive file'
Select 'Extract files and run an installation command'
Name the package anything
'No prompt' for 'Confirmation prompt'
'Do not display a license' for 'License agreement'
Click 'Add' for the 'Packaged files', from there select the bat/cmd file
Then in 'Install Program' text box for 'Install Program to Launch', type cmd /c, followed by the full name of the bat/cmd file, (example: emptyrecyclebin.bat => cmd /c emptyrecyclebin.bat)
Leave the 'Post Install Command' as is
'Hidden' for 'Show window'
'No message' for 'Finished message'
Click 'Browse', and select where to download the exe to
Enable 'Hide File Extracting Progress Animation from User'
Disable 'Store files using Long File Name inside Package'
Definitely 'No restart' for 'Configure restart'
Then save SED if you want to re-compile it quicker later
Then create the package! A command window should quickly appear and disappear
Navigate to the place where you downloaded the exe to, and enjoy!
All of the above methods do not protect your source code in any way. I recently saw a press release in the news about a new compiler that does not depend on CMD.exe. I don't know exactly how it works, but it doesn't create temporary files at runtime.
https://www.prlog.org/12882479-the-worlds-first-true-compiler-for-batch-files.html
Using IEXPRESS makes a kind of SFX archive, which does not achieve the main goal of hiding the source code with passwords. All other "compilers" work on a similar principle - extract the script to a temporary folder and run it via cmd.exe. The press release claimed a real compilation, so I downloaded the trial version and wrote a primitive script to measure the speed:
#echo off
set startTime=%time%
set counter=0
:main_loop
echo %counter%
set /a counter=counter+1
if %counter% LEQ 10000 goto main_loop
echo Start Time: %startTime%
echo Finish Time: %time%
After compiling the code runs twice as fast and I haven't noticed any calls to cmd.exe in the Task Manager. In addition, I ran Process Monitor and saw no creation of temporary files while it was running. This leads me to believe that this compiler provides better protection for the source code.
You can also develop a simple exe, which just calls your bat-script.
For example you could write one in C# (I'm no C#-Pro, this is actually my first program and I copied lots of it from this other Stackoverflow post.):
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;
class BatCaller {
static void Main() {
var batFile = System.Reflection.Assembly.GetEntryAssembly().Location.Replace(".exe", ".bat");
if (!File.Exists(batFile)) {
MessageBox.Show("The launch script could not be found.", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
System.Environment.Exit(42);
}
var processInfo = new ProcessStartInfo("cmd.exe", "/c \"" + batFile + "\"");
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
var process = Process.Start(processInfo);
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => Console.WriteLine("output>>" + e.Data);
process.BeginOutputReadLine();
process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => Console.WriteLine("error>>" + e.Data);
process.BeginErrorReadLine();
process.WaitForExit();
Console.WriteLine("ExitCode: {0}", process.ExitCode);
process.Close();
}
}
If you store this code above to MySuperApp.cs just next to MySuperApp.bat and then compile it with csc.exe /target:winexe MySuperApp.cs (and maybe even add /win32icon:MySuperApp.ico to add a fancy icon) it will generate a MySuperApp.exe.
Launching MySuperApp.exe will call MySuperApp.bat (the bat-file with the same name).
csc.exe (should?) be present on every Windows machine.
Different versions of Windows has different effects for same batch file commands, and some commands are limited to some Windows systems eg. findstr and shutdown.
BTW, Win 10 CMD doesn't allow changes to SETLOCAL on command line. OK for batch files.
See this link for different commands for restarting different versions of windows:
https://www.computerhope.com/issues/ch000321.htm
So if you were to compile a script on Win 98, and run on Win 8.1, you'd get unexpected results or scripts may not even work.
See list of commands here:
https://www.ionos.com/digitalguide/server/know-how/windows-cmd-commands/
For this reason, one would need a different compiler on each version of Windows, preferably which would spit out binary code (generic) that can be run on as many CPU chips as possible, with same instruction sets. A workaround offered by most programs is to wrap the script in an exe file that would unwrap and execute the script when opened/run eg. Bat_To_Exe_Converter, Bat2Exe, BatchCompiler, iexpress or Winzip:
https://support.winzip.com/hc/en-us/articles/115011794948-What-is-a-Self-Extracting-Zip-File-
To solve this issue of portability, virtual machines have become more popular and hence the rise of Java & related scripts.
This however, would still be intepreted code, and not as fast as compiled code. Even byte code (intermediate code) from virtual machines still need to be compiled, even if it's (JIT):
https://aboullaite.me/understanding-jit-compiler-just-in-time-compiler/
In short, you can get an exe file which would contain a script that would be intepreted by the command processor, but it won't be a native executable file, meaning it won't run without a host by the Windows operating system.
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 am trying to start the default application for a file, wait for it to complete, and then continue with my batch file. The problem is that start, when used below simply creates another command prompt window with the example.doc in the title bar. I can use call instead of start, but then call does not wait for the program to finish before going to the next line. It appears that start needs to have an executable name and will not work with the default application system in windows.
Any ideas how I can make this happen without having to hardcode the windows application in the batch file as well?
set filename=example.doc
start /wait %filename%
copy %filename% %filename%.bak
How do I start the default application for a file, wait for completion, then continue?
It appears that start needs to have an executable name and will not work with the default application system in windows.
start, when used below simply creates another command prompt window with the example.doc in the title bar
start /wait %filename%
The above command won't work because %filename% is used as the window title instead of a command to run.
Always include a TITLE this can be a simple string like "My Script" or just a pair of empty quotes ""
According to the Microsoft documentation, the title is optional, but depending on the other options chosen you can have problems if it is omitted.
Source start
Try the following command instead:
start "" /wait %filename%
Alternative solution using the default open command
Any ideas how I can make this happen without having to hardcode the
windows application in the batch file as well?
One way is to use assoc and ftype to get the default open command used for the file then execute that command.
The following batch file does that for you (so no hard coding of windows applications is needed).
Open.cmd:
#echo off
setlocal enabledelayedexpansion
set _file=example.doc
rem get the extension
for %%a in (%_file%) do (
set _ext=%%~xa
)
rem get the filetype associated with the extension
for /f "usebackq tokens=2 delims==" %%b in (`assoc %_ext%`) do (
set _assoc=%%b
)
rem get the open command used for files of type filetype
for /f "usebackq tokens=2 delims==" %%c in (`ftype %_assoc%`) do (
set _command=%%c
rem replace %1 in the open command with the filename
set _command=!_command:%%1=%_file%!
)
rem run the command and wait for it to finish.
start "" /wait %_command%
copy %_file% %_file%.bak 1>nul
endlocal
Further Reading
An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
assoc - Display or change the association between a file extension and a fileType
enabledelayedexpansion - Delayed Expansion will cause variables to be expanded at execution time rather than at parse time.
for - Conditionally perform a command several times.
for /f - Loop command against the results of another command.
ftype - Display or change the link between a FileType and an executable program.
start - Start a program, command or batch script (opens in a new window).
variable edit/replace - Edit and replace the characters assigned to a string variable.
Simply use the filename directly as command, unless that filename is a batch file, in which case use call.
In a batch file invocation of a GUI subsystem executable is blocking, unlike for an interactive command.
Use the start command when you don't want blocking execution.
There is a subtle point about “default application”, namely that a file type can have a registered default application for the graphical shell, e.g. its “Open with…”, without having an assoc/ftype association, or different from that association.
I'm not entirely sure of which registry entries are used for this. I've always had to look it up and research it each time. As I recall it's not well-documented.
But hopefully you're OK with just the assoc/ftype scheme.
A further subtle point about “default application”: on the laptop I'm writing this on the ftype association for text files is to open them in Notepad:
[H:\forums\so]
> assoc .txt
.txt=txtfile
[H:\forums\so]
> ftype txtfile
txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1
[H:\forums\so]
> _
And this is what the graphical shell (Windows Explorer) will do.
But cmd.exe looks inside files, and if it finds an executable signature then it tries to run the text file as an executable, even in Windows 10:
[H:\forums\so]
> echo MZ bah! >oops.txt
[H:\forums\so]
> oops.txt
This version of H:\forums\so\oops.txt is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.
[H:\forums\so]
> _
I have searched for many weeks to solve my problem and can't find a good way of doing it that works on every machine I may need to use.
I know START command opens a new window to do the .exe, but I want to stay in the same window and run the .exe
(because I want my batch file to continue ONLY WHEN THE .EXE has finished running)
I have found that on some computers when I .exe it opens a new window and other computers is stays in the same window which makes me think my code is fine but there is a setting somewhere on the computers that is different.
Can you help? What are my options? The .exe I am running is NASTRAN which is an engineering solver that runs in command window.
To wait for the command to terminate you should use the WAIT flag:
start /WAIT c:/windows/system32/notepad.exe
You could start an application without creating a new window using the B flag:
start /WAIT /B "c:/windows/system32/cmd.exe"
You should also try reading the help text for the start command:
start /?
You can use cmd /k example.exe
You probably have a different variant of the .exe on some machines which is called only there, and spawns a separate window, for reasons I cannot know. Search for the .exe file on all machines and compare.
Also, post your batch file code so we can exactly see how you start the .exe.
You could consider not using start at all. Simply start the executable directly.
Did you try using call in the batch file. it runs the exe in the same window. as the batch file. The next statement in the batch file is executed after this exe is finished running
In order to do this you have to run an executable from the directory where it is located, and also have to avoid the use of "start" command.
For example:
cd C:\MyDirectory\
MyApplication.exe -Parameter1 -ParameterN
I achieved showing output of my executable (no aforementioned solutions worked for me) in the same CMD window only via rights escalation script (it will launch your .bat/.cmd file as admin):
if _%1_==_payload_ goto :payload
:getadmin
echo %~nx0: elevating self
set vbs=%temp%\getadmin.vbs
echo Set UAC = CreateObject^("Shell.Application"^) >> "%vbs%"
echo UAC.ShellExecute "%~s0", "payload %~sdp0 %*", "", "runas", 1 >> "%vbs%"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
goto :eof
:payload
<<<start writing your commands from here. E.g.:
"C:\my program\launcher.exe" argument1>>>
pause
P.S. Don't forget to remove <<< and >>> from script.
I have this bat file and I want to minimize the cmd window when I run it:
#echo off
cd /d C:\leads\ssh
call C:\Ruby192\bin\setrbvars.bat
ruby C:\leads\ssh\put_leads.rb
I want the command window minimized immediately. Any ideas on how to do this?
There is a quite interesting way to execute script minimized by making him restart itself minimised. Here is the code to put in the beginning of your script:
if not DEFINED IS_MINIMIZED set IS_MINIMIZED=1 && start "" /min "%~dpnx0" %* && exit
... script logic here ...
exit
How it works
When the script is being executed IS_MINIMIZED is not defined (if not DEFINED IS_MINIMIZED) so:
IS_MINIMIZED is set to 1: set IS_MINIMIZED=1.
Script starts a copy of itself using start command && start "" /min "%~dpnx0" %* where:
"" - empty title for the window.
/min - switch to run minimized.
"%~dpnx0" - full path to your script.
%* - passing through all your script's parameters.
Then initial script finishes its work: && exit.
For the started copy of the script variable IS_MINIMIZED is set by the original script so it just skips the execution of the first line and goes directly to the script logic.
Remarks
You have to reserve some variable name to use it as a flag.
The script should be ended with exit, otherwise the cmd window wouldn't be closed after the script execution.
If your script doesn't accept arguments you could use argument as a flag instead of variable:
if "%1" == "" start "" /min "%~dpnx0" MY_FLAG && exit
or shorter
if "%1" == "" start "" /min "%~f0" MY_FLAG && exit
Use the start command, with the /min switch to run minimized. For example:
start /min C:\Ruby192\bin\setrbvars.bat
Since you've specified a batch file as the argument, the command processor is run, passing the /k switch. This means that the window will remain on screen after the command has finished. You can alter that behavior by explicitly running cmd.exe yourself and passing the appropriate switches if necessary.
Alternatively, you can create a shortcut to the batch file (are PIF files still around), and then alter its properties so that it starts minimized.
The only way I know is by creating a Windows shortcut to the batch file and then changing its properties to run minimized by default.
Using PowerShell you can minimize from the same file without opening a new instance.
powershell -window minimized -command ""
Also -window hidden and -window normal is available to hide completely or restore.
source: https://stackoverflow.com/a/45061676/1178975
If you want to start the batch for Win-Run / autostart, I found I nice solution here https://www.computerhope.com/issues/ch000932.htm & https://superuser.com/questions/364799/how-to-run-the-command-prompt-minimized
cmd.exe /c start /min myfile.bat ^& exit
the cmd.exe is needed as start is no windows command that can be executed outside a batch
/c = exit after the start is finished
the ^& exit part ensures that the window closes even if the batch does not end with exit
However, the initial cmd is still not minimized.
One way to 'minimise' the cmd window is to reduce the size of the console using something like...
echo DO NOT CLOSE THIS WINDOW
MODE CON COLS=30 LINES=2
You can reduce the COLS to about 18 and the LINES to 1 if you wish.
The advantage is that it works under WinPE, 32-bit or 64-bit, and does not require any 3rd party utility.
If you type this text in your bat file:
start /min blah.exe
It will immediately minimize as soon as it opens the program. You will only see a brief flash of it and it will disappear.
You could try running a script as follows
var WindowStyle_Hidden = 0
var objShell = WScript.CreateObject("WScript.Shell")
var result = objShell.Run("cmd.exe /c setrbvars.bat", WindowStyle_Hidden)
save the file as filename.js
Yet another free 3rd party tool that is capable of minimizing the console window at any time (not only when starting the script) is Tcl with the TWAPI extension:
echo package require twapi;twapi::minimize_window [twapi::get_console_window] | tclkitsh -
here tclkitsh.exe is in the PATH and is one of the tclkit-cli-*-twapi-*.exe files downloadable from sourceforge.net/projects/twapi/files/Tcl binaries/Tclkits with TWAPI/. I prefer it to the much lighter min.exe mentioned in Bernard Chen's answer because I use TWAPI for countless other purposes already.
You can minimize the command prompt on during the run but you'll need two additional scripts: windowMode and getCmdPid.bat:
#echo off
call getCmdPid
call windowMode -pid %errorlevel% -mode minimized
cd /d C:\leads\ssh
call C:\Ruby192\bin\setrbvars.bat
ruby C:\leads\ssh\put_leads.rb
One option is to find one of the various utilities that can change the window state of the currently running console window and make a call to it from within the batch script.
You can run it as the first thing in your batch script. Here are two such tools:
min.exe
http://www.paulsadowski.com/wsh/cmdprogs.htm
cmdow
http://www.commandline.co.uk/cmdow/index.html
Another option that works fine for me is to use ConEmu, see http://conemu.github.io/en/ConEmuArgs.html
"C:\Program Files\ConEmu\ConEmu64.exe" -min -run myfile.bat
try these
CONSOLESTATE /Min
or:
SETCONSOLE /minimize
or:
TITLE MinimizeMePlease
FOR /F %%A IN ('CMDOW ˆ| FIND "MinimizeMePlease"') DO CMDOW %%A /MIN
http://conemu.github.io/en/ConEmuArgs.html download flagged by Virus Total.
May have Malware.