Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Friday, May 3, 2024

Cannot start cmd.exe on Windows 10

Somehow I encountered the problem that I could not start the Windows Command Prompt (cmd.exe). The solution turns out is to remove a key from the registry. A number of posts points to the removal of HKCU\Software\Microsoft\Command Processor\AutoRun. A complexity comes from the factor that the user account is a standard user account; howeer, regedit needs to run as an administrator, which means the HKCU is the administrator, not the standard user.

To address this issue, we can perform the following steps

  1. Figure out the user's sid:
    
        whoami /user
        
    The sid begins with S- that we can easily recognize from the output.
  2. Open regedit, and browse to HKEY_USERS, to the user according to the user's sid, to Software, to Microsoft, to Command Processor, and then locate AutoRun, and remove it.

A StackOverflow post indicates several more keys to remove, but it is not necessary in my case, but it is good to document it, just in case in the future


reg delete "HKCU\Console" /f
reg delete "HKCU\Software\Microsoft\Command Processor" /v "AutoRun" /f
reg delete "HKLM\Software\Microsoft\Command Processor" /v "AutoRun" /f
reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File 
Execution Options\cmd.exe" /f

Sunday, January 14, 2024

Thursday, March 30, 2023

Binding Process to TCP/UDP Port Failure on Windows

Windows has the concept of reserved TCP/UDP ports. These ports can nonetheless be used by any other application. These can be annoying because the reserved ports would not shown be used when we query used ports using netstat. For instance, if we want to bind TCP port 23806 to an application, we determine the availability using the netstat command, such as


C:> netstat -anp tcp | find ":23806"

C:>

The output is blank, which means that the port is unused. However, when we attempt to bind the port to a process of our choice, we encounter an error, such as


bind [127.0.0.1]:23806: Permission denied

This is annoying. The reason is that the port somehow becomes a reserved port. To see this, we can query reserved ports, e.g.,


C:> netsh int ipv4 show excludedportrange protocol=tcp

Protocol tcp Port Exclusion Ranges

Start Port    End Port
----------    --------
      1155        1254
      ...          ...
     23733       23832
     23833       23932
     50000       50059     *

* - Administered port exclusions.


C:>
  

which shows that 23806 is now a served port. What is really annoying is that the range can be updated by Windows dynamically. There are several methods to deal with this.

  1. Method 1. Stop and start the Windows NAT Driver service.
    
      net stop winnat
      net start winnat
      
    After this, query the reserved the ports again. It is often the reserved ports are much limited when compared to before, e.g.,
    
    C:>netsh int ipv4 show excludedportrange protocol=tcp
    
    Protocol tcp Port Exclusion Ranges
    
    Start Port    End Port
    ----------    --------
          2869        2869
          5357        5357
         50000       50059     *
    
    * - Administered port exclusions.
    
    C:>
      
  2. Method 2. If you don't wish to use this feature of Windows, we can disable reserved ports.
    
    reg add HKLM\SYSTEM\CurrentControlSet\Services\hns\State /v EnableExcludedPortRange /d 0 /f
    

Sunday, January 29, 2023

Ressetting Network Stack on Windows

Sometimes, I want to reset the network stack on Windows. I found that Intel has a good documentation for it. I copy the steps below:

Resetting the network stack


ipconfig /release
ipconfig /flushdns
ipconfig /renew
netsh int ip reset
netsh winsock reset

Running WireGuard Windows GUI Client as Non-administrator User

As indicated in this document, and also referenced in several places, we can run the WireGuard Windows GUI client as a non-administrator user with the functionality limited to toggle on or off the existing VPN tunnel configuration created.

This generally involves two steps as an administrator on the Windows host:

  1. Create a registration key, which is specified in the command below
    
        reg add HKLM\Software\WireGuard /v LimitedOperatorUI /t REG_DWORD /d 1 /f
        
  2. Add the non-administrator user we wish to be able to toggle on/off the tunnel to the the Network Configuration Operators builtin group. We can do this by invoking the lusrmgr command.

Saturday, July 30, 2022

Windows 10 does not know some "devices" of a Dell Precision Workstation

I was installing Windows 10 on a Dell Precision T3620 Workstation. Although the systems worked well, it bothers me that the Windows Device Manager reported that some devices were not recognized, i.e., an yellow exclamation point on the devices, like the following screenshot shows,

