我下载了一个文件并想验证它的 MD5 校验和。 7Zip 的文件上下文菜单输出不包含 MD5 校验和,因此我从 Windows 站点下载了 fciv.exe,并将其复制到我的 System32 文件夹中。
然后我陷入了尝试添加自定义上下文菜单项的困境。据我所知,我可以修改 Computer\HKEY_CLASSES_ROOT*\shell 中的注册表,并添加一个 MD5 密钥,其下面有一个命令密钥来执行cmd /k fciv.exe "%1"
作为解决方案。
然而,我想更进一步,使用 VB 脚本将输出发送到一个简单的消息框,而不是打开控制台。我找到了代码here https://stackoverflow.com/questions/6060876/vbscript-getting-results-from-shell如下:
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
这就是我陷入困境的地方:
-
我不知道如何调整脚本以使用右键单击菜单中可用的文件路径
第二个是当我尝试运行脚本时。
-
当我尝试使用上下文菜单运行脚本时,Windows 会弹出“此应用程序无法在您的电脑上运行”的窗口来阻止它。
有什么建议么?如果它是一个可以复制文本的对话框,那就加分了。提前致谢!
例如,假设您已创建 c:\temp\md5.vbs(并且您的脚本有效!),为什么不将命令值设置为(通过导入此注册表):
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\""
和你的脚本:
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
这是未经测试的,您可能想要“可变”(环境变量?)现实世界中 c:\temp\ 的位置,而不是硬编码路径......
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)