XtremeDocumentStudio
.NET
PDFOne
.NET
XtremeDocumentStudio
(for Java)
PDFOne
(for Java)
Gnostice Document Studio
Delphi
eDocEngine
VCL
PDFtoolkit
VCL
StarDocs
Web APIs

Gnostice Blog

Thursday, February 11, 2016

Automated Microsoft Help 3 (MSHC) installation/uninstallation

Using a VBScript script.

By V. Subhash

Visual Studio used CHM (compiled HTML) format files in Visual Studio 6 & Visual Studio .NET. These files were displayed by Microsoft HTML Help Executable (hh.exe). In Visual Studio 2005 and 2008, MS Help 2 (HXS) format was used. These help files were loaded by Microsoft Document Explorer (dexplorer.exe).

Starting with Visual Studio 2010, a new format MS Help 3 (MSHC) format was used. Visual Studio initially used a web server application to display these help files. You could open the help content URLs in any web browser of your choice.

Starting with Visual Studio 2010 SP1, a dedicated help viewer application (Microsoft Help Viewer) was available. Here again, there were several versions - 1.0 (for Visual Studio 2010 SP1), 2.0 (for Visual Studio 2012), 2.1 (for Visual Studio 2013) and 2.2 (for Visual Studio 2015).

MS Help 3 help content is managed by a separate executable. There are several versions of this application:

The syntax of these executables vary subtly. By adding "/?" switch, you can find out what will work. For some strange reason, the "/?" switch starts a new window. The output of this switch has been captured in the Notes section below.

Because of the uncertainty of the location, version and availability of the executables, help installation/uninstallation can get complicated. I created this VBScript to automate this process. The installer/uninstaller application should execute the following command to run the VBScript script.

cscript /nologo vs-help.vbs install/uninstall 2010/2012/2013/2015 path-of-.msha product-name book-name

An installer/uninstaller application will have to use the following arguments to the vs-help.vbs file:

The VBScript and WScript/CScript documentation might be useful to update/fix this script.


Dim oShell, oExec, oExecErr, oExecOutput, sKey, sHelpKey, sCommand, sHelpFile, oFSO, sHlpMgrExe

On Error Resume Next

Set oShell = Wscript.CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

If IsNull(oShell) Or IsNull(oFSO) Then
Wscript.Echo "Error: Unable to create shell objects."
WScript.Quit 1
End If

If WScript.Arguments.Unnamed.Count < 4 Then
Wscript.Echo "Error: Syntax is ""cscript /nologo vs-help.vbs install/uninstall 2010/2012/2013/2015 path-of-.msha product-name book-name"""
Wscript.Echo "For Visual Studio 2012 and later, book-name is not required."""
WScript.Quit 1
ElseIf ((WScript.Arguments.Unnamed(1) = "2010") And _
(WScript.Arguments.Unnamed.Count <> 5)) Then
Wscript.Echo "Error: Syntax is ""cscript /nologo vs-help.vbs install/uninstall 2010/2012/2013/2015 path-of-.msha product-name book-name"""
Wscript.Echo "For Visual Studio 2010, book-name must be specified."""
WScript.Quit 1
ElseIf ((LCase(WScript.Arguments.Unnamed(0)) <> "install") And _
(LCase(WScript.Arguments.Unnamed(0)) <> "uninstall")) Then
Wscript.Echo "Error: First argument should ""install"" or ""uninstall"""
WScript.Quit 1
ElseIf ((WScript.Arguments.Unnamed(1) <> "2010") And _
(WScript.Arguments.Unnamed(1) <> "2012") And _
(WScript.Arguments.Unnamed(1) <> "2013") And _
(WScript.Arguments.Unnamed(1) <> "2015")) Then
Wscript.Echo "Error: Second argument has to be ""2010"" or ""2012"" or ""2013"" or ""2015"""
WScript.Quit 1
ElseIf (Right(WScript.Arguments.Unnamed(2), Len(".msha")) <> ".msha") Then
Wscript.Echo "Error: Help file name should end with "".msha"""
WScript.Quit 1
ElseIf ((WScript.Arguments.Unnamed(3) <> "XtremeDocumentStudio .NET") And _
(WScript.Arguments.Unnamed(3) <> "PDFOne .NET")) Then
Wscript.Echo "Error: Fourth argument has to be ""XtremeDocumentStudio .NET"" or ""PDFOne .NET"""
WScript.Quit 1
ElseIf Not oFSO.FileExists(WScript.Arguments.Unnamed(2)) Then
Wscript.Echo "Error: This .msha file does not exist " & VbCrLf & """" & WScript.Arguments.Unnamed(0) & """"
WScript.Quit 1
End If