In fact, these unrecognized devices are,

  • PCI Data Acquisition and Signal Processing Controller,
  • PCI Memory Controller, and
  • SM Bus Controller

It turns out that many users had similar problem, and the solution is to update some device drivers. However, I was slightly frustrated that the very driver that solved my problem (all three unrecognized devices) wasn't listed under "driver" on the Dell Support's website. Instead, it was listed under "Utility", and was the "Intel Chipset Device Software."

Saturday, April 16, 2022

Setting up X2Go

If you wish to have Windows Remote Desktop-like experience when we access a Linux hosts, X2GO is probably the best solution. X2GO runs on the NX or NoMachine protocol. Contrast to the solution that runs a X server on a Linux host, and run a client application on another host, we can leave a session and resume it with NX or X2GO, which offers the experience similar to Windows Remote Desktop. 

Below is a "minimal" setup for a Fedora Linux server and a Windows client. We call it a "minimal" setup because we do not install a full Linux desktop, rather, we install a graphical terminal like xterm. 

  1. Install the X2GO server on Fedora Linux
    
    sudo dnf install x2goserver x2goserver-xsessions xterm
        
  2. Install the X2GO client on Windows. For this, we download the client installation package, and run the installation package.
  3. Now we can use X2GO -- nothing needs to be done on the Linux server
    1. Start the X2GO client on the Windows host
    2. Create a new sessiono if we have not done so
    3. When creating the new session, we specify the Linux host we connect to and the user name we log on
    4. It is important to note that we should select the "Session Type" as "Single Application" and enter the command as "/usr/bin/xterm" since we did not install a full Linux Deskop and only installed xterm
    5. To connect to the Linux server and run xterm, we open the session.
    6. We can close the session. Next time when we open it, it resumes from where we close it

Friday, April 8, 2022

SSH cannot connect to any non-local SSH servers on WSL 2

Recently, I encountered a strange problem. That is, I cannot connect to any non-local SSH servers from a WSL 2 terminal using the ssh client from WSL 2. However, I would not have any problem to connect to these SSH servers using ssh.exe from Windows and PuTTY or other SSH clients on Windows. Here is what I observe when I try to connect Github.com,


ssh -vvv -T ssh@github.com
OpenSSH_7.9p1 Debian-10+deb10u2, OpenSSL 1.1.1d  10 Sep 2019
debug1: Reading configuration data /home/hui/.ssh/config
debug1: /home/hui/.ssh/config line 17: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "github.com" port 22
debug2: ssh_connect_direct
debug1: Connecting to github.com [140.82.113.3] port 22.

The process hangs on "Connecting to ..." until times out. I attempted all of the methods discussed in this threads and the method of adding a Firewall rule for WSL, but to no avail in my case. The solution finally works for me is to restart the Windows Container Networking service.

Using PowerShell, we can restart the service on command line as follows,


PS C:\WINDOWS\system32> Restart-Service -Force -Name hns

The solution came to me because I wanted to restart the networking stack of WSL and to see if it would resolve this issue. The method to do it comes from this Github gist. To restart the networking stack of WSL, run the following commands,


# Restart the Host Network Service 
Restart-Service -Force -Name hns
# Restart the Windows Subsystem for Linux Manager
Restart-Service LxssManager
# Restart the WSL Network adapter
Restart-NetAdapter -Name "vEthernet (WSL)"

In my case, restarting the Windows Container Networking service (hns) is sufficient for me to resolve the problem.

Reference

  1. Reset your WSL network connection trying to fix WSL2 media disconnected error
  2. WSL2 SSH can't connect to any public SSH server
  3. SSH connections hanging from WSL2

Tuesday, June 8, 2021

Solving problem updating Windows 10 to version 20H2 or newer

I have been trying to update Windows 10 to Windows 10 version 20H2. The problems that I  encountered are,

  1. When using Windows Update, I saw the update process stuck at 61%, eventually failed. I am not the only one, clearly. For instance, there are numerous online threads. Here are several examples, example 1, example 2, and example 3. Want to see more, just Google it. 
  2. When using Windows 10 Update Assistant, one of the recommended method, I saw it stuck at 99%, for eons. 

 Finally, I found the right answer, i.e., the method documented in this post,

