Scripting VBScript来确定注册表字符串和启动批处理文件?

Scripting VBScript来确定注册表字符串和启动批处理文件?,scripting,vbscript,registry,helpers,Scripting,Vbscript,Registry,Helpers,我对使用VBScript编写脚本相当陌生。我一直在尝试写一些东西来删除一个程序,我们已经安装了三个不同版本的。我发现,唯一可以轻松区分这三个版本的方法是使用带有版本号的字符串值的注册表项 Dim WshShell:Set WshShell = CreateObject("WScript.Shell") WScript.echo RegistryValueExists ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\") Function Regist

我对使用VBScript编写脚本相当陌生。我一直在尝试写一些东西来删除一个程序,我们已经安装了三个不同版本的。我发现,唯一可以轻松区分这三个版本的方法是使用带有版本号的字符串值的注册表项

    Dim WshShell:Set WshShell = CreateObject("WScript.Shell")

WScript.echo RegistryValueExists ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\")


Function RegistryValueExists (RegistryValue)
  'Ensure the last character is NOT a backslash (\) - if it is, we aren't looking for a value
  If (Right(RegistryValue, 1) = "\") Then
    'It's not a registry value we are looking for
    RegistryValueExists = false
  Else
    'If there isnt the value when we read it, it will return an error, so we need to resume
    On Error Resume Next

    'Try reading the value
    WshShell.RegRead RegistryValue

    'Catch the error
    Select Case Err
      Case 0:
        'Error Code 0 = 'success'
        RegistryValueExists = true
      Case Else
        'Any other error code is a failure code
        RegistryValueExists = false
    End Select

    'Turn error reporting back on
    On Error Goto 0
  End If
End Function
我想我应该写一个脚本来检查注册表,看看哪个版本是通过字符串显示的。但是,我找到的每个脚本基本上都是为了确定键是否存在,而不是字符串,并且不允许我调用函数来启动批处理脚本。下面是我发现的一个脚本,可能/可能不是我想做的事情的开始。帮助

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Metalogix\PAM4Exchange Outlook Addin\是键,字符串是AddInVersion,REG_SZ,然后是版本号

    Dim WshShell:Set WshShell = CreateObject("WScript.Shell")

WScript.echo RegistryValueExists ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\")


Function RegistryValueExists (RegistryValue)
  'Ensure the last character is NOT a backslash (\) - if it is, we aren't looking for a value
  If (Right(RegistryValue, 1) = "\") Then
    'It's not a registry value we are looking for
    RegistryValueExists = false
  Else
    'If there isnt the value when we read it, it will return an error, so we need to resume
    On Error Resume Next

    'Try reading the value
    WshShell.RegRead RegistryValue

    'Catch the error
    Select Case Err
      Case 0:
        'Error Code 0 = 'success'
        RegistryValueExists = true
      Case Else
        'Any other error code is a failure code
        RegistryValueExists = false
    End Select

    'Turn error reporting back on
    On Error Goto 0
  End If
End Function

事实上,实现这一点并不需要VBScript。您可以直接从批处理文件中读取该注册表值

for /f "usebackq tokens=2,3*" %%A in (`REG QUERY "HKLM\SOFTWARE\Wow6432Node\Metalogix\PAM4Exchange Outlook Addin" /v "AddInVersion"`) do if %%A==REG_SZ set AddInVersion=%%B
echo %AddInVersion%
您只需要添加一些调用批处理脚本的代码,例如:

if "%AddInVersion%"=="1.0" call uninstall1.bat
if "%AddInVersion%"=="2.0" call uninstall2.bat

谢谢我感谢你的帮助!