[SOLVED] : I copied the file and launched the hash in this copy.
I need an application to search for exe current MD5. I can get MD5 of any file. However, no matter what I do, I can not get FileStream to read the open EXE. I tried using FileOptions.Asynchronous, but that did not help.
EDIT: I guess I'm not very clear. I want my application to be able to read itself.
EDIT code:
private void GetMd5()
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
FileInfo fi = new FileInfo(Process.GetCurrentProcess().MainModule.FileName);
FileStream stream = File.Create(Process.GetCurrentProcess().MainModule.FileName, (int)fi.Length, FileOptions.Asynchronous);
md5.ComputeHash(stream);
stream.Close();
string rtrn = "";
for (int i = 0; i < md5.Hash.Length; i++)
{
rtrn += (md5.Hash[i].ToString("x2"));
}
MessageBox.Show(rtrn.ToUpper());
}
source
share