This  method worked for me. The caveat is that 1) contrast of using Windows update, I have to wait for two to three hours before it finishes; 2) it updates my Windows to 21H1 directly. Regardless, updating to a new version is what I wanted since Microsoft is going to cease supporting older versions of Windows 10.

The steps as outlined in the article linked in the above are,

  1. Open File Explorer, type C:\$GetCurrent, and then press Enter.
  2. Copy and paste the Media folder to the desktop. If you don't see the folder, select View and make sure the check box next to Hidden items is selected.
    Restart your PC, open File Explorer, type C:\$GetCurrent in the address bar, and then press Enter.
  3. Copy and paste the Media folder from the desktop to C:\$GetCurrent.
  4. Open the Media folder and double-click Setup.
  5. Follow the instructions to start the upgrade. On the Get important updates screen, select Not right now, and then select Next.
  6. Follow the instructions to finish upgrading to Windows 10. After you're done, make sure to install available updates. Select the Start  button, and then select Settings  > Update & Security  > Windows Update > Check for updates.



Friday, March 19, 2021

Displaying Command Line Arguments on Windows without Installing Additional Software?

On Windows, can we obtain from the command line a process's command line arguments without installing any additional software like the Process Explorer of the Windows Sysinternal? As documented by a Stack Overflow discussion, the answer is Yes, via WMIC. Here are two examples,

  1. List all processes and their command line arguments
    
      WMIC path win32_process get Caption,Processid,Commandline
      
  2. List a process, e.g., chrome.exe, and its command line arguments
    
      WMIC path win32_process where "caption='chrome.exe'" get Caption,Processid,Commandline  
      

Tuesday, January 12, 2021

Computing File Hash on Windows

Two "build-in" tools we can use to compute file hash values on Windows are Windows PowerShell and CertUtil.

In Windows PowerShell, we can compute a hash value for a file using Get-FileHash command.

C:\> PowerShell
PS C:\> help Get-FileHash

NAME
Get-FileHash

SYNTAX
Get-FileHash [-Path] <string[]> [-Algorithm {SHA1 | SHA256 | SHA384 | SHA512 | MACTripleDES | MD5 | RIPEMD160}]
[<CommonParameters>]

Get-FileHash -LiteralPath <string[]> [-Algorithm {SHA1 | SHA256 | SHA384 | SHA512 | MACTripleDES | MD5 |
RIPEMD160}] [<CommonParameters>]

Get-FileHash -InputStream <Stream> [-Algorithm {SHA1 | SHA256 | SHA384 | SHA512 | MACTripleDES | MD5 | RIPEMD160}]
[<CommonParameters>]


ALIASES
None


REMARKS
Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
-- To download and install Help files for the module that includes this cmdlet, use Update-Help.
-- To view the Help topic for this cmdlet online, type: "Get-Help Get-FileHash -Online" or
go to https://go.microsoft.com/fwlink/?LinkId=517145.

Windows also comes with a tool called CertUtil that provides an option to compute file hash value as well.


C:\>CertUtil -hashfile -?
Usage:
  CertUtil [Options] -hashfile InFile [HashAlgorithm]
  Generate and display cryptographic hash over a file

Options:
  -Unicode          -- Write redirected output in Unicode
  -gmt              -- Display times as GMT
  -seconds          -- Display times with seconds and milliseconds
  -v                -- Verbose operation
  -privatekey       -- Display password and private key data
  -pin PIN                  -- Smart Card PIN
  -sid WELL_KNOWN_SID_TYPE  -- Numeric SID
            22 -- Local System
            23 -- Local Service
            24 -- Network Service

Hash algorithms: MD2 MD4 MD5 SHA1 SHA256 SHA384 SHA512

CertUtil -?              -- Display a verb list (command list)
CertUtil -hashfile -?    -- Display help text for the "hashfile" verb
CertUtil -v -?           -- Display all help text for all verbs
  
Below are examples.

