The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,842 other followers

Archive for the ‘Batch-Files’ Category

For – Loop through a range of numbers | Windows CMD |

Posted by jpluimers on 2017/06/27

Since I always forget:

for /l %1 in (1,2,200) do echo %1 >> text-%1.txt

This creates files with incremental filenames like this:



via: For – Loop through a range of numbers | Windows CMD | [WayBack]

Posted in Batch-Files, Development, Scripting, Software Development | 4 Comments »

How bad is the Windows command line really?

Posted by jpluimers on 2017/04/13

How bad is the Windows command line really?

The Windows command line is bad. Very bad.

But it took until recently for old Windows versions – that out of the box had either no or poor PowerShell versions – to have slowly died.

So only now PowerShell finally has become an option that really works across all Windows versions I use. Go PowerShell!


Posted in Batch-Files, Development, PowerShell, Scripting, Software Development | Leave a Comment »

7zip: compress from the command-line; a few notes and a small batch file

Posted by jpluimers on 2017/04/04

I wanted to compress a few files from the current directory in a zip file using the 7z.exe command-line version of 7zip.

The trick is about finding where 7z.exe is as the directory containing 7z.exe is not in the Windows PATH.


call SortDateTime.bat
echo %SortDateTime% %SortDate%-%SortTime%

for /f "usebackq tokens=2* delims= " %%c in (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip" /v Path`) do (
  set sevenzExe="%%d7z.exe"
endlocal & if exist %sevenzExe% %sevenzExe% a -tzip MyServer.exe MyClient.exe



Posted in Batch-Files, Development, Power User, Scripting, Software Development | Leave a Comment »

defrag.exe: tracking an already in progress operation can be done from non-admin session

Posted by jpluimers on 2017/03/17

When you want to defrag.exe (the built-in Windows one, not the SysInternals Windows NT4 one, so make sure SysInternals comes last in your path) a volume, you have to run it with an elevated UAC Admin token.

But I just found out that you can do this without an Admin token:

C:\Windows\System32>Defrag.exe C: /t /v /u
Microsoft Drive Optimizer
Copyright (c) 2013 Microsoft Corp.

Tracking operation on (C:)...

Performing pass 2:
        Free Space Consolidation:  31% complete...

This makes it much easier to separate monitoring scripting from execution.


Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »

Windows 10 – language neutral batch file to start Windows

Posted by jpluimers on 2017/02/22

A while ago, I bitched that Microsoft moved away the Windows Update out of the Control panel into a language depended place (in Windows 10 1511 update broke the Hyper-V networking – Fix network connection issues).

Since then I had to maintain too many locales running Windows 10. So here is the batch file:

for /f "delims=" %%A in ('PowerShell -Command "(Get-Culture).Name"') do explorer "%LocalAppData%\Packages\windows.immersivecontrolpanel_cw5n1h2txyewy\LocalState\Indexed\Settings\%%A\AAA_SystemSettings_MusUpdate_UpdateActionButton.settingcontent-ms"

It uses these tricks:

  1. Set output of a command as a variable (in this case a for loop variable)
  2. Execute PowerShell script in a .bat file
  3. PowerShell Get-Culture (which gets a .NET CultureInfo instance)
  4. CultureInfo.Name property (which has the nl-NL, en-US, etc codes in it)

It replaced this simple batch-file which has worked for like 10 years:

%windir%\System32\rundll32.exe url.dll,FileProtocolHandler wuapp.exe


via: Windows Update Shortcut – Create in Windows 10 – Windows 10 Forums

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, Batch-Files, CommandLine, Development, Power User, PowerShell, Scripting, Software Development, Windows, Windows 10 | Leave a Comment »

%d bloggers like this: