npocmaka / batch.scripts Goto Github PK
View Code? Open in Web Editor NEWbatch script utils and examples by npocmaka -
Home Page: https://www.linkedin.com/in/npocmaka/
License: MIT License
batch script utils and examples by npocmaka -
Home Page: https://www.linkedin.com/in/npocmaka/
License: MIT License
__COMPAT_LAYER
is defined as environment variable on Windows 10 Pro and its value is RunAsInvoker
.
C:\> ECHO %__COMPAT_LAYER%
RunAsInvoker
Why is the __COMPAT_LAYER
variable defined in this script? Which Windows OS is targeted to the following definition?
batch.scripts/Java/javaDetect.bat
Line 3 in ff1679b
When the javaDetect.bat script is run after a new CMD session is opened, the following error occurs:
Environment variable JAVA_VERSION not defined
To fix this error, the comment lines assigning to the JAVA_VERSION
variable have been removed.
@ECHO OFF
SET __COMPAT_LAYER=RunAsInvoker
:: Export java settings from registry to a temporary file
START /W REGEDIT /E %Temp%\java.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft"
IF NOT EXIST "%Temp%\java.reg" (
START /W REGEDIT /E %Temp%\java.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft"
)
IF NOT EXIST "%Temp%\java.reg" (
ECHO Java NOT installed
EXIT /b 1
)
:: Find java location
FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%\java.reg ^| FIND "INSTALLDIR"') DO SET JAVA_HOME=%%B
SET JAVA_HOME=%JAVA_HOME:"=%
SET JAVA_HOME=%JAVA_HOME:\\=\%
SET JAVA_HOME
:: Get java version
FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%\java.reg ^| FIND "CurrentVersion"') DO SET JAVA_VERSION=%%B
SET JAVA_VERSION=%JAVA_VERSION:"=%
SET JAVA_VERSION
SET JAVA_VERSION=%JAVA_VERSION:.=%
SET JAVA_VERSION=%JAVA_VERSION:_=%
SET /A JAVA_VERSION=%JAVA_VERSION%
FOR /f tokens^=2-5^ delims^=.-_^" %%j in ('%JAVA_HOME%\bin\java.exe -fullversion 2^>^&1') do set "JAVA_VERSION=%%j%%k%%l%%m"
:: Delete temporary file
DEL %Temp%\java.reg /S /Q > NUL 2>&1
set JAVA_VERSION
:: Check java version compatibility
IF %JAVA_VERSION% LSS 16020 (
ECHO.
ECHO YOU NEED AT LEAST JAVA WITH VERSION 1.6.0_20 -- this is just an example echo.
GOTO :EOF
)
PAUSE
Everything fine
There is some suggestions to improvement on .net batch prologue.
(as a source screenCapture.bat was used)
Here is updated prologue I use:
// 2>nul||@goto :batch
/*
:batch
@echo off
if exist "%~dpn0.exe" (
"%~dpn0.exe" %*
exit /b %errorlevel%
)
setlocal
:: find csc.exe
set "csc="
for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*csc.exe") do set "csc=%%#"
if not exist "%csc%" (
echo no .net framework installed
exit /b 10
)
call %csc% /nologo /r:"Microsoft.VisualBasic.dll" /out:"%~dpn0.exe" "%~dpn0.bat" || (
exit /b %errorlevel%
)
"%~dpn0.exe" %*
endlocal & exit /b %errorlevel%
*/
Hi,
Someone recommended: https://github.com/npocmaka/batch.scripts/blob/master/hybrids/.net/c/screenCapture.bat
But there are only very few comments. Would it be possible to add more comments, or
alternatively, add a second variant with more comments? I can program, but not in
C# / .NET so it would be super-useful if I understand what is going on in that program.
Thanks for reading and perhaps also considering!
I want to write a batch script that will start a website if it isn't started and detect if it is closed and reopen it again, I'm not sure if this is possible but im really intrigued to find out so far I'm stuck on how to get it to loop as in constantly check if the website is open or if it is closed right now I'm going somewhere along the lines of this but I get stuck on trying to figure out how to loop it to where it will reopen the website if closed
@echo off
Color 09
Title Website Checker
Goto start
:start
Taskkill /T "msedge.exe"
Cls
Echo press any key to launch website.com
Pause
Start www.website.com
Timeout /t 15
Pause
Is there a way to make it working? On windows 10 the same script work fine
Automation server can't create object - Microsoft JScript runtime error
In between endlocal
and del ~.txt /q /f >nul 2>nul
, ~.txt
is missing. On its current state, the file won't open any file. Also, adding if EXIST
in the first deletion command would make everything cleaner.
Final state of the file:
@echo off
if EXIST ~.txt del ~.txt /q /f >nul 2>nul
start "" /w dxdiag /t ~
setlocal enableDelayedExpansion
set currmon=1
for /f "tokens=2 delims=:" %%a in ('find "Current Mode:" ~.txt') do (
echo Monitor !currmon! : %%a
set /a currmon=currmon+1
)
endlocal
~.txt
del ~.txt /q /f >nul 2>nul
I would have opened a pull request but I have no idea on how to do it.
Some users don't want all that extra information or features that you have in your file.
Me personally, I just need to have your file, but in a way that I can use them like on a POSIX system.
There is some suggestions to improvement on .net batch prologue, future improvement of (#25)
It runs .exe files immediately if .exe file is located near .bat file.
It does not generate output // 2>nul ||
at the begin
Here is updated prologue I use, attached to hello world example:
@goto :batch_start_label_cs_hybrid
/*
@:batch_start_label_cs_hybrid
@echo off
if exist "%~dpn0.exe" (
"%~dpn0.exe" %*
exit /b %errorlevel%
)
setlocal
:: Additional options to csc.exe (like /r:"references")
set CSC_OPS=
:: Runner options
set CS_FAIL_EXIT_CODE=1001
:: find csc.exe
set "csc="
for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*csc.exe") do set "csc=%%#"
if not exist "%csc%" (
echo Error: no .net framework installed
exit /b %CS_FAIL_EXIT_CODE%
)
set BAT_START_LINE=batch_start
set BAT_START_LINE=%BAT_START_LINE%_
set BAT_START_LINE=%BAT_START_LINE%label_cs_hybrid
call findstr /V "%BAT_START_LINE%" "%~dpn0.bat" > "%~dpn0.bat.cs"
if not exist "%~dpn0.bat.cs" (
echo Error: fail to prepare executable
exit /b %CS_FAIL_EXIT_CODE%
)
call %csc% /nologo %CSC_OPS% /out:"%~dpn0.exe" "%~dpn0.bat.cs" || (
exit /b %CS_FAIL_EXIT_CODE%
)
del "%~dpn0.bat.cs"
"%~dpn0.exe" %*
endlocal & exit /b %errorlevel%
*/
using System;
public class Program
{
public static int Main(string[] Argv)
{
Console.WriteLine("Hello, world!");
return 0;
}
}
I use this prologue in zip.bat utility:
https://github.com/openlab-vn-ua/BatArt/blob/master/zip.bat
I'm using windows 10 and the screen res is 1600x900
position arg returns correct XxY co-ordinates
but moveTo doesn't move exactly like the co-ordinates provided.
I need to enter 65000x65000 to reach (moveTo) near the bottom-right corner.
The script is run in the temp folder how to transform into .exe running in the local folder where the .bat was converted?
I am trying to use sendKeys to bring a window to foreground by sendKeys "window title" ""
but seems it only works if the window is hidden, if it is minimized, then this will not work..
is there a way to add this feature of restore minimized window?
Thanks very much for the script.
I don't understand how to continue scripting after saving to external file the script output.
once the output has been saved to external file, the script closes and I can't execute other code after the winhttpjs,bat.
Is there a way to bypass this behaviour?
Thank you in advance.
Giuseppe
hi,, i need to submit a form post, with one field. until now i was able to get value of field.. but i dont now how to submit a post request with one input value., thanks
The find
function in dataStructures/binaryTree.bat produces the following error:
!test_tree6! was unexpected at this time.
To resolve this error, I removed the !%1!
syntax used for delayed expansion. This solution worked but I'm not sure it's the right approach.
call pinnerJS.bat Regshot.exe startmenu
return
pinning Regshot.exe to start menu
Regshot is not pinned
not in folder %AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu
not in C:\ProgramData\Microsoft\Windows\Start Menu
not in C:\ProgramData\Microsoft\Windows\Start Menu\Programmes
Thanks for fix
Can I use this to execute the exe first (ex. putty.exe) then execute the .bat next?
zipjs.bat unzip -source test.zip -destination testdir
gives an error: "Either the target does not exist or is not a correct type"
The reason is the check in line 551: if(!Shell.Application.ExistsFolder(source) ){
I suggest replacing it with if(!Scripting.FileSystemObject.ExistsItem(source) ){
It alerts me everytime I run/edit one of your batch files
We protect your PC
Are you 100% sure that your batch files are safe?
Is it possible to use SystemTrayNotification.bat to display a balloon notification to all logged in users? Or at the very least direct it to a different user other than the logged in user?
I'm using this on an RDS machine commonly used by 3 people simultaneously. It would be awesome to pop up subtle notifications between users that don't interrupt work flow.
Thanks, works brilliantly! Is it possible to get some documents to print in twofold, threefold, ... ?
Hello,
Running this command only capture the foreground window not the specified one. Sometimes its the good one but not everytime.
screenCapture capture.png title
EDIT: I read in the code that only foreground windows can be captured.
Case closed or new features needed?
Is there a way to replace multiple strings with a loop using replacer.bat?
call replacer.bat "content.txt" "foo" "bar" "xyz abc" "bla fart"
call replacer.bat "content.txt" "foo\bar" "xyz\abc" "bla\fart"
These commands don't work, the help isn't very helpful, and executing a command for each replacement is not something very optimized
Hi,
Thank you for this great script!
The option -keep no
doesn't seem to be reliable though. Sometimes the source folder remains to exist; some of its contents was deleted, but not all if it.
I've worked around this by performing an RD of the source folder aftwerwards.
Best regards,
Johan
Hey ther. i used the scale.bat and its worked since long time and now its dont scale it :(
since 2 days the scale.bat dosnt scale my .jpg anymore. i tryed with 1 line comands and with only defaults sets. nothing worked.
if ther any updates on windows 10 i missed to check or is somthing else? i cant explain it on me.
both systems (pc and laptop(windows 10 on both)) have this problem.
i used the scale.bat in original with only changed this defaults
var maxWidth=300;
var maxHeight=300;
var force=true;
and i call it with this line:
for /f "delims=" %%X in ('dir /s /a-h /b *Folder.jpg') do (call scale.bat -source "%%~dpXFolder.jpg" -target "jpg") & (attrib +H "%%~dpXFolder.jpg")
set update_time=1
FileTimeFilterJS.bat "." -filetime modified -direction after -hh -%update_time%
Hi, i´ve just used your https://github.com/npocmaka/batch.scripts/edit/master/hybrids/iexpress/bat2exeIEXP.bat , I have to say is awesome.
Now the problem is that I dont know if some malware ( or a colleague of mine ) deleted all my *bats, although I still have the generated Exes but none of their respective sources.
Do you have a file to reverse the process? Or indicate an app/ online site that could decompile it? so I can have access to de code again?
Thanks a lot and again, great tool!
Lets concider FileTimeFilerJS.bat as example.
If I call it in different directories and call FileTimeFilerJS.bat
by absolute path:
cd testdir1
/path/FileTimeFilerJS.bat . -hh -10
cd testdir2
/path/FileTimeFilerJS.bat . -hh -10
In each directory where I call it new unnecessary .exe file will be created.
My suggestion to avoid it is to create .exe file only in directory where FileTimeFilerJS.bat
is located.
To do it enough just to replace:
"%~n0.exe"
To
"%~dp0%~n0.exe"
in all /hybrids/.net/*.bat
files
If you agree, I can make a pull request.
.
I was using this script https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/winhttpjs.bat. So what I want is to get the response and make it as a variable and not using external txt files.
CMD files have many advantages over BAT files. More info on the differences between .cmd and .bat files
Absolutely great job!
Just one suggestion to speedup operation in .net bat files:
Add if exist "%~n0.exe" %~n0.exe %*
just after begin of bath body, so it will not search for .net framework if to compile .net part if it is already compiled (if compiled .exe exists, it will run it immediately):
Was:
:batch
@echo off
setlocal
Faster:
:batch
@echo off
if exist "%~n0.exe" (
"%~n0.exe" %*
exit /b %errorlevel%
)
setlocal
PS: Edited: Added exit after execution
Should the zipItem argument really call the ZipDirItems command?
https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/zipjs.bat#L796
and should the ZipItem command fail if the source isn't a folder?
https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/zipjs.bat#L491
I am using your caputre screen script and it is working great if I start it manually. However ist das not work when it is started by a scheduled task. I am getting no error, but the image file is not being created.
I just modified the following lines inside the DragMouseTo funcion:
replaced
mouseInput.mkhi.mi.dx = x;
mouseInput.mkhi.mi.dy = y;
for
mouseInput.mkhi.mi.dx = CalculateAbsoluteCoordinateX(x);
mouseInput.mkhi.mi.dy = CalculateAbsoluteCoordinateY(y);
And now works correctly
In line 549 it should be changed from (source) to (destination). We do not want to check if the source is a proper folder, but the destination. Now unzipping fails on all commands.
Tried it locally and that fixed the issue.
Hi,
This tool would be really useful for me, but VirusTotal claims all converted batch files as malicious. Is there any technical reason for this?
Hi
I'm Trying to get response from my website using your tool "winhttpjs.bat" but it's not working, what I'm doing wrong? sorry... I have poor knowledge about api and batch file.
files:
1-call.bat
call winhttpjs.bat https://*********** -method POST -body-file body.json -saveTo response.txt
2-body.json
{ "email":"****@****.***", "key":"*******************" }
3-and your tool: winhhtpjs.bat
when I run call.bat the cmd popup for a second and then an EMPTY response.txt file created!!
the email and key info are correct but for testing only.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.