C:\> CertUtil -hashfile C:\Windows\System32\drivers\etc\hosts sha512
SHA512 hash of C:\Windows\System32\drivers\etc\hosts:
59119e66f5945029f8652c5981589d95cace534adc6780ccea736b7e776615caa0b567c14d161271d6066f57d9bab0d4055850162f5a046c0456264b7b9e7508
CertUtil: -hashfile command completed successfully.

C:\> PowerShell
PS C:\> Get-FileHash -Path C:\Windows\System32\drivers\etc\hosts -Algorithm sha512 | Format-List


Algorithm : SHA512
Hash      : 59119E66F5945029F8652C5981589D95CACE534ADC6780CCEA736B7E776615CAA0B567C14D161271D6066F57D9BAB0D4055850162F5
            A046C0456264B7B9E7508
Path      : C:\Windows\System32\drivers\etc\hosts

Sunday, October 4, 2020

Configuring Windows Dynamic Port Allocation?

Some Windows applications can reserve TCP or UDP ports which may cause some other applications fail to run. These threads provide solutions to this problem,

The solution are generally three.

  1. Removing/disabling the offending application or Windows feature. For instance, the threads point out Hyper-V is often the culprit because it reserves ports dynamically and unpredictably. We can disable it if we aren't using it,
    
    REM disable Hyper-V
    dism.exe /Online /Disable-Feature:Microsoft-Hyper-V
      
    In PowerShell, do this to remove all Hyper-V adapters,
    
    Get-HNSNetwork | Remove-HNSNetwork
      
  2. Reset dynamic port range from which the offending application reserves ports. For instance, for Hyper-V, for instance, we can do this,
    
    dism.exe /Online /Disable-Feature:Microsoft-Hyper-V
    
    netsh int ipv4 add excludedportrange protocol=tcp startport=50051 numberofports=1
    
    dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All
        
  3. Disable dynamic port allocation, i.e.,
    
    reg add HKLM\SYSTEM\CurrentControlSet\Services\hns\State /v EnableExcludedPortRange /d 0 /f
        

Saturday, August 29, 2020

X11 Forwarding from Linux to Windows

We are discussing here how to set up SSH's X11 Forwarding to forward Linux systems X11's display to a X server on Windows, and discuss a few challenges. Just to be clear, our objective is to run X server on the Windows host, and forward Linux systems' display to the X server on the Window host.

  1. On the Windows host, install a X server, such as, vcXsrv
  2. On the Linux system, install xauth package, e.g., on Debian or Ubunbu, we run
        sudo apt-get install xauth    
    On Fedora Linux, we run
        sudo dnf install xorg-x11-xauth    
  3. On the Linux system, check if SSH daemon (sshd)'s X11 Forwarding feature is enabled. To do this, we open /etc/ssh/sshd_config, and look for the following line,
      X11Forwarding yes  
    If we don't find this line, we must add it. If this is line is commented out, we must uncomment it. After that we reload SSH daemon's configuration, such as,
      sudo systemctl reload sshd
    
  4. On Windows host, we run
    
        ssh -Y the_username@the_linux_system    
    or
        ssh -X the_username@the_linux_system
        

Remarks

If SSH's X11 Forwarding is successfully set up, there isn't a need to set the DISPLAY variable on the Linux system; otherwise, we aren't doing X11 Forwarding, instead, we just display to a display that isn't local.

The preconditions for X11 Forwarding to work is that we need xauth program on both client and server side, i.e., in our case, xauth must be present on both the Windows system and the Linux system. In fact, vcXsrv comes with a copy of xauth. 

