Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, I would like to calculate checksum of textfile. I'm transferring file from server to client. Once file transfer is done, I'm checking the checksum of the textfile in both the ends.. But it is not working.

What I have tried:

HINSTANCE retval = ShellExecute(NULL, L"open", L"cmd.exe", L"/C cksum mytextfile.txt", L"C:\\Users\\kingbird\\Desktop\\ServerAppl\\Transfer\\mytextfile.txt",
SW_SHOWNORMAL);


Please make this right.
Posted
Updated 5-Feb-19 1:29am

Why are you using a command line utility to perform checksums? Instead, use a hash value: SHA (or even MD5 since this isn't a security app): Implementing SHA1 hash using Windows Cryptography API and C++[^]
And it's MS link: Example C Program: Creating an MD5 Hash from File Content - Windows applications | Microsoft Docs[^]

That way, you are in complete control of the checking code, and updates to the system cannot affect how your code works.
 
Share this answer
 
v2
You must find out what the problem is. At first open a cmd and execute the statement locally. Often it is problem of access rights and so the shell doesnt know how the pathes have to get resolved. Proof that the calculation doesnt hint to some other problem.

In my experience the CreateProcessAsUserW and other functions from that API led to better results. A bit cumbersome, but it worked.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900