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 »
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.
echo %SortDateTime% %SortDate%-%SortTime%
for /f "usebackq tokens=2* delims= " %%c in (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip" /v Path`) do (
endlocal & if exist %sevenzExe% %sevenzExe% a -tzip _my-build.%SortDate%-%SortTime%.zip MyServer.exe MyServer.map MyClient.exe MyClient.map
Posted in Batch-Files, Development, Power User, Scripting, Software Development | Leave a Comment »
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 »
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:
- Set output of a command as a variable (in this case a for loop variable)
- Execute PowerShell script in a .bat file
- PowerShell Get-Culture (which gets a .NET CultureInfo instance)
- 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 »
Posted by jpluimers on 2017/01/04
for /f "tokens=* delims= " %%f in (myfile) do
If you put
delims as the last parameter, then an ending space will be included as delimiter (at the start or in the middle it won’t).
A great tip by jeb and Joey in an answer for windows – Batch file FOR /f tokens – Stack Overflow
Posted in Batch-Files, Pingback, Scripting, Software Development, Stackoverflow | Leave a Comment »