Another problem is about access control. In the above set up, we run as a different user from the login user on the Linux system, we will see a "couldn't connect to display" error. For instance, after we log in we can run X11 program without any problem; however, when we run the same program with sudo, we will observe the error. This is actually an access control problem, and this cannot be resolved by running a command like "xhost +" as the login user, because the command like "xhost +" is only about controlling access to the "local" display. This linked post explains very well how we should resolve this, that is, we need to use xhost to add the X11 cookie associated with the remote display set up by the login user to the new user. We repeat the steps outline in the post below,

  1. After we log in with via SSH with X11 Forwarding, e.g.,
    
        ssh -X the_username@the_linux_system
        
  2. On the Linux system, query the X11 cookie using xauth,
    
        xauth list $DISPLAY 
        
    The output looks the following,
    
        the_linux/unix:10  MIT-MAGIC-COOKIE-1  123456989abcdef1000011
        
  3. On the Linux system, show the value of the DISPLAY variable
    
        echo $DISPLAY
        
    The output may be,
    
        the_linux:10.0
        
  4. On the Linux, become the user we wish to run a GUI program, e.g., to become the root user,
    
        sudo -s
        
  5. As the new user, e.g., the root, set the X11 cookie to the one we show in the above, e.g.,
    
        xauth add the_linux/unix:10  MIT-MAGIC-COOKIE-1  123456989abcdef1000011
        
    Note that after "add", we simply copy and paste the X11 cookie value that we list before.
  6. As the new user, check if the DISPLAY is set and if set, it has the same value as the old user. If not, set it, e.g.,
    
        export DISPLAY=the_linux:10.0
        
    It is often that this step isn't necessary because it is often set and the value is identical to the one listed under the older user.

X Server on Windows Host for Linux Virtual Machine Guests

We can run thin Linux (or other UNIX) virtual machine guests systems including Docker containers without GUI. Linux systems often need memory on the order of hundred megabytes to run. Without GUI, we can run more virtual machine instances and run the instances faster. These instances on the VMs or in the containers can still run GUI applications if we install X server on the host. 

For host systems that comes with X natively, this is quite easy, and just need to inform the guest which display to use. However, not all host systems have X natively. For instance, Windows does not come with one natively. Luckily, there are  a few free or inexpensive X Server for Windows available. Below are the simple steps to realize this idea on a Windows host,

  1. Download and install vcXsrv
  2. Launch vcXsrv using the XLaunch shutcut. If you run it on the host for the guest Linux systems on the hosted VMs, and the host has firewall like Windows Defender to prevent outside access to the X server, you can safely check "Disable access control" to allow any X client to display on the server. 
  3. vcXsrv has a tray icon on Windows. Right-click the tray icon, open "Show log", and the log will tell us what host IP addresses the X server is bound to, such as, 192.168.1.101. 
  4. Log in to a Linux guest,  such as, ssh to the Linux guest,
  5. Set the DISPLAY environment variable, e.g., if our host IP address is 192.168.1.101
    export DISPLAY=192.168.1.101:0.0
    
  6. Lanuch a GUI application from the Linux guest, and we shall see it's running and the X server is displaying the GUI.

Very importantly, we are not using SSH's X forwarding feature here. Not everyone can successfully enable SSH's X forwarding feature smoothly. This method is simpler to set up to those who have a problem to set SSH's X forwarding up. 

In next post, we shall discuss what it takes to set up SSH's X forwarding.


Thursday, August 27, 2020

X Servers for Windows

When we run multiple thin Linux/Unix systems on virtual machines on a Windows host, we wish to have X server for windows. There are in fact a few free ones, at least for personal use. Here are some of these X servers.

  • MobaXterm that integrates PuTTY and Cygwin/X with feature-rich GUI
     
  • VcXsrv that is based on from xorg's source code, compiled with Visual Studio (Visual C++, so vc - X - srv)
     
  • Cygwin/X.
     
  • Xming. An older version of Xming is available for free, but new versions require a donation like $20. 

Friday, June 19, 2020

"git status" shows modifications, but "git diff" shows nothing

I encountered a strange problem about a git repository today, that is, when I do a git status, git reports there are modifications. However, when I do a git diff, git reports no difference, like the following,

$ git status .
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   .gitignore

$ git diff
$

After a little bit digging, apparently a few others encountered the same problem as a Stack Overflow discussion indicates.

The cause of my case are two,
  1. Some files have different line endings from the version in the repository as a result that I was working on a Windows Subsystem for Linux and had the git's configuration property core.autocrlf set as input. I revealed the Windows line ending using vim, as in the following,
    
    $ vim -b .gitignore
    # Compiled class file^M
    *.class^M
    ^M
    # Log file^M
    *.log^M
    ^M
    # BlueJ files^M
    *.ctxt^M
    

    where the ^M characters are the Windows line endings, i.e., CR LF. I got rid of the line endings using sed, as in,
    
     sed -i -e s/^M// .gitignore
    

    Note that we enter the line ending by pressing CRTL-V CRTRL-M
  2. The second issue is that some files have different permissions from those in the repository. Since I was using a Windows Subsystem for Linux on a Windows host, it is difficult for me to set the permissions identical to those in the repository. However, we can let git to ignore permission difference, i.e.,
    
    git config --local core.filemode false
    

    where I only did this for the repository. If we wish to do this for globally for all repositories, just issue the command without the --local option.