sHelpFile = WScript.Arguments.Unnamed(2)
Select Case WScript.Arguments.Unnamed(1)
Case "2010"
sKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Help\v1.0\AppRoot"
sHlpMgrExe = "HelpLibManager.exe"
Case "2012"
sKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Help\v2.0\AppRoot"
sHlpMgrExe = "HlpCtntMgr.exe"
sCatalog = "VisualStudio11"
Case "2013"
sKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Help\v2.1\AppRoot"
sHlpMgrExe = "HlpCtntMgr.exe"
Case "2015"
sKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Help\v2.2\AppRoot"
sHlpMgrExe = "HlpCtntMgr.exe"
End Select

sHelpKey = oShell.RegRead(sKey)

If IsNull(sHelpKey) Or IsEmpty(sHelpKey) Then
Wscript.Echo "Folder for " & sHlpMgrExe & " was not found in the registry (" & sKey & ")"
Else
'Wscript.Echo sHlpMgrExe & " found at " & sHelpKey
If (Right(sHelpKey, 1) <> "\") Then
sHelpKey = sHelpKey & "\"
End If

sCommand = """" & sHelpKey & sHlpMgrExe & """ /operation install /catalogName VisualStudio11 /locale en-us /sourceUri """ & sHelpFile & """"

If LCase(WScript.Arguments.Unnamed(0)) = "install" Then
Select Case WScript.Arguments.Unnamed(1)
Case "2010"
sCommand = """" & sHelpKey & sHlpMgrExe & """ /product vs /version 100 /locale en-us /install /sourceMedia """ & sHelpFile & """ /productName """ & WScript.Arguments.Unnamed(3) & """ /vendor Gnostice"
Case "2012"
sCommand = """" & sHelpKey & sHlpMgrExe & """ /operation install /catalogName VisualStudio11 /locale en-us /sourceUri """ & sHelpFile & """"
Case "2013"
sCommand = """" & sHelpKey & sHlpMgrExe & """ /operation install /catalogName VisualStudio12 /locale en-us /sourceUri """ & sHelpFile & """"
Case "2015"
sCommand = """" & sHelpKey & sHlpMgrExe & """ /operation install /catalogName VisualStudio14 /locale en-us /sourceUri """ & sHelpFile & """"
End Select
ElseIf LCase(WScript.Arguments.Unnamed(0)) = "uninstall" Then
Select Case WScript.Arguments.Unnamed(1)
Case "2010"
'"C:\Program Files\Microsoft Help Viewer\v1.0\HelpLibManager.exe" /product vs /version 100 /locale en-us /uninstall /silent /vendor "Gnostice" /productName "PDFOne .NET" /mediaBookList "Developer Guide"
sCommand = """" & sHelpKey & sHlpMgrExe & """ /silent /product vs /version 100 /locale en-us /uninstall /vendor Gnostice /productName """ & WScript.Arguments.Unnamed(3) & """ /mediaBookList """ & WScript.Arguments.Unnamed(4) & """"
Case "2012"
sCommand = """" & sHelpKey & sHlpMgrExe & """ /operation uninstall /catalogName VisualStudio11 /locale en-us /sourceUri """ & sHelpFile & """ /vendor Gnostice /productName """ & WScript.Arguments.Unnamed(3) & """"
Case "2013"
sCommand = """" & sHelpKey & sHlpMgrExe & """ /operation uninstall /catalogName VisualStudio12 /locale en-us /sourceUri """ & sHelpFile & """ /vendor Gnostice /productName """ & WScript.Arguments.Unnamed(3) & """"
Case "2015"
sCommand = """" & sHelpKey & sHlpMgrExe & """ /operation uninstall /catalogName VisualStudio14 /locale en-us /sourceUri """ & sHelpFile & """ /vendor Gnostice /productName """ & WScript.Arguments.Unnamed(3) & """"
End Select
End If

Wscript.Echo VbCrLf & "Product: " & WScript.Arguments.Unnamed(3)
If WScript.Arguments.Unnamed(1) = "2010" Then
Wscript.Echo "Book name: " & WScript.Arguments.Unnamed(4)
End If
Wscript.Echo "IDE: Visual Studio " & WScript.Arguments.Unnamed(1)
Wscript.Echo "Operation: " & WScript.Arguments.Unnamed(0)
Wscript.Echo "Help file: " & WScript.Arguments.Unnamed(2)
Wscript.Echo "Help file manager: " & sHelpKey & sHlpMgrExe & VbCrLf

'WScript.Quit 1
Wscript.Echo "Executing command..." & VbCrLf & vbTab & sCommand & VbCrLf & VbCrLf
Set oExec = oShell.Exec(sCommand)

WScript.Echo "Reading error codes..."
WScript.Echo oExec.StdErr.ReadAll
WScript.Echo "Error Code: " & oExec.ExitCode
End If


Notes
Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2018 Gnostice Information Technologies Private Limited. All rights reserved.