Thursday, 18 January 2018

P/invoke CreateProcessWithLogonW causes Error 1058: The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.

If you're running the CreateProcessWithLogonW Win32 API command with P/invoke you may receive the following error

Error 1058: The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.
 
This can occur if the "Secondary Logon" (seclogon) service is disabled in the services control panel. 


Wednesday, 17 January 2018

Can't copy and paste from a Barclays bank statement PDF (SECURED in the title bar)

You might find that when you try and copy and paste from a Barclays bank statement you're no longer allowed to do this. If you're trying to get a reference number out of the document this is infuriating as you end up having to try and copy a 16 digit number by eye, and when doing business accounts doing it many times.

You'll see that there's no copy command when you right click the text



You'll notice the word SECURED in the title bar






This is some nonsensical security added by Barclays.

To resolve this issue do the following


  • Open the PDF file in Google Chrome
  • Click Print
  • Select the destination as Save As PDF
  • Click Save and select a destination
You can now copy from the PDF











Friday, 5 January 2018

Get-Disk PowerShell cmdlet does not show dynamic disks.

We've been updating our Windows server documentation tool to use the newer Get-Disk cmdlets on Windows 2012 and above and found that when you configure a disk as dynamic


The Get-Disk PowerShell cmdlet disappears the disk. It's interesting as the same thing happens in Server Manager. Whilst dynamic disks are deprecated it's still frustrating when things disappear from a user interface rather than showing them as an "Unsupported Disk".


You can however see dynamic disks when using the Get-PhysicalDisk cmdlet

Basic Disk
  • Shows in Disk Management MMC
  • Shows in Get-Disk cmdlet
  • Shows in Server Manager
  • Shows in Get-PhysicalDisk cmdlet
  • Shows in Win32_DiskDrive


Dynamic Disk
  • Shows in Disk Management MMC
  • Doesn't show in Get-Disk cmdlet
  • Doesn't show in Server Manager
  • Shows in Get-PhysicalDisk cmdlet
  • Shows in Win32_DiskDrive


Storage Pool Member Disk
  • Doesn't show in Disk Management MMC
  • Doesn't show in Get-Disk cmdlet
  • Doesn't show in Server Manager
  • Shows in Get-PhysicalDisk cmdlet
  • Doesn't show in Win32_DiskDrive

Storage Pool Virtual Disk
  • Shows in Disk Management MMC
  • Shows in Get-Disk cmdlet as a Microsoft Storage Space Device
  • Shows in Server Manager
  • Doesn't show in Get-PhysicalDisk cmdlet (it's not a physical disk)
  • Does show in Win32_DiskDrive

Friday, 8 December 2017

Get-LocalGroupMember PowerShell cmdlet issues - An unspecified error occurred: error code = 1789

We've recently been working on the new local account management PowerShell cmdlets and found an issue with the Get-LocalGroupMember cmdlet

If a user group has a member that cannot be resolved normally most APIs will return just the SID of the account, and certainly the Computer Management MMC shows the user as the SID and as an unknown account.


Unfortunately the  Get-LocalGroupDetails PowerShell cmdlet fails completely with the following error



 Get-LocalGroupDetails. An unspecified error occurred: error code = 1789

If you use an -ErrorAction SilentlyContinue parameter the cmdlet will return with no members which is obviously misleading as there may be other, valid accounts in the group.



Thursday, 7 December 2017

How to relock a Bitlocker drive after you've unlocked it with PowerShell

If you're using Windows Server 2012 or above you can use PowerShell to relock a bitlocker drive that you have already unlocked

Lock-BitLocker E:

However if the drive is in use you may see this error

Lock-BitLocker : Access is denied. (Exception from HRESULT: 0x80070005
(E_ACCESSDENIED))
At line:1 char:1
+ Lock-BitLocker E:
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], UnauthorizedAcc
   essException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Lock-BitLocke
   r
 

This is simple to resolve - simply add the -ForceDismount parameter
Lock-BitLocker E: -ForceDismount  



Tuesday, 5 December 2017

Running start in a batch file or .cmd file displays a command prompt instead of running the application.

I've recently run into an issue whereby I'm trying to start several Visual Studio environments as another user with the runas command for remote testing.

So I created a batch file with the runas command which then launches a second batch file that starts 4 instances of Visual Studio.

@echo off
cls
start "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe"
start "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe"
start "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe"
start "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe"

However instead 4 command prompt windows are loaded.

When you run the same command live inside a command prompt it works.

This is a case of not reading the documentation! The first parameter of the start command is the window title, so you need two double quotes, or just enter any title.

@echo off
cls
start "" "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe"
start "" "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe"
start "" "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe"
start "" "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe"

Friday, 1 December 2017

System.IO.File.ReadAllText method and Default encoding with Nano server

You may find that running the following command on Nano will fail
[System.IO.File]::ReadAllText($path, [System.Text.Encoding]::Default)

Exception calling "ReadAllText" with "2" argument(s): "Value cannot be null.

This is because the Default encoding is not longer in the list of valid encoding types


To resolve this issue either call ReadAllText with no parameter, or a different encoding parameter. Or better still use the Get-Content cmdlet which takes the pain away from this encoding.