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,640 other followers

Archive for the ‘Windows’ Category

Not sure why yet, but sometimes ping and nslookup cannot reverse lookup a machine by IPv4, but tracert can

Posted by jpluimers on 2019/07/15

A while ago I had a situation that when doing a ping or nslookup on an IPv4 address in Windows, it would not show the name through reverse lookup, but tracert could.

It is not quite the same as what happened in these posts:

This post is basically a place to put notes in when this ever happens again.

–jeroen

Posted in Power User, Windows | Leave a Comment »

PowerShell: get WindowsUpdate information

Posted by jpluimers on 2019/07/11

A while back, I needed to check Windows Update information on a few hosts, so I wanted to script it. Below are a few links that helped me solve this started.

Note: For Windows Update, you need the TiWorker.exe process, which can consume a lot of CPU. See DISM fix for Windows 8.1 high CPU usage of TiWorker.exe which is basically the same for all Windows versions since 8.0.

The infrastructure management on that site was ehm, a bit lacking, so PowerShell modules were out, heck even PowerShell itself was initially problematic (it needed running of unsigned sources.

A few notes on the above links.

Using Microsoft.Update.AutoUpdate

This gets the last date that anything was done (query, actual update, download) on Windows Updates, but does not guarantee the installation date; on some systems it does not even return a result:

$windowsUpdateObject = New-Object -ComObject Microsoft.Update.AutoUpdate
$windowsUpdateObject.Results

This one works better though:

$windowsUpdateObject = New-Object -ComObject Microsoft.Update.AutoUpdate
$windowsUpdateObject.Results.LastInstallationSuccessDate

Based on that, you can get the number of days like this:

(New-TimeSpan -Start $windowsUpdateObject.Results.LastInstallationSuccessDate.Date -End (Get-Date)).Days

Using Get-HotFix

Though some people report that InstalledOn can be empty, I’ve hardly that happen with Get-HotFix. The easiest way to get around that is filtering with | Where-Object InstalledOn -ne $null

The cool thing with Get-HotFix is that you can filter on the kind of security update, so this gets the moment the last security update got installed:

(Get-HotFix -Description "Security Update" | Where-Object InstalledOn -ne $null | Sort-Object InstalledOn -Descending | Select-Object -First 1).InstalledOn

And this the number of days since the last security update got installed:

(New-TimeSpan -Start (Get-HotFix -Description "Security Update" | Where-Object InstalledOn -ne $null | Sort-Object InstalledOn -Descending | Select-Object -First 1).InstalledOn -End (Get-Date)).Days

Step by step:

Get-HotFix -Description "Security Update"

Gets all the security updates.

| Where-Object InstalledOn -ne $null

Filter out entries having an empty InstalledOn.

Sort-Object InstalledOn -Descending

Get the most recent on the top.

| Select-Object -First 1

Select only the top entry.

(Get-HotFix -Description "Security Update"...).InstalledOn

Get only the InstalledOn property.

Get-Date

Get the current timestamp consisting of date and time.

New-TimeSpan -Start (...).InstalledOn -End (Get-Date)

Get a TimeSpan over a start and end timestamp.

(New-TimeSpan ...).Days

Get the Days property of a TimeSpan.

You can do the same for regular updates by changing the -Description parameter:

(Get-HotFix -Description "Update" | Where-Object InstalledOn -ne $null | Sort-Object InstalledOn -Descending | Select-Object -First 1).InstalledOn
(New-TimeSpan -Start (Get-HotFix -Description "Update" | Where-Object InstalledOn -ne $null | Sort-Object InstalledOn -Descending | Select-Object -First 1).InstalledOn -End (Get-Date)).Days

The Description values I found are these:

PS C:\Users\Developer> Get-HotFix | Sort-Object -Unique Description | Select-Object Description

Description
-----------
Hotfix
Security Update
Update

Ironically, since the command is called Get-HotFix, the Hotfix entries on my various Windows systems have been a  long long time ago:

(New-TimeSpan -Start (Get-HotFix -Description "Hotfix" | Where-Object InstalledOn -ne $null | Sort-Object InstalledOn -Descending | Select-Object -First 1).InstalledOn -End (Get-Date)).Days

When writing this in 2017, on Windows 8.1, this was more than 600 days, Windows 7 more than 400 days and Windows 10 did not have any Hotfix entries.

Old PowerShell versions

On PowerShell 2 and older, you get an error containing “Where-Object : Cannot bind parameter ‘FilterScript'”:

Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert the "InstalledOn" value of type "System.String" to type "System.Management.Automation.ScriptBlock".
At line:1 char:48
+ (New-TimeSpan -Start (Get-HotFix | Where-Object <<<< InstalledOn -ne $null | Sort-Object InstalledOn -Descending | Select-Object -First 1).InstalledOn -End (Get-Date)).Days
+ CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand

You solve it like this:

(New-TimeSpan -Start (Get-HotFix | Where-Object { $_.InstalledOn -ne $null } | Sort-Object InstalledOn -Descending | Select-Object -First 1).InstalledOn -End (Get-Date)).Days

By now code has become almost unreadable, so you can split it using backtick ` characters:

( `
New-TimeSpan -Start `
  ( `
    Get-HotFix | Where-Object { $_.InstalledOn -ne $null } `
    | Sort-Object InstalledOn -Descending `
    | Select-Object -First 1 `
  ).InstalledOn `
  -End (Get-Date)`
).Days

One more thing

On non-English Windows systems, the InstalledOn might actually be in the future, as you can view this happening by this simple command which I ran on 2017-11-02 :

Get-HotFix | Out-GridView

You solve it by adding a filter:

Get-HotFix | Where-Object InstalledOn -lt (Get-Date) | Out-GridView

If you run them from a script (like a batch file Get-HotFix ^| Out-GridView or ps1 file Get-HotFix | Out-GridView), then the grid-view will pop-up and immediately close because the PowerShell process ends. In that case, you need to change your scripts to add the -Wait parameter:

PowerShell Get-HotFix ^| Out-GridView -Wait

Powershell.exe -Command "Get-HotFix | Out-GridView -Wait"

Get-HotFix | Out-GridView -Wait

See:

In C#

If I ever want to do the same from C#, I need to figure out where to get the WUApiLib from; more on that library is at [WayBack] Use C# to interact with Windows Update – Stack Overflow and [WayBack] Searching, Downloading, and Installing Updates (Windows).

–jeroen

Posted in Development, Power User, PowerShell, Scripting, Software Development, Windows | Leave a Comment »

Colored text output in PowerShell console using ANSI / VT100 codes – Stack Overflow

Posted by jpluimers on 2019/07/08

Cool: Windows 10 allows ANSI/VT100 terminal escape codes without extra tooling. [WayBack] Colored text output in PowerShell console using ANSI / VT100 codes – Stack Overflow.

It is off by default (can be modified through the registry), can be turned on by either using an API call, or by piping through PowerShell.

For older versions, read [WayBack] Windows console with ANSI colors handling – Super User, of which this is a small quote:

For Windows version below 10, the Windows command console doesn’t support output coloring by default. You could install either CmderConEmuANSICON or Mintty (used by default in GitBash and Cygwin) to add coloring support to your Windows command console.

Via [WayBack] Did you know that you can enable VT100 terminal emulation in PowerShell as well as the Cmd window? This will allow you to do adb shell to your Android … – Lars Fosdal – Google+

–jeroen

Posted in Power User, Windows | Leave a Comment »

Windows: running a batch file during logon of a single or all users

Posted by jpluimers on 2019/07/01

You can automatically start processes during logon in a lot of ways (Trojans/Viruses find new ways all of the time).

The easiest way is to create a shortcut in one of the Startup folders. There are two of them: one for all the users, and one for the current user. Depending on your locale, Explorer can show a translated name, but the actual folder is named either of these:

  • "%AllUsersProfile%/Start Menu\Programs\Startup"
  • "%AppData%\Microsoft\Windows\Start Menu\Programs\Startup"

The folders do not exist at first, but are created when software starts putting shortcuts in them.

For a manual process, I created the two batch files below that create, then go to them (in both the console and explorer).

From there you can add shortcuts to things you want to run during logon.

They are based on:

I have successfully tested them in various Windows versions up until 10.

–jeroen

Batch files:

 

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

SequoiaView Homepage

Posted by jpluimers on 2019/07/01

I thought I had scheduled a blog post about the great tool on [WayBackSequoiaView Homepage, but didn’t. In the mean time, Paolo Buffa posted an overview with a really nice historic perspective:

Is amazing from how many years I’m using this program, and how many operating systems it managed to go thru almost unscathed, without modification.

Paolo Buffa

Source: [Archive.is] SequoiaView: a piece of history. – Data Center IT – Spiceworks

I still use it, despite it being quite old: 2002 era, written in Delphi 5. It’s beautiful in part because of its anciency, but also because it is so simple and intuitive that I still use it regularly.

The age also shows in the web page (which when writing it was still on-line): The SequiaView home page link above is actually a classic frame inside [WayBackThe SequoiaView Homepage. Back then, it was already starting to be considered obsolete to write HTML using frameset [WayBackFraming (World Wide Web) – Wikipedia.

The SequoiaView [WayBack] Download Page even points to non-existing ftp-download URLs via counter CGI scripts:

None of them have been archived by the WayBack machine: https://web.archive.org/web//ftp://ftp.win.tue.nl/pub/home/sequoia//

To verify alternative downloads, just check these hashes:

hash command filename hash output
$ md5 Sequoia1.3Install.zip MD5 (Sequoia1.3Install.zip) = 28d356f2bafe258805794257c284a075
$ md5 Sequoia1_3XPInstall.exe MD5 (Sequoia1_3XPInstall.exe) = 142586a5cc7a0139bde8c13e5cc4d301
$ shasum Sequoia1.3Install.zip 762ab30177a7f6a0d4f173fd2442ba7b61df4c2e Sequoia1.3Install.zip
$ shasum Sequoia1_3XPInstall.exe c1db10a0f7d36adbc14b5a7a3f08fc35db1bee8b Sequoia1_3XPInstall.exe

I’ve a copy in my archive that I just use in a portable way: just copy over SequoiaView directory with these files in it:

  • Archives.col
  • DEFAULT.COL
  • Images.col
  • License.txt
  • Movies.col
  • ReleaseNotes.txt
  • Sequoia.cnt
  • Sequoia.exe
  • SEQUOIA.HLP
  • Sound.col

A few things that could be fixed (if ever hopefully MagnaView open sources it: [WayBack] @jpluimers More @magnaview did you ever consider to open source the Delphi code for http://www.win.tue.nl/sequoiaview/ or give someone NDA access to fix some bugs?):

  • Access violation when re-scanning a drive
  • Option to show multiple links to the same physical file
  • Indication of more rights  needed to index a file or directory
  • Better explorer integration (via context menu)

Read the rest of this entry »

Posted in Delphi, Delphi 5, Development, Power User, Software Development, Windows | Leave a Comment »

 
%d bloggers like this: