如何检查是否安装了 Ghostscript 版本以及安装位置? [英] How can I check IF a version of Ghostscript is installed and IF SO where it is installed?
问题描述
正如标题所说.我需要在 VBS 中检查 (1) Ghostscript 是否安装在本地计算机上,如果是 (2) 安装位置.
As the title says. I need to check in VBS whether (1) Ghostscript is installed on the local computer and if so (2) where it is installed.
我认为问题 (1) 我已经解决了:
I think question (1) I have solved:
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Set oReg = GetObject("winmgmts:!root/default:StdRegProv")
If oReg.EnumKey(HKLM, "SOFTWARE\GPL Ghostscript\", arrSubKeys) = 0 Then
KeyExists = True
Else
KeyExists = False 'The script stops since it requires GS to be installed
End If
...
objShell.Run(pathToGhostScript & "-arguments")
但是,就我而言,注册表中的 GS 看起来像
However, in my case GS in the registry looks like
HKEY_LOCAL_MACHINE\SOFTWARE\GPL Ghostscript\9.01\
注意:我正在检查注册表项 SOFTWARE\GPL Ghostscript\
而不是 SOFTWARE\GPL Ghostscript\9.01\
因为我的检查将返回 FALSE
如果有人会安装 ...\9.2\
或其他东西.我假设无论安装哪个版本,注册表项 SOFTWARE\GPL Ghostscript\
都将始终存在.这个假设正确吗?
Note: I'm checking for a registry entry SOFTWARE\GPL Ghostscript\
and not SOFTWARE\GPL Ghostscript\9.01\
because my check would return FALSE
if someone would have installed ...\9.2\
or something. I'm assuming that whichever version might be installed, the registry key SOFTWARE\GPL Ghostscript\
would always exist. Is this assumption correct?
最终,我需要调用(就我而言)C:\Program Files\gs\gs9.01\bin\gswin32.exe
.如果我查看注册表,..\bin\
的路径只能从注册表值 SOFTWARE\GPL Ghostscript\9.01\GS_DLL
派生,它返回 C:\Program Files\gs\gs9.01\bin\gsdll32.dll
.我假设我可以使用这个值,删除 ..\bin\
之后的所有内容并将 gswin32.exe
连接到路径.然后我会在上面的脚本中填充 pathToGhostScript
变量.
Eventually, I need to call (in my case) C:\Program Files\gs\gs9.01\bin\gswin32.exe
. If I look at the registry, the path to ..\bin\
can only bderived from the registry value SOFTWARE\GPL Ghostscript\9.01\GS_DLL
, which returns C:\Program Files\gs\gs9.01\bin\gsdll32.dll
. I assume I could take this value, remove everything after ..\bin\
and concatenat gswin32.exe
to the path. I would then have filled the pathToGhostScript
variable in my script above.
问题:如何从脚本中返回 GS_DLL
的值?因为我知道在我的情况下可以在 ..\9.01\GS_DLL
下找到该值,但在其他人的电脑上它也可能是例如...\9.57\GS_DLL
...
Question: how do I return the value for GS_DLL
from my script? Because I know the value can be found under ..\9.01\GS_DLL
in my case, but on someone else's pc it might also be eg. ..\9.57\GS_DLL
...
我的问题:
- 这是最好的方法吗?
- 如果没有,有什么更可靠的方法可以查看 gswin32.exe 是否可用?
- 如果是,你能帮我填写上面讨论的空白吗?
推荐答案
我认为可以安全地假设 Ghostscript 可执行文件将与 DLL 位于同一目录中,因此应该可以使用以下内容:
I think it's safe to assume that the Ghostscript executable will be located in the same directory as the DLL, so something like this should work:
Const HKLM = &h80000002
Const baseKey = "SOFTWARE\GPL Ghostscript"
Const value = "GS_DLL"
Set reg = GetObject("winmgmts://./root/default:StdRegProv")
If reg.EnumKey(HKLM, baseKey, subkeys) <> 0 Then
WScript.Echo "Cannot enumerate subkeys of " & baseKey & "."
WScript.Quit 1
End If
For Each sk In subkeys
If reg.GetStringValue(HKLM, baseKey & "\" & sk, value, gsLib) <> 0 Then
WScript.Echo "Cannot read value " & value & "."
WScript.Quit 1
End If
Next
Set fso = CreateObject("Scripting.FileSystemObject")
gsDir = fso.GetParentFolderName(gsLib)
gs = fso.BuildPath(gsDir, "gswin32.exe")
WScript.Echo gs
这篇关于如何检查是否安装了 Ghostscript 版本以及安装位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!