Skip to content

Instantly share code, notes, and snippets.

@juankb1024
juankb1024 / deleteRows.bat
Created May 15, 2018 21:21
Delete row from CA database even if versioning is exhausted
@echo off
:Top
Certutil -deleterow 8/31/2010 Request
If %ERRORLEVEL% EQU -939523027 goto Top
@juankb1024
juankb1024 / ErrorControl.bat
Created May 30, 2017 22:50
How to stop on error in batch
IF %errorlevel% neq 0 (exit /b %errorlevel%) ELSE (exit /b 0)
@juankb1024
juankb1024 / lastIndexOfString.bat
Created July 27, 2016 19:54
Found last index of string script
@echo off
setlocal enabledelayedexpansion
set S=%1
set I=0
set L=-1
:l
if "!S:~%I%,1!"=="" goto ld
if "!S:~%I%,1!"=="_" set L=%I%
set /a I+=1
goto l
@juankb1024
juankb1024 / Date.bat
Created July 26, 2016 19:41
Found nice date parsing windows cmd batch script
for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set MyDate=%%x
ECHO %MyDate%
set today=%MyDate:~0,4%-%MyDate:~4,2%-%MyDate:~6,2%
ECHO %today%
pause
@juankb1024
juankb1024 / AskPasswordMine.bat
Last active July 29, 2022 10:37
Found cool batch script to ask user credentials masking the password
@echo off
:: This batch file will create an HTML Application (HTA).
:: Values entered in the HTA will be saved as %TEMP%\USERIN.BAT
:: After the USERIN.BAT is CALLed from the main batch
:: (and assuming there is enough room in the environment)
:: environmental variables USERNAME and PASSWORD will be set.
:: It is your responsibility to delete the USERIN.BAT
:: after you CALL it. Because this batch file needs to
:: find itself, you must be sure to call it from your
:: main batch file with a full path and file name.
@juankb1024
juankb1024 / printFilePathComponents.bat
Created July 26, 2016 16:47
windows cmd to identify all components of a file passed as a parameter
set file=%1
FOR %%i IN ("%file%") DO (
ECHO filedrive=%%~di
ECHO filepath=%%~pi
ECHO filename=%%~ni
ECHO fileextension=%%~xi
)