Something a little shorter would be: Code: Public Function CurrentMD5() Dim sb As New StringBuilder() Dim Hash As MD5 = MD5.Create() Using mf As FileStream = File.OpenRead(Process.GetCurrentProcess().ProcessName.ToString() & ".exe") For Each b As Byte In Hash.ComputeHash(mf) sb.Append(b.ToString("x2").ToUpper()) Next End Using Return sb.ToString() End Function Usage: Code: Try Label1.Text = CurrentMD5() Catch ex As Exception MsgBox(ex.Message) End Try
You could also use AppDomain.CurrentDomain.FriendlyName to return the applications name along with the file extension. ie: myapp.exe VB.NET Code: Public Function CurrentMD5() Dim sb As New StringBuilder() Dim Hash As MD5 = MD5.Create() Using mf As FileStream = File.OpenRead(AppDomain.CurrentDomain.FriendlyName) For Each b As Byte In Hash.ComputeHash(mf) sb.Append(b.ToString("x2").ToUpper()) Next End Using Return sb.ToString() End Function Code: Label1.Text = CurrentMD5() C# Code: public static string CurrentMD5() { StringBuilder sb = new StringBuilder(); MD5 Hash = MD5.Create(); using (FileStream mf = File.OpenRead(AppDomain.CurrentDomain.FriendlyName)) { foreach (byte b in Hash.ComputeHash(mf)) { sb.Append(b.ToString("x2").ToUpper()); } } return sb.ToString(); } Code: label1.Text = CurrentMD5();