Showing posts with label Windows Tips and Tricks. Show all posts
Showing posts with label Windows Tips and Tricks. Show all posts

Monday, November 20, 2023

Get Network Interface Card GUID in Windows

Get Network Interface Card GUID in Windows

Method 1 - using netsh
PS C:\> netsh lan show interfaces
Below shows sample output
There is 1 interface on the system:

    Name             : Ethernet
    Description      : Microsoft Hyper-V Network Adapter
    GUID             : 17ab0088-6ca5-4aac-82bb-c533700cda21
    Physical Address : 00-15-5D-1C-45-00
    State            : Connected. Network does not support authentication.
Method 2 - using PowerShell WMI
PS C:\> Get-CimInstance -ClassName Win32_NetworkAdapter | Select-Object -Property DeviceID, GUID, Name
Below shows sample output
DeviceID GUID                                   Name
-------- ----                                   ----
0                                               Microsoft Kernel Debug Network Adapter
1        {17AB0088-6CA5-4AAC-82BB-C533700CDA21} Microsoft Hyper-V Network Adapter
2                                               WAN Miniport (SSTP)
3                                               WAN Miniport (IKEv2)
4                                               WAN Miniport (L2TP)
5                                               WAN Miniport (PPTP)
6                                               WAN Miniport (PPPOE)
7                                               WAN Miniport (IP)
8                                               WAN Miniport (IPv6)
9                                               WAN Miniport (Network Monitor)

Saturday, November 18, 2023

Control Panel console command equivalent

There are cases where you might need to run some of the Control Panel applets to perform quick configuration like add user accounts under different user credentials(say administrator account). Anyway below lists the files and equivalent Control Panel applet.
Command Description
access.cpl Accessibility Options
appwiz.cpl Add or REmove Programs
bthprops.cpl Bluetooth configuration
desk.cpl Display Properties
firewall.cpl Windows Firewall
hdwwiz.cpl Add Hardware Wizard
inetcpl.cpl Internet Properties
intl.cpl Regional and Laguage Options
irprops.cpl Infrared Properties
joy.cpl Game Controllers
jpicpl32.cpl Java Control Panel
main.cpl Mouse Properties
mmsys.cpl Sounds and Audio Devices Properties
ncpa.cpl Network Connections
powercfg.cpl Power Options Properties
sysdm.cpl System Properties
telephon.cpl Phone and Modem Properties
timedate.cpl Date and Time Properties
wscui.cpl Security and Maintenance

Friday, April 28, 2023

Install Windows Terminal using winget

Install Windows Terminal using winget

Windows Terminal is a new, modern, feature-rich, productive terminal application for command-line users. It includes many of the features most frequently requested by the Windows command-line community including support for tabs, rich text, globalization, configurability, theming & styling, and more.

To install Windows Terminal using winget, do:
PS C:\>winget install Microsoft.WindowsTerminal
Note:
To install winget on Windows 2022 follow this link.

Wednesday, April 26, 2023

Getting "Store is not available in your country or region" in Microsoft Store

Getting "Store is not available in your country or region" in Microsoft Store

When I open Microsoft Store I am getting the following error message on Windows 10 20H2
Store is not available in your country or region
Code: 0x87e10002
CV: SGmLmAU6/UWYL9FO
To fix this, open Control Panel | Clock and Region | Region, check if it shows the following:

Format: English (United States)
Match Windows display language (recommended)
If yes, then change it to:

Format:
English (United States)
Click on Apply and then close and open Microsoft Store.

Sunday, November 20, 2022

Native boot into VHDX

Native boot into VHDX

Why would you boot into VHDX instead of dual booting? Because it is easy(ier) vs adjusting partition post-Windows installation. And the partition layout may not be easy to adjust without using advanced partitioning tool. Also booting into native VHDX gives full access to the hardware without the penalty of virtualization. This allow you to run say other virtuaization on top of native boot!
I prepare VHDX using Hyper-V and once it is ready to my liking I use the VHDX to boot into it. Below are the general steps:

  • Copy a VHDX into the desired location. For example, copy C:\VMs\W21H1M2\Virtual Hard Disks\W21H1M2.vhdx to C:\VMs\NaviteBoot\NaviteBoot.vhdx
  • Mount C:\VMs\NaviteBoot\NaviteBoot.vhdx using File Explorer
  • Note of volume/drive letter for the mounted VHDX, e.g. V:
  • Change directory to V:\Windows
  • Run bcdboot V:\Windows. This should have added the VHDX into the boot options
  • Optional, change the boot description. Get the GUID entry for the just added VHDX. The GUID can be displayed by running bcdedit /v. Look for the GUID that corresponds to the folder location of the VHDX. Then run bcdedit /set like below
    c:\>bcdedit /set {02e6ec1d-d2c3-11ea-a71f-b3a579503f4b} description “W10VHDX2”

    Where:
    {02e6ec1d-d2c3-11ea-a71f-b3a579503f4b}: was taken from step above
    W10VHDX2: is the label
  • Optional, change boot order. Using the same GUID, run bcdedit /default like below
    c:\>bcdedit /default {02e6ec1d-d2c3-11ea-a71f-b3a579503f4b}