Monday, June 1, 2020

Problem: Application Icon on Windows Taskbar Becomes White Square

I was using a Windows 10 system. I noticed somehow the icon of application on the taskbar became a white square, like this picture shows,


I figured out a solution to resolve this. That is to delete the thumbnail icon cache that we can find at %LOCALAPPDATA%\Microsoft\Windows\Explorer, i.e.,

  1. Open a Windows Command Prompt window
  2. Do the following from the command line on the Windows Command Prompt window
    1. taskkill /F /IM explorer.exe
    2. del %LOCALAPPDATA%\Microsoft\Windows\Explorer\thumbcache_*.db
    3. explorer.exe
Sometimes, it is also necessary to remove all the thumbnails themselves, i.e., run the Disk Cleanup application. From the command line, that is,
  1. Run the Disk Cleanup application, i.e., cleanmgr.exe
  2. Uncheck everything using the user interface, and check "Thumbnails" (See the screen shot). 
  3. Click OK to confirm
  4. Exit the Disk Cleanup application

The system will rebuild the thumbnail cache and the thumbnails.

Sunday, May 24, 2020

"grep" does not work on WSL?

Does "grep" not always work on the Windows Subsystem for Linux (WSL) on Windows 10? I has been investigating this problem that bothered me a great deal. Here is what I saw,

$ vi josh.txt

What I saw in vi is,

  Josh
  Anonymous
~       
~                                                                        ~  

OK, let's grep something ...

$ grep "Josh" josh.txt
$ echo $?
1

Should I have seen a match and exit-code 0 instead? I haven't gotten a clue until I ran strace,

$ strace grep "Josh" josh.txt
...
openat(AT_FDCWD, "josh.txt", O_RDONLY|O_NOCTTY) = 3
fstat(3, {st_mode=S_IFREG|0777, st_size=42, ...}) = 0
read(3, "\377\376 \0 \0J\0o\0s\0h\0 \0\r\0\n\0 \0 \0A\0n\0o\0n\0"..., 98304) = 42
read(3, "", 98304)                      = 0
close(3)                                = 0
...
$

Good, I saw 'J', 'o, ..., but what are these '\377', '\376', ... Instead of doing octal numbers to hexadecimal number conversion, I let strace do this for me, and

$ strace grep "Josh" josh.txt
...
openat(AT_FDCWD, "josh.txt", O_RDONLY|O_NOCTTY) = 3
fstat(3, {st_mode=S_IFREG|0777, st_size=42, ...}) = 0
read(3, "\xff\xfe\x20\x00\x20\x00\x4a\x00\x6f\x00\x73\x00\x68\x00\x20\x00\x0d\x00\x0a\x00\x20\x00\x20\x00\x41\x00\x6e\x00\x6f\x00\x6e\x00"..., 98304) = 42
read(3, "", 98304)                      = 0
close(3)                                = 0                            = 0
...
$

Huh? No characters? What are these "\xff\xfe\x20\x00..."? How about

$ cat josh.txt
    J o s h
     A n o n y m o u s
$

At this moment, I realized that the character encoding is neither ASCII nor UTF-8, and it must be something else, and the leading bytes are the "Byte Order Marks (BOM)". Windows API documentation has a page that has the following,

Byte order markDescription
EF BB BF UTF-8
FF FE UTF-16, little endian
FE FF UTF-16, big endian
FF FE 00 00 UTF-32, little endian
00 00 FE FF UTF-32, big-endian
Note
A byte order mark is not a control character that selects the byte order of the text.

It turns out the text file is encoded in "UTF-16, little endian". Just for fun, I ran file,

$ file josh.txt
josh.txt: Little-endian UTF-16 Unicode text, with CRLF line terminators
$

That's it! I got this file from downloading it in Webex on the Windows host, and Webex must have encoded it in the Windows default encoding scheme, "UTF-16, little endian".

