The Wiert Corner – irregular stream of stuff

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

  • 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,706 other followers

Archive for the ‘Batch-Files’ Category

if statement – How to ask for batch file user input with a timeout – Stack Overflow

Posted by jpluimers on 2019/05/14

The trick is to use the choice command; see [WayBackif statement – How to ask for batch file user input with a timeout – Stack Overflow

–jeroen

Posted in Batch-Files, Development, Microsoft Surface on Windows 7, Power User, Scripting, Software Development, Windows, Windows 10, Windows 7, Windows 8, Windows 8.1, Windows 9, Windows Server 2000, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server 2016, Windows Vista, Windows XP | Leave a Comment »

Run cmd as elevated user (via: windows – How to run batch file command with elevated permissions? – Super User)

Posted by jpluimers on 2019/03/13

Based on [WayBack] windows – How to run batch file command with elevated permissions? – Super User:

powershell -command "Start-Process cmd.exe -Verb runas"

This works better than "runas /user:administrator cmd.exe" as that forces to use the specific Administrator account, whereas the PowerShell way allows you to specify the actual account during elevation.

You can extend this to run a command with one or more parameters based on [WayBack] Launch Elevated CMD.exe from Powershell – Stack Overflow (thanks [WayBack] mklement0):

powershell -command "Start-Process cmd.exe -Verb runas -Args /k, call, goto-bin"

This will actually pass “call goto-bin” to cmd.exe which tries to execute the “goto-bin” command (which I have around on the PATH as goto-bin.bat).

You can either use comma-separated parameters or a quoted string. In this expansion, comma-separated is easier in this PowerShell construct.

–jeroen

Posted in Batch-Files, CommandLine, Console (command prompt window), Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows | Leave a Comment »

msbuild: /p: or /property: but be ware of the equals sign

Posted by jpluimers on 2019/02/27

From [WayBackHow do I pass this common property to MSBuild using TeamCity? – Stack Overflow, I learned you can pass properties to msbuild using the /p:propertyname=value or /property:propertyname=value syntax (where you can quote "value" when needed):

I am using the TeamCity Visual Studio runner. I want to add a setting that is not accessible from Visual Studio./Property:FileAlignment=4096I typed that directly into the build step “Command line

However, when passing these parameters to batch files first, be aware that they can strip equals signs from parameters: [WayBack] windows – Preserving “=” (equal) characters in batch file parameters – Stack Overflow

I bumped into this when passing properties to https://bitbucket.org/jeroenp/wiert.me/src/tip/Run-Dependend-rsvars-From-Path.bat

–jeroen

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

Windows <= 10: batch file to open Windows Update panel

Posted by jpluimers on 2019/02/15

Up until Widows 8.1, you could use wuapp to start the Windows Update panel.

For a while, Windows 10 needed a cumbersome language specific workaround described at Windows 10 – language neutral batch file to start Windows.

That stopped working after a few builds, but I forgot to make a note in which build exactly. Already in Windows 10 build 10122, the icon in wucltux.dll, so this might have been shortly after the initial “RTM” (retroactively named 1507).

So for a while, I had this batch file:

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)

But now I have extended it to support old and new Windows versions:

if exist %windir%\System32\wuapp.exe (
  %windir%\System32\rundll32.exe url.dll,FileProtocolHandler wuapp.exe
) else (
  %windir%\explorer ms-settings:windowsupdate
)

–jeroen

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

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

In windows, can I redirect stdout to a (named) pipe in command line? – Super User

Posted by jpluimers on 2019/01/14

Interesting thought [WayBackIn windows, can I redirect stdout to a (named) pipe in command line? – Super User.

The only problem seems to be a good way of creating/removing those pipes.

–jeroen

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

 
%d bloggers like this: