Friday, March 10, 2017

How to list certificate installed on my PC using PowerShell.

Use the below code to get the list of certificate installed .

This code gets the children of “Cert:\LocalMachine\my ” , adds the same to an array

$certificates = @{}
Get-ChildItem Cert:\LocalMachine\my | % {
        $cert = $_
        $_.DnsNameList | % {
   
            [string] $dnsName = $_
            $certificates[$dnsName] = $cert.Thumbprint
        }
    }

 $certificates

Tuesday, November 29, 2016

Configuring an Executable to Run as a Service on Windows Server?


Windows NT Resource Kit provides below two utilities that allow you to run an executable as a service

Instrsrv.exe
Srvany.exe
 

More details regarding the same can be found at the below links.


Wednesday, October 26, 2016

Wednesday, September 28, 2016

How to Cast int to enum and back in C#?

How to Cast int to enum and back in C#

To cast an int to enum just do the bellow

MyEnum foo = (MyEnum)myInt;                        

To cast to enum from a string value do the below


MyEnum foo = (MyEnum) Enum.Parse(typeof(MyEnum), myString)

Tuesday, September 27, 2016

How do I convert byte[] to stream in C#?

The easiest way to convert a byte array to a stream is using the MemoryStream class:

Stream stream = new MemoryStream(byteArray);

Thursday, June 30, 2016

How to ignore certificate errors while debugging...


While debugging we use to come across certificate errors when talking to other sites. One of the solution to ignore these certificate errors while debugging is to add the below code as first statement in Program.cs  

 

ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;