Useful Bat Scripts

Johnatan56

Honorary Master
Joined
Aug 23, 2013
Messages
30,955

Johnatan56

Honorary Master
Joined
Aug 23, 2013
Messages
30,955
1. Create multiple folders with same name + number

Code:
@echo off
FOR /L %%A IN (Start,Increment,End) DO (
	mkdir "Name %%A"
)

Change the start to the first number, second is the increment, end is the final one. All should be integers.
Adjust name to the leading name, you can also change the end. MD is make directory.
 
Last edited:

Johnatan56

Honorary Master
Joined
Aug 23, 2013
Messages
30,955
2. Index all folders within directory

Only top level folders:
Code:
@echo off
dir  /a:d >> folderList.txt
change folderList to desired name.

In order to only have the folder names add /b:
Code:
@echo off
dir /a:d /b >> folderList.txt

Including sub-folders:
Code:
@echo off
dir /s /b /o:n /ad > folder_and_subfolder_list.txt
though the above will also include the parent folder location, e.g. C:\Parent\directryOfBat
 
Last edited:

ashfaak

Well-Known Member
Joined
Jan 5, 2010
Messages
330
Shutdown once a program has closed.

Code:
@ECHO OFF

:LOOP
tasklist | find /i "Firefox" >nul 2>&1
IF ERRORLEVEL 1 (
  GOTO CONTINUE
) ELSE (
  ECHO Firefox is still running
  Timeout /T 5 /Nobreak
  GOTO LOOP
)

:CONTINUE
Shutdown -s -t 00
 

supersunbird

Honorary Master
Joined
Oct 1, 2005
Messages
60,141
For adding registry key so that Outlook 2010 connects fast to a Office365 mailbox, if one is accessing it over a proxy server:

REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\RPC" /v "EnableForceHttpProxy" /t REG_DWORD /d 1 /f
 

Johnatan56

Honorary Master
Joined
Aug 23, 2013
Messages
30,955
Toggle Proxy On/Off, save as VBS:
Code:
Option Explicit 
Dim WSHShell, strSetting
Set WSHShell = WScript.CreateObject("WScript.Shell")

'Determine current proxy setting and toggle to oppisite setting
strSetting = wshshell.regread("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
If strSetting = 1 Then 
NoProxy
Else Proxy
End If

'Subroutine to Toggle Proxy Setting to ON
Sub Proxy 
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"
End Sub

'Subroutine to Toggle Proxy Setting to OFF
Sub NoProxy 
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD"
End Sub
 

MagicDude4Eva

Banned
Joined
Apr 2, 2008
Messages
6,479
Pro-tip: Use Git or Gist (gist.github.com).

/LinuxIsBetter: Find files with the same content (would be curious to see how this can be done in Windows):
find * | xargs md5sum | sort | uniq -D -w 34
 

Johnatan56

Honorary Master
Joined
Aug 23, 2013
Messages
30,955
Pro-tip: Use Git or Gist (gist.github.com).

/LinuxIsBetter: Find files with the same content (would be curious to see how this can be done in Windows):

The MS guys might need this - https://github.com/cldrn/nmap-nse-scripts/blob/master/scripts/smb-vuln-ms17-010.nse



This should help you out with all your WannaCry issues you have :p

As in same file type or duplicate?

Find duplicate files:
Windows:
Code:
@echo off
setlocal disableDelayedExpansion
set root="c:\test"
set "prevTest=none"
set "prevFile=none"
for /f "tokens=1-3 delims=:" %%A in (
  '"(for /r "%root%" %%F in (*) do @echo %%~znxF:%%~fF:)|sort"'
) do (
  set "currTest=%%A"
  set "currFile=%%B:%%C"
  setlocal enableDelayedExpansion
  if !currTest! equ !prevTest! echo "!currFile!"
  endlocal
  set "prevTest=%%A"
)
Set root location to correct location.
https://stackoverflow.com/questions/26076097/windows-batch-file-to-find-duplicates-in-a-tree
 
Top