How do I grep this file? There might be many other methods. But I just use the iconv command  to convert the encoding from utf-16 to utf-8, and then redirect the output to grep, like,

$ iconv -f utf-16le -t utf-8 josh.txt | grep "Josh"
  Josh
$ echo $?
0
$

Problem solved!

Sunday, May 17, 2020

Failed to Start Virtual Machine in VMWare Workstation Player

I upgraded VMWare Workstation Player to 15.5.2 on a Windows 10 host. It failed to start any virtual machines after the upgrade. The error message is

VMware Player and Device/Credential Guard are not compatible. VMware
Player can be run after disabling Device/Credential Guard. Please visit
http://www.vmware.com/go/turnoff_CG_Dg for more details. 
 

I followed the instruction to make sure that the Device Guide was disabled. Since I have a Windows Pro, to disable Device Guard, I run the Local Group Policy Editor

mmc gpedit.msc


However, the problem remains. It turned out an additional step was need, that was to run the following command as the system adiministrator and reboot the Windows host,

bcdedit /set hypervisorlaunchtype off 

Wednesday, May 13, 2020

Configuring Windows LAN Manager Authentication Level

Windows LAN Manager authentication level can cause interoperability issues between Windows servers and Samba clients, between Windows clients and Samba servers, and sometimes between Samba servers and clients, and Windows servers and clients.

On Windows, the authentication level is in the Windows Registry at

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\LmCompatibilityLevel




There are two methods to change the authentication level. Regardless on which edition of Windows, one can always directly edit the Windows Registry. The value of the LmCompatibilityLevel can be 0, 1, 2, 3, 4, and 5 on Windows 10. According to the official Windows 10 documentation, the meaning of the 6 levels are as follows,



SettingDescription Registry security level
Send LM & NTLM responses Client devices use LM and NTLM authentication, and they never use NTLMv2 session security. Domain controllers accept LM, NTLM, and NTLMv2 authentication. 0
Send LM & NTLM – use NTLMv2 session security if negotiated Client devices use LM and NTLM authentication, and they use NTLMv2 session security if the server supports it. Domain controllers accept LM, NTLM, and NTLMv2 authentication. 1
Send NTLM response only Client devices use NTLMv1 authentication, and they use NTLMv2 session security if the server supports it. Domain controllers accept LM, NTLM, and NTLMv2 authentication. 2
Send NTLMv2 response only Client devices use NTLMv2 authentication, and they use NTLMv2 session security if the server supports it. Domain controllers accept LM, NTLM, and NTLMv2 authentication. 3
Send NTLMv2 response only. Refuse LM Client devices use NTLMv2 authentication, and they use NTLMv2 session security if the server supports it. Domain controllers refuse to accept LM authentication, and they will accept only NTLM and NTLMv2 authentication. 4
Send NTLMv2 response only. Refuse LM & NTLM Client devices use NTLMv2 authentication, and they use NTLMv2 session security if the server supports it. Domain controllers refuse to accept LM and NTLM authentication, and they will accept only NTLMv2 authentication. 5


LmCompatibilityLevel 1 provides the highest level of compatibility, but isn't recommended is it permits dated and less secure LM and NTMLv1.

On a Windows Professional edition system, we can also use the Local Group Policy Editor. In an elevated Windows Command Prompt window, i.e., a Windows Command Prompt window ran as the system administrator, open the Local Group Policy Editor by the following command,

mmc gpedit.msc

Then, locate the option via the following navigation sequence,
  1. (In the Left Navigation Pan) Computer Configuration
  2. (In the Left Navigation Pan)Windows Settings
  3. (In the Left Navigation Pan)Security Settings
  4. (In the Left Navigation Pan)Local Policies
  5. (In the Left Navigation Pan)Security Options
  6. (In the Right Policy Option Pan) Network security: LAN Manager authentication level
Double-click on the option, and select one of the 6 options that corresponds to the 6 LmCompatibilityLevel values.



Alternatively, one may directly open the Local Security policies by the command,

mmc secpol.msc

With this, there would be a shorter navigation sequence,
  1. (In the Left Navigation Pan)Local Policies
  2. (In the Left Navigation Pan)Security Options
  3. (In the Right Policy Option Pan) Network security: LAN Manager authentication level