batch-file

New line as a delimeter of FOR loop

帅比萌擦擦* 提交于 2020-01-11 10:22:08
问题 I am new to batch script, and I am trying to parse a file that has key value (kind) of pairs delimited by new line. For example: the value of abc 1234 the value of def 5678 the value of ghi 9876 I would like to read this file using new line as delimited so that I can access the values. Something like for /f "tokens=1,2,3 delims='\n'" %%i in ('findstr /C:the value of abc 'filepath') do echo %%j 回答1: You can't set 'new line' as delimiter. Try this: @echo off &setlocal for /f "tokens=1*delims=:"

SET Command - Floating point numbers?

末鹿安然 提交于 2020-01-11 10:08:39
问题 How do I use the SET command in windows for floating point arithmatic. /A stands for arithmetic and %VAR% prints the data of VAR not the name. For example when I do: SET /A VAR="2.5+3.1" ECHO %VAR% pause I get the error: 'Missing Operator'. The output (5.6) should be converted to floating point too I'm still busy learning the basic syntax. Regards, Snipe 回答1: The arithmetic operations of SET /A command are performed over 32-bits integer numbers only; however, you may easily simulate fixed

Unzip file error when running VBS script from a batch in Windows 10

前提是你 提交于 2020-01-11 07:37:11
问题 When running the VBS unzip code batch in Win 10, I'm getting the error below. What can be a reason for this, given it was reported working before by others? Changing target directories or explicitly setting them doesn't affect the error. @echo off setlocal enabledelayedexpansion cd /d %~dp0 set vbs="%temp%\_.vbs" call :UnZipFile "E:\Temp\" "%USERPROFILE%\Downloads\archive.zip\" exit /b :UnZipFile <ExtractTo> <newzipfile> if exist %vbs% del /f /q %vbs% >%vbs% echo Set fso = CreateObject(

obfuscating batch+HTA hybrid script

霸气de小男生 提交于 2020-01-11 07:26:07
问题 Following is the hybrid batch script: <!-- :: Batch section @echo off setlocal echo Select an option: for /F "delims=" %%a in ('mshta.exe "%~F0"') do set "HTAreply=%%a" echo End of HTA window, reply: "%{HTAreply}%" pause goto :EOF --> <HTML> <HEAD> <HTA:APPLICATION SCROLL="no" SYSMENU="no" > <TITLE>HTA Buttons</TITLE> <SCRIPT language="JavaScript"> window.resizeTo(374,100); function closeHTA(reply){ var fso = new ActiveXObject("Scripting.FileSystemObject"); fso.GetStandardStream(1).WriteLine

How to kill a process based on its image / file path?

纵饮孤独 提交于 2020-01-11 07:23:50
问题 How to kill a task based on the path of the executable? The usage of taskkill /F /IM "app.exe" doesn't work in this case because there are other programs running that have the same image/process/file name, but are totally different executables. The paths are different and the .exe files with same file name are different, too. Something like "taskkill /F /IM "C:\path\to\exe\app.exe" would be ideal. 回答1: Using WMIC , as suggested in the comments by Squashman, you can do it as a single command:

Batch: How to export yesterday's date keeping format [mm/dd/yyyy]?

只谈情不闲聊 提交于 2020-01-11 07:22:57
问题 I am trying to create an environment variable for yesterday's date. It MUST be in the format of MM/DD/YYYY . For code I currently have: set m=%date:~-7,2% set /A m -= 1 set DATE_YESTERDAY=%date:~-10,2%/%m%/%date:~-4,4% echo %DATE_YESTERDAY% This works great, HOWEVER, when I offset to yesterdays day with -1 instead of " 12/03/2019 " I get " 12/3/2019 ". Thus, missing the zero/0. Any ideas to keep format as MM/DD/YYYY ? I have seen many other questions regarding this, however, all come short!

Batch: How to export yesterday's date keeping format [mm/dd/yyyy]?

*爱你&永不变心* 提交于 2020-01-11 07:22:49
问题 I am trying to create an environment variable for yesterday's date. It MUST be in the format of MM/DD/YYYY . For code I currently have: set m=%date:~-7,2% set /A m -= 1 set DATE_YESTERDAY=%date:~-10,2%/%m%/%date:~-4,4% echo %DATE_YESTERDAY% This works great, HOWEVER, when I offset to yesterdays day with -1 instead of " 12/03/2019 " I get " 12/3/2019 ". Thus, missing the zero/0. Any ideas to keep format as MM/DD/YYYY ? I have seen many other questions regarding this, however, all come short!

Save output from FIND command to variable

一世执手 提交于 2020-01-11 07:00:50
问题 Like the title says, I'm trying to take the output from a FIND command and save it to a variable. Specifically, I'm using: DIR /b /s "C:\" | FIND "someexe.exe" to locate a specific .exe file, which seems to work fine, but then I want to save the results of FIND to use later in the same script. I've tried various different tweaks of: for /f "usebackq" %%i in (`DIR /b /s "C:\" | FIND "someexe.exe"`) do SET foobar=%%i but when I try to run the script the command window immediately closes

How can I split a binary file into chunks with certain size with batch script without external software?

≡放荡痞女 提交于 2020-01-11 06:43:30
问题 There are many reasons to want to split file into chunks - mainly for network transfer (e.g. e-mail attachments) but I'm sure there are scenarios that could require such thing I cannot imagine. So how can a file be split into chunks that can be easily assembled back to original file (including non-windows systems) ? What are possibilities: MAKECAB - the built-in Windows archiver - it can compress file and split it , but will be difficult to assemble the file on non-Windows machine. WSH

How to execute a batch file on uninstall in Inno Setup?

隐身守侯 提交于 2020-01-11 06:31:04
问题 I'm using code from How do you execute command line tools without using batch file in Inno Setup response to execute all my batch files on installation (before, after). No I want to execute them just when user click "YES" to uninstaller , but can't find a way to do it. It executes before the confirmation Here is my code from [Code] section: function InitializeUninstall(): Boolean; var ResultCode : Integer; begin Result := True; Exec(ExpandConstant('{app}\scripts\unset.bat'), '', '', SW_HIDE,