Skip to main content

Posts

Showing posts with the label Windows Programming Tips and Tricks

Get display resolution from the command line

Get display resolution from the command line This will get both local resolution and remote desktop screen resolution using WMIC. c:\>wmic path Win32_VideoController get VideoModeDescription Sample out below when run on remote desktop session VideoModeDescription 1024 x 768 x 4294967296 colors 1912 x 989 x 4294967296 colors Tags: WMIC screen resolution

Debugging COM server startup problem using Visual Studio Debugger

This is closely related to debugging COM server using CDB/WinDbg combination .  Debugging startup or registration of out of process COM server can be tricky as the process is being started by the COM infrastructure (RpcSs). To debug a COM server called myserver.exe, do run the following: c:\> reg.exe ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\myserver.exe" /v debugger /t REG_SZ /d "vsjitdebugger.exe" /f The next time myserver.exe is activated the Visual Studio debugger will popup and provide an option to run a new instance or attach to an existing session. Note that same technique applies to Windows service.

How to install Assembly Binding Log Viewer (fuslogvw.exe) from Windows 10 SDK

The Assembly Binding Log Viewer(fuslogvw.exe) displays details for assembly binds. This information helps you diagnose why the .NET Framework cannot locate an assembly at run time. These failures are usually the result of an assembly deployed to the wrong location, a native image that is no longer valid, or a mismatch in version numbers or cultures.  If you don't have Visual Studio installed and you wanted to run it (fuslogvw.exe), do: Download Windows 10 SDK installer .  Install Windows 10 SDK and ensure Open fuslogvw.exe in C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools

Creating and logging in to a Windows Containers user with a password

Windows Containers by default uses ContainerAdministator user account with blank password. Creating a new user with password can be done but cannot be used in DockerFile for example. If you want to use another user in a container you have to create a user with blank password! To login to a container with a password, do the following: PS C:\> $cert = New-SelfSignedCertificate -DnsName "dontcare" -CertStoreLocation Cert:\LocalMachine\My PS C:\> winrm create winrm/config/Listener?Address=*+Transport=HTTPS ('@{Hostname="notimportant"; CertificateThumbprint="' + $cert.Thumbprint + '"}') PS C:\> winrm set winrm/config/service/Auth '@{Basic="true"}' PS C:\> $cred = New-Object pscredential 'timus', (ConvertTo-SecureString -String 'P@$$w0rd' -AsPlainText -Force) PS C:\> Enter-PSSession -Credential $cred -ComputerName localhost -Authentication Basic -UseSSL -SessionOption (New-PSSessionOption -Skip

Logging in to remote ssh server using private/public key pair

Logging in to remote ssh server using private/public key pair I have recently used VS Code for remote development and I am experiencing multiple disconnections a day. Like disconnecting form the docking station, moving around the house or just plain network issues. Using password to reconnect is becoming an annoyance. To help improve the workflow I have enabled private/public key pair, like: PS C:\> ssh-keygen -t rsa -b 2048 PS C:\> cat ~/.ssh/id_rsa.pub | ssh user@remote_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" This was tested on Windows 10 v1909.

Export the code section of a DLL or EXE to a file

How to export the code section of a DLL or EXE to a file using dumpbin. Open Developer Command Prompt for VS 2019 Export disassembly for a DLL, like c:\> dumpbin /disasm mydll.dll > mydll.asm References: https://docs.microsoft.com/en-us/cpp/build/reference/disasm?view=msvc-160 http://ntcoder.com/bab/2007/06/06/disassembling-a-dll-or-exe/

Debugging COM server using CDB/WinDbg combination

This actually applies to any application but most applicable for COM/DCOM servers and Windows services.  For example, to debug Notepad application remotely or on another session add the following to the registry on the target computer.  c:\> reg.exe ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\Notepad.exe" /v debugger /t REG_SZ /d "\"C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\cdb.exe\" -server tcp:port=5500 -g -G" /f  When Notepad.exe is run it will automatically be attached to a debugger (cdb). To connect to the cdb session using WinDbg, do  c:\> "C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\windbg.exe" -remote tcp:server=localhost,port=5500 ~ts

Load langs.xml failed! in Notepad++

I got Notepad++ 5.7 installed in Windows 7 Professional, used to work nicely but lately I am getting the following error: Load langs.xml failed! One reason could be that lang.xml got corrupted. This is not unexpected as Windows 7 I am using tends to hang-up and I need to force a hard reboot. One way to fix this is to: 1) Navigate to C:\Program Files\Notepad++. 2) Rename lang.xml to lang.xml.1. 3) Copy lang.model.xml to lang.xml Enjoy! References: http://superuser.com/questions/67128/notepad-load-langs-xml-failed ~ts

Windows dialog rc file is using dialog system units

This has never occurred to me before, I have been tweaking win32 API for awhile, but I really never paid much attention with the dimensions as saved in resource files for dialog boxes. Interestingly, the units stored in rc file are not really in pixel but rather in dialog unit. :( My understanding is that this will make the dialog independent of the font size. If user/developer changes the font size, the dialog box will adjust accordingly. Seems like a neat idea but I was dumbfounded at first sight. It makes my life harder though as I am trying to cross-reference runtime dialog boxes against design time. I was planning to cross ref them using the dimensions but it turns out to be not a good option. The quest is on........... Related links: http://msdn.microsoft.com/en-us/library/aa380902(VS.85).aspx ~rs~