Now reboot and note that the first entry in the boot sequence is labled W10VHDX2. To delete the entry use msconfig.exe

Thursday, October 06, 2022

Windows Quick Tip: Enable/Disable Run Dialog history

Windows Quick Tip: Enable/Disable Run Dialog history

Windows Run Dialog history can be disalbed for security or enabled for convenience
To enable/disable, navigate to the registry key below:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
Start_TrackProgs DWORD
0 = Turn off
1 = Turn on

Saturday, May 14, 2022

Quick Tip: Disable Windows Firewall from the command line

Disable Windows Firewall from the command line

Using elevated command prompt, run:

c:\> netsh advfirewall set allprofiles state off

Keywords: Windows Firewall netsh
Reference(s):
http://techgenix.com/quicklyturnonoffwindowsfirewallusingcommandline/

Saturday, February 05, 2022

How to properly delete Windows10Upgrade folder

How to properly delete Windows10Upgrade folder

So you are running out of storage and you are staring at Windows10Upgrade and wondering how you can get rid of it correctly? Well, fear no more, it is easy. Open up Control Panel and navigate to Control Panel\All Control Panel Items\Programs and Features or appwiz.cpl. Then look for Windows 10 Upgrade Assistant and uninstall the application.See below for how it looks like.

Get hostname from an IP in Windows

Get hostname from an IP in Windows


Method 1 - Using built-in ping. This only works if a working DNS server has reverse look-up configured.
c:\>ping -a 8.8.8.8

The hostname for 8.8.8.8 was returned as dns.google, below shows the output details.
Pinging dns.google [8.8.8.8] with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=52ms TTL=112
Reply from 8.8.8.8: bytes=32 time=56ms TTL=112
Reply from 8.8.8.8: bytes=32 time=59ms TTL=112
Reply from 8.8.8.8: bytes=32 time=56ms TTL=112

Ping statistics for 8.8.8.8:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 52ms, Maximum = 59ms, Average = 55ms

Method 2 - Using nslookup
c:\>nslookup 8.8.8.8

This is the same as method 1, it needs a working DNS to provide the information
Server:  somedc.com
Address:  some_ip_here

Name:    dns.google
Address:  8.8.8.8

Method 3 - Using nbtstat
c:\>nbtstat -a 192.168.1.101

With the added bonus that it also shows the MAC address and name M1. Limitiation is that this only works on network that supports NetBIOS and on the same collision domain.
vEthernet (nat):
Node IpAddress: [172.20.64.1] Scope Id: []

    Host not found.

Ethernet:
Node IpAddress: [192.168.1.100] Scope Id: []

           NetBIOS Remote Machine Name Table

       Name               Type         Status
    ---------------------------------------------
    WORKGROUP     	<00>  GROUP       Registered
    M1			  	<00>  UNIQUE      Registered
    M1     		  	<20>  UNIQUE      Registered

    MAC Address = 00-15-5D-0E-53-54

Method 4 - Using psexec
c:\>psexec \\192.168.1.101 -u administrator -p p@$$w0rd hostname

This is using psexec to run hostname command remotely. Note that it shows the hostname (M1), IP, and exit code of the command hostname.
PsExec v2.2 - Execute processes remotely
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals - www.sysinternals.com


M1
hostname exited on 192.168.1.101 with error code 0.

Thursday, November 18, 2021

Resolve Windows NetBIOS name in Ubuntu 20.04

Resolve Windows NetBIOS name in Ubuntu 20.04

It is very common to have a mix of Windows and Ubuntu/Linux in an enterprise environment. There are scenarios where Ubuntu can get IP via DHCP but not enroll the machine to DNS. To resolve Windows NetBIOS machine name in Ubuntu in a workgroup environment do the following. Install nss-winbind like below

$: sudo apt install libnss-winbind

Then update /etc/nsswitch.conf. On Ubuntu 20.04, this will be line 12, which should look like below:
hosts:          files wins dns

Refs:
https://8thstring.blogspot.com/2010/05/resolve-netbios-name-in-ubuntu.html

Thursday, August 19, 2021

Change Windows 10 to dark mode and black background

Change Windows 10 to dark mode and black background using Registry (cmd.exe)
c:\> reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" /v "AppsUseLightTheme" /t REG_DWORD /d "0" /f
c:\> reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" /v "SystemUsesLightTheme" /t REG_DWORD /d "0" /f
c:\> powershell -command add-type -typedefinition """"using System;`n using System.Runtime.InteropServices;`n public class PInvoke { [DllImport(`"""user32.dll`""")] public static extern bool SetSysColors(int cElements, int[] lpaElements, int[] lpaRgbValues); }""""; [PInvoke]::SetSysColors(1, @(1), @(0x000000))

 

Ref:

https://superuser.com/questions/1214337/update-hkcu-control-panel-colors-background-via-cmd-and-apply-immediately

Sunday, May 02, 2021

Monday, April 12, 2021

How to delete Windows protected partition

How to delete Windows protected partition

Run diskpart in elevated command prompt, like:
c:\> diskpart
Then follow the prompts like below:
Microsoft DiskPart version 10.0.18362.1171

Copyright (C) Microsoft Corporation.
On computer: M1

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          180 GB    53 GB        *

DISKPART> select disk 0

Disk 0 is now the selected disk.

DISKPART> list partition

  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
  Partition 1    System             100 MB  1024 KB
  Partition 2    Reserved            16 MB   101 MB
  Partition 3    Primary            126 GB   117 MB
  Partition 4    Recovery           499 MB   126 GB

DISKPART> select partition 4
DISKPART> delete partition override
DISKPART> exit
Leaving DiskPart...

Windows containers cannot use USER instruction to change user with a password

 I have a Dockerfile like below:


FROM mcr.microsoft.com/windows/servercore:20H2 as final
RUN net user timus P@$$w0rd123!@# /add /Passwordchg:No
RUN WMIC USERACCOUNT WHERE "Name='timus'" SET PasswordExpires=FALSE
RUN net localgroup administrators timus /add
USER timus
RUN whoami

Running this will fail with an error message like below:
C:\mydocker>docker build -t myimages:1.0.0 -f Dockerfile Sending build context to Docker daemon 678.8MB Step 1/6 : FROM mcr.microsoft.com/windows/servercore:20H2 as final ---> 4943ff812624 Step 2/6 : RUN net user timus P@$$w0rd!@# /add /Passwordchg:No ---> Running in 95d4d70138d8 The command completed successfully. Removing intermediate container 95d4d70138d8 ---> d00130167ea2 Step 3/6 : RUN WMIC USERACCOUNT WHERE "Name='timus'" SET PasswordExpires=FALSE ---> Running in 0d05945d8f70 Updating property(s) of '\\0D05945D8F70\ROOT\CIMV2:Win32_UserAccount.Domain="0D05945D8F70",Name="timus"' Property(s) update successful. Removing intermediate container 0d05945d8f70 ---> b37beaf1f201 Step 4/6 : RUN net localgroup administrators timus /add ---> Running in 82871efe73b3 The command completed successfully. Removing intermediate container 82871efe73b3 ---> 17d3a473c8e6 Step 5/6 : USER timus ---> Running in fc69793db808 Removing intermediate container fc69793db808 ---> 8e515f363d94 Step 6/6 : RUN whoami ---> Running in 1d88d8a9e089 container 1d88d8a9e0897835a2cd00082f92ef99d7896623ce7ba7c1921176569c670cfe encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The user name or password is incorrect. (0x52e) [Event Detail: Provider: 00000000-0000-0000-0000-000000000000] [Event Detail: Provider: 00000000-0000-0000-0000-000000000000] [Event Detail: onecore\vm\compute\management\orchestration\vmhostedcontainer\processmanagement.cpp(173)\vmcomputeagent.exe!00007FF720E4A40B: (caller: 00007FF720E05C8B) Exception(2) tid(388) 8007052E The user name or password is incorrect. CallContext:[\Bridge_ProcessMessage\VmHostedContainer_ExecuteProcess] Provider: 00000000-0000-0000-0000-000000000000] extra info: {"CommandLine":"cmd /S /C whoami","User":"timus","WorkingDirectory":"C:\\","CreateStdInPipe":true,"CreateStdOutPipe":true,"CreateStdErrPipe":true,"ConsoleSize":[0,0]}
This is failing because as of this writing (4/12/2021) Windows containers does not support using USER instruction for users with password, it is expecting it to be blank!
See this GitHub issue for details - https://github.com/moby/moby/issues/28585

My docker cheat sheet

My docker cheat sheet

Installing base container image for Server Core 2019. If you are running Windows Server 2019 virtual machine, this will allow you to run the container in process isolation mode instead of Hyper-V isolation. Process isolation is more light-weight and allows you to run a Server 2019 VM with dynamic memory setting in Hyper-V.

PS C:\> docker image pull mcr.microsoft.com/windows/servercore:ltsc2019
To list downloaded images, do
PS C:\> docker images
This will show something like below
PS C:\> docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
mcr.microsoft.com/windows/servercore   ltsc2019            3eaa9ebbf51f        5 weeks ago         5.25GB

To run a Windows container based on servercore:ltsc2019, do:
PS C:\> docker run -it mcr.microsoft.com/windows/servercore:ltsc2019 cmd.exe
This will open a cmd.exe prompt. This should allow you to play inside that container.

This container should be running in process isolation mode. To verify that get the cotainers running, like:
PS C:\> docker ps -a
Sample output below
PS C:\> docker ps -a
CONTAINER ID        IMAGE                                           COMMAND             CREATED             STATUS                      PORTS               NAMES
0dcd0e1f1a01        mcr.microsoft.com/windows/servercore:ltsc2019   "cmd.exe"           7 seconds ago       Up 6 seconds                                    gracious_ride
c9e4859871c2        mcr.microsoft.com/windows/servercore:ltsc2019   "cmd.exe"           56 minutes ago      Exited (0) 50 minutes ago                       distracted_curran
540f0bd0e7fd        mcr.microsoft.com/windows/servercore:ltsc2019   "cmd.exe"           About an hour ago   Exited (0) 58 minutes ago                       reverent_bohr
Note that 0dcd0e1f1a01 shows it is running (STATUS column shows Up x seconds).

Now check Isolation mode, like
PS C:\> docker inspect 0dcd0e1f1a01 | Select-String -Pattern "Isolation"
It shoud show something like below
PS C:\> docker inspect 0dcd0e1f1a01 | Select-String -Pattern "Isolation"
            "Isolation": "process",
To re-start an exited container, e.g., 540f0bd0e7fd do:
PS C:\> docker start 540f0bd0e7fd
This will start a container in the background. To interact with it do:
PS C:\> docker attach 540f0bd0e7fd
To start another shell on a conatiner, do:
PS C:\> docker exec -it 540f0bd0e7fd cmd.exe

Changing Windows user password from the command line

 Changing Windows user password from the command line


C:\> net user  administrator newpassword

Can’t install Hyper-V Management Tools on Windows Server 2019 if the machine/VM does not support virtualization

Can’t install Hyper-V Management Tools on Windows Server 2019 if the machine/VM does not support virtualization
 

I tried to install PowerShell Direct to manage docker containers but can't install the feature, trying to run:

PS C:\> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell

 yields with error below:

PS C:\Users\Administrator> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell
Enable-WindowsOptionalFeature : One or several parent features are disabled so current feature can not be enabled.
At line:1 char:1
+ Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException
    + FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand

Apparently this happens when the OS is running on a machine that does not support virtualization or the VM does not have nested virtualization enabled.

Sunday, April 11, 2021

Creating new Windows admnistrator user from the command line

Creating new Windows admnistrator user from the command line

I am not quite comfortable with too few options available when creating a new user in Windows 10 Home edition, so I do the following.

c:\> net user timus P@$$w0rd123!@# /add /Passwordchg:No
c:\> WMIC USERACCOUNT WHERE "Name='timus'" SET PasswordExpires=FALSE
c:\> net localgroup administrators timus /add

Tuesday, March 30, 2021

Changing the color of the title bar via registry

This will change the title bar to black
c:\> reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v "AutoColorization" /t REG_SZ /d "0" /f
c:\> reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM" /v "ColorPrevalence" /t REG_DWORD /d "1" /f
c:\> reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM" /v "AccentColor" /t REG_DWORD /d 4282203453 /f
c:\> reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM" /v "AccentColorInactive" /t REG_DWORD /d "13882323" /f

Saturday, January 16, 2021

Install .Net 3.5 from the command line

Install .Net 3.5 from the command line
c:\> dism.exe /online /enable-feature /all /featurename:NetFX3 /Source:E:\sources\sxs

Formatting code in Blogger

I have been using Github gists to share code and I have no plan of abandoning it. For smaller/one liners, I sometimes use div element with ...