5

I downloaded a file and wanted to verify it's MD5 Checksum. 7Zip's file context menu output doesn't include an MD5 checksum, so I downloaded fciv.exe from the Windows site, and copied it into my System32 folder.

Then I went down the rabbit hole of trying to add a custom context menu item. I got as far as to see that I could modify the registry at Computer\HKEY_CLASSES_ROOT*\shell and add a MD5 key with a command key underneath it to execute cmd /k fciv.exe "%1" as a solution.

However, I wanted to go further and use a VB Script to send the output to a simple message box instead of having the console open up. I found code here as follows:

Option Explicit

Const WshRunning = 0
Const WshFinished = 1
Const WshFailed = 2

Dim shell : Set shell = CreateObject("WScript.Shell")
Dim exec : Set exec = shell.Exec("fciv.exe filename-from-right-click")

While exec.Status = WshRunning
    WScript.Sleep 50
Wend

Dim output

If exec.Status = WshFailed Then
    output = exec.StdErr.ReadAll
Else
    output = exec.StdOut.ReadAll
End If

WScript.Echo output

This was where I got stuck:

  1. I have no idea how to adapt the script to use the file path available from the right click menu and second when I even try to run the script.

  2. When I even try to run the script using the context menu, Windows blocks it with a "This app can't run on your PC" pop-up.

Any suggestions? Bonus points if it's to a dialog box where the text can be copied. Thanks in advance!

Rdt
  • 53
  • 3
  • Interesting question. – user692942 Oct 11 '20 at 18:26
  • 1
    I suppose what you could do is put the script in the SendTo folder. That way, if you rightclick a file and select the script in SendTo, it would capture the path (in `Wscript.Arguments(0)`) and you can work with it. – Rno Oct 12 '20 at 14:37

1 Answers1

1

Assuming, for example, that you have created c:\temp\md5.vbs (and that your script works!), why don't you set the command value to (by importing this registry):

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\MD5]
@="Get MD5 Checksum"

[HKEY_CLASSES_ROOT\*\shell\MD5\command]
@="wscript.exe \"c:\\temp\\md5.vbs\" \"%1\""

and your script to:

Option Explicit

Const WshRunning = 0
Const WshFinished = 1
Const WshFailed = 2

Dim shell : Set shell = CreateObject("WScript.Shell")
Dim exec : Set exec = shell.Exec("fciv.exe " & chr(34) & Wscript.Arguments(0) & chr(34))

While exec.Status = WshRunning
    WScript.Sleep 50
Wend

Dim output

If exec.Status = WshFailed Then
    output = exec.StdErr.ReadAll
Else
    output = exec.StdOut.ReadAll
    InputBox "Copy and paste your MD5 checksum","MD5 Checksum",output 
End If

Set exec = Nothing
Set shell = Nothing

This is untested, and you may want to 'variablise' (environment variable?) the location of c:\temp\ in the real world as opposed to a hard coded path...

Captain_Planet
  • 1,228
  • 1
  • 12
  • 28
  • How does this capture the path from rightclick as per OP's question? – Rno Oct 14 '20 at 21:48
  • The "%1" is the path to the file that has been right-clicked. And this is passed as an argument to the vbscript.... – Captain_Planet Oct 14 '20 at 21:52
  • You mean assuming that the command is included in the context menu...which the OP said he did. Okay, never mind :) – Rno Oct 14 '20 at 21:59
  • It's a different command line!!! And the command is included in the registry, as the OP has already referred to! – Captain_Planet Oct 14 '20 at 22:11
  • 1
    Thanks - this worked perfectly. As it turns out, you can just ctrl-c from MsgBox output! So in favor of nicer output formatting I just replaced the InputBox with `MsgBox output, 64, "Calculated MD5 Checksum" ` – Rdt Nov 14 '20 at 03:43