Archive for the ‘Batch-Files’ Category
Posted by jpluimers on 2023/10/10
For tomorrow’s post Ookla speedtest CLI for Windows has some undocumented arguments to accept license and GDPR I neede the full path to the speedtest.exe which I had installed using Chocolatey.
I know chocolatey uses a shim that redirects to the actual executable, so a simple where speedtest.exe would not cut it.
My guess would be that the generated shim allowed to either get the target pathname out, or have the target pathname encoded in it.
Luckily the first applies: a few of the shim command-line parameters are in [Wayback/Archive] Chocolatey Software Docs | Executable shimming (like symlinks but better):
You pass these arguments to an executable that is a shim (e.g. executables in the bin directory of your Chocolatey install, not choco.exe):
--shimgen-help – shows this help menu and exits without running the target
--shimgen-log – logging is shown on command line
--shimgen-waitforexit – explicitly tell the shim to wait for target to exit – useful when something is calling a gui and wanting to block – command line programs explicitly have waitforexit already set.
--shimgen-exit – explicitly tell the shim to exit immediately.
--shimgen-gui – explicitly behave as if the target is a GUI application. This is helpful in situations where the package did not have a proper .gui file.
--shimgen-usetargetworkingdirectory – set the working directory to the target path. Useful when programs need to be running from where they are located (usually indicates programs that have issues being run globally).
--shimgen-noop – Do not actually call the target. Useful to see what would happen if you ran the command.
But the below dumps show more more (using [Wayback/Archive] Strings – Windows Sysinternals | Microsoft Docs, [Wayback/Archive] clip | Microsoft Docs and post-processing in [Wayback/Archive] Notepad++).
Back to the second solution,
strings C:\ProgramData\chocolatey\bin\speedtest.exe | findstr speedtest.exe
showed
speedtest.exe
..\\lib\speedtest\tools\speedtest.exe
Cannot find file at '..\\lib\speedtest\tools\speedtest.exe' (
speedtest.exe
speedtest.exe
And towards the first,
strings C:\ProgramData\chocolatey\bin\speedtest.exe | clip
resulted in this fragment:
Read the rest of this entry »
Posted in Batch-Files, Chocolatey, CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows | Leave a Comment »
Posted by jpluimers on 2023/09/12
TL;DR
I have converted the below PowerShell one-liner into this batch file (the ^| syntax is to ensure the pipe runs within PowerShell, not within the batch file):
PowerShell 'Get-CimInstance -Namespace "Root\cimv2\mdm\dmmap" -ClassName "MDM_EnterpriseModernAppManagement_AppManagement01" ^| Invoke-CimMethod
-MethodName UpdateScanMethod'
The why and how
Since I am a CLI person, and some Windows applications are only available on the Microsoft Store, I wanted to be able to initiate an update cycle from the command-line interface.
So I searched for [Wayback/Archive] microsoft store update all apps from the command-line – Google Search and found these to be valuable:
Read the rest of this entry »
Posted in Batch-Files, Development, Microsoft Store, Power User, PowerShell, Scripting, Software Development, Windows, Windows 10, Windows 11 | Leave a Comment »
Posted by jpluimers on 2023/08/29
Often the power is in the combinations of tools.
Read until the epilogue…
Prologue
In this case, I needed to be able to query the JSON results of calls to REST services from the command-line so I could process them in Batch files.
Since I could not find anything readily available, I originally Originally I opted for the PowerShell command-line scripting tool, as that ships with recent Windows versions and can re-use anything that .NET brings. But though [Wayback/Archive] .NET has built in JSON serialization support, there is [Wayback/Archive] no querying support in it.
Then I thought about Delphi, as it [Wayback/Archive] too has a built-in JSON parser, but even the well known [Wayback/Archive] JSON SuperObject library has no query support.
Back to .NET, which – like Delphi – has a well known and respected third party JSON library as well: [Wayback/Archive] NewtonSoft JSON aka JSON.net and that one [Wayback/Archive] does have support for querying JSON with the SelectToken function.
That’s the fundament of the rest of this article, with the potential to be used in a cross-platform as well.
So no need for a plan B.
Read the rest of this entry »
Posted in *nix, *nix-tools, .NET, Batch-Files, Conference Topics, Conferences, Development, Event, JavaScript/ECMAScript, jq, JSON, Power User, Scripting, Software Development, Windows, Windows Development | Leave a Comment »
Posted by jpluimers on 2023/07/28
and when upgrading to Chocolatey to version 2, I got this error:
Invalid argument --localonly. This argument has been removed from the list command and cannot be used.
The upgrade broke a small batch file choco-list-installed.bat that I run on a lot of systems including both old and new chocolatey installations some dating back to before 2015 having this simple content:
choco list --localonly
Read the rest of this entry »
Posted in Batch-Files, Chocolatey, Development, Power User, Scripting, Software Development, Windows | Leave a Comment »
Posted by jpluimers on 2023/05/18
After using Chocolatey for a long time and writing about it, I have written a few articles on other Windows package managers like winget and Scoop.
Part of the reason was that I wanted to install new systems in a semi-automatic way including WSL2 (Windows Subsystem for Linux 2).
As I have spent quite some time getting treated against metastasised rectum cancer, I missed part of the evolvement of WSL into WSL2 and of the winget evolvement.
The good news is that this simplified the scripted installation of WSL2 a lot, as over time, this got very easy, as confirmed in these posts/messages I found via [Wayback/Archive] winget wsl2 – Google Search:
I even found back this was announced when I was still in hospital: during the Build 2020 conference. A summary is at [Wayback/Archive] The Windows Subsystem for Linux BUILD 2020 Summary – Windows Command Line describing the introduction of wsl.exe --install and that it defaults to install WSL 2 as back-then already most Windows Insider build users using WSL had switched from WSL 1 to WSL 2.
Back to installing
Yesterday, in Windows “equivalents” for bash backticks in cmd and PowerShell, I showed how to get the wsl.exe information:
C:\temp>PowerShell -Command "SigCheck "$((Get-Command -CommandType Application wsl).Path)""
Sigcheck v2.82 - File version and signature viewer
Copyright (C) 2004-2021 Mark Russinovich
Sysinternals - www.sysinternals.com
c:\windows\system32\wsl.exe:
Verified: Signed
Signing date: 09:24 15/10/2021
Publisher: Microsoft Windows
Company: Microsoft Corporation
Description: Microsoft Windows Subsystem for Linux Launcher
Product: Microsoft« Windows« Operating System
Prod version: 10.0.19041.1320
File version: 10.0.19041.1320 (WinBuild.160101.0800)
MachineType: 64-bit
This was on one of my Windows 10 systems with version 21H2.
The installation progress was as follows and took ome 3 minutes on a 50 Mibit/s fiber connection:
C:\temp>wsl.exe --install
Installing: Virtual Machine Platform
Virtual Machine Platform has been installed.
Installing: Windows Subsystem for Linux
Windows Subsystem for Linux has been installed.
Downloading: WSL Kernel
Installing: WSL Kernel
WSL Kernel has been installed.
Downloading: Ubuntu
The requested operation is successful. Changes will not be effective until the system is rebooted.
Time to play around (:
–jeroen
Posted in Batch-Files, Chocolatey, Development, Power User, Scoop, Scripting, Software Development, Windows, Windows Development, winget, WSL Windows Subsystem for Linux | Leave a Comment »
Posted by jpluimers on 2023/05/17
A while ago, I needed the file information of wsl.exe on one of my Windows systems.
On Linux, I would do something like file `which bash` where file will give the file details and which gets you the full path to bash.
The file equivalent on Windows for me is [Wayback/Archive] Sigcheck – Windows Sysinternals | Microsoft Docs, which is part of [Wayback/Archive] File and Disk Utilities – Windows Sysinternals | Microsoft Docs.
The which equivalent on Windows for me is [Wayback/Archive] where | Microsoft Docs.
Read the rest of this entry »
Posted in bash, Batch-Files, CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | 1 Comment »
Posted by jpluimers on 2023/05/11
I finally got annoyed enough to figure out how to disable the Windows 10 news (and weather) feeds.
At first I thought the solution in this post worked for Windows 11 as well, but re-testing in Windows 11 it does not or does not (or not any more: given so many new Windows 11 releases with ever changing functionality I’m not surprised).
Disable Windows news feeds for current user
Failure: just disabling the news feed will automatically get it reset by explorer.exe
Based on the below sources, I made this small batch file:
Read the rest of this entry »
Posted in Batch-Files, Development, Power User, Registry Files, Scripting, Software Development, Windows, Windows 10, Windows 11 | Leave a Comment »
Posted by jpluimers on 2023/05/10
Sometimes, you want to restart the Windows explorer. This is already an exception case which you want to do when explorer hangs (for instance when taskbar icons do not respond any more), or has files locked which need to be modified. I described the latter in Inno Setup: Program Folder not showing up In Start > All Programs , with this very simple restart script:
taskkill /F /IM explorer.exe
start explorer
Even more exception is wanting to run explorer with a UAC elevated administrative token. I sometimes do this when moving around stuff from other users on the same computer without having them logged on (as that would lock the files or directories to be moved around).
The risk of running explorer under UAC elevation, is that any program you start will also start UAC elevated, so beware what you ask for…
This is how you start explorer under UAC elevation:
pwsh.exe -nol -noni -nop -w hidden -c "taskkill /f /im explorer.exe; start explorer -v runas -a /nouaccheck"
or if you run an older Windows version of PowerShell:
PowerShell.exe -nol -noni -nop -w hidden -c "taskkill /f /im explorer.exe; start explorer -v runas -a /nouaccheck"
These command-line options and verbs are used:
Time to explain a few:
Read the rest of this entry »
Posted in Batch-Files, CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows, Windows 10, Windows 11, Windows 7, Windows 8.1 | 1 Comment »
Posted by jpluimers on 2023/03/16
PolyShell is a script that’s simultaneously valid in Bash, Windows Batch, and PowerShell (i.e. a polyglot).
[Wayback/Archive] llamasoft/polyshell: A Bash/Batch/PowerShell polyglot!
Need to check this out, as often I have scripts that have to go from one language to the other or vice versa.
Maybe it enables one language to bootstrap functionality in the other?
The quest
The above polyglot started with a quest to see if I can could include some PowerShell statements in a batch file with two goals:
- if the batch file started from the PowerShell command prompt, then execute the PowerShell code
- if the batch file started from the
cmd.exe command prompt, then have it start PowerShell with the same command-line arguments
The reasoning is simple:
- PowerShell scripts will start from the PATH only when PowerShell is already running
- Batch files start from the path when either
cmd.exe or PowerShell are running
Lots of users still live in the cmd.exe world, but PowerShell scripts are way more powerful, and since PowerShell is integrated in Windows since version 7, so having a batch file bootstrap PowerShell still makes sense.
Since my guess was about quoting parameters the right way, my initial search for the link below was [Wayback/Archive] powershell execute statement from batch file quoting – Google Search.
I have dug not yet into this, so there are still…
Many links to read
These should give me a good idea how to implement a polyglot batch file/PowerShell script.
–jeroen
Posted in *nix, *nix-tools, bash, bash, Batch-Files, Development, JavaScript/ECMAScript, Perl, Polyglot, Power User, PowerShell, Scripting, Software Development | Leave a Comment »