(view source code of devcon_help.vbs as plain text)
Option Explicit
Dim arrCommands, arrLines, arrPATH
Dim blnFirstLink
Dim i, intPos
Dim objExec, objFSO, objHTMLFile, objRE, wshShell
Dim strCommand, strDEVCON, strHTMLCode, strHTMLFile, strLine, strMsg, strOutput, strPATH, strScriptFile, strScriptVer, strVersion
strScriptVer = "1.00"
strMsg = ""
If WScript.Arguments.Named.Count > 0 Then Syntax
If WScript.Arguments.Unnamed.Count > 1 Then Syntax
Set wshShell = CreateObject( "WScript.Shell" )
Set objExec = wshShell.Exec( "DEVCON.EXE Help" )
If objExec.ExitCode <> 0 Then
strMsg = "ERROR: DEVCON not found, not in the current directory, nor in the PATH\n\n"
Syntax
End If
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
With objFSO
If WScript.Arguments.Unnamed.Count = 1 Then
If .FolderExists( .GetParentFolderName( WScript.Arguments.Unnamed(0) ) ) Then
strHTMLFile = .GetAbsolutePathName( WScript.Arguments.Unnamed(0) )
Else
strMsg = "ERROR: invalid path for HTML output file\n\n"
Syntax
End If
Else
strScriptFile = WScript.ScriptFullName
strHTMLFile = .BuildPath( .GetParentFolderName( strScriptFile ), .GetBaseName( strScriptFile ) & ".html" )
End If
End With
strDEVCON = ""
strVersion = ""
strPATH = wshShell.ExpandEnvironmentStrings( wshShell.CurrentDirectory & ";%PATH%" )
arrPATH = Split( strPATH, ";" )
For i = 0 To UBound( arrPATH )
If Trim( arrPATH(i) ) <> "" Then
If strDEVCON = "" Then
With objFSO
If .FileExists( .BuildPath( arrPATH(i), "DEVCON.EXE" ) ) Then
strDEVCON = .BuildPath( arrPATH(i), "DEVCON.EXE" )
strVersion = .GetFileVersion( strDEVCON )
End If
End With
End If
End If
Next
Set arrCommands = CreateObject( "System.Collections.ArrayList" )
strHTMLCode = "<!DOCTYPE HTML>\n<html>\n<head>\n<title>Help for DEVCON " & strVersion & "</title>\n</head>\n"
strHTMLCode = strHTMLCode & "<body>\n\n<div style=""max-width: 800px; text-align: center; margin-left: auto; margin-right: auto;"">\n\n<div style=""max-width: 800px; text-align: left;"">\n\n<h1>help for <a href=""http://www.robvanderwoude.com/devcon.php"">DEVCON</a> " & strVersion & "</h1>\n\n<pre>"
strOutput = objExec.StdOut.ReadAll
arrLines = Split( strOutput, vbCrLf )
blnFirstLink = False
For i = 0 To UBound( arrLines )
strLine = Escape( arrLines(i) )
If InStr( arrLines(i), Space( 9 ) ) > 2 And Left( arrLines(i), 4 ) <> "help" And Left( arrLines(i), 1 ) <> "-" Then
intPos = InStr( strLine, " " )
strCommand = Left( strLine, intPos - 1 )
arrCommands.Add strCommand
strLine = "<a href=""#helptext_" & strCommand & """>" & strCommand & "</a>" & Escape( Mid( strLine, intPos ) )
If Not blnFirstLink Then
strLine = "\n" & strLine
blnFirstLink = True
End If
End If
strHTMLCode = strHTMLCode & "\n" & strLine
Next
arrCommands.Sort
strHTMLCode = SuperTrim( strHTMLCode ) & "</pre>\n\n"
strHTMLCode = strHTMLCode & "<p>Type <code>DEVCON help <em>command</em></code> on the command line for detailed help on <em>command</em>.</p>\n\n"
For Each strCommand In arrCommands
Set objExec = wshShell.Exec( "DEVCON.EXE Help " & strCommand )
If objExec.ExitCode = 0 Then
strHTMLCode = strHTMLCode & "<h2 id=""helptext_" & strCommand & """>DEVCON " & strCommand & "</h2>\n\n<pre>"
strHTMLCode = strHTMLCode & SuperTrim( Escape( objExec.StdOut.ReadAll ) )
strHTMLCode = strHTMLCode & "</pre>\n\n<p style=""text-align: center;""><a href=""" & objFSO.GetFileName( strHTMLFile ) & """>Back to the top of the page</a></p>\n\n<p> </p>\n\n"
End If
Next
strHTMLCode = Replace( strHTMLCode & "</div>\n\n<p> </p>\n\n<p style=""text-align: center;"">HTML page generated by devcon_help.vbs, Version " & strScriptVer & "<br />\nWritten by Rob van der Woude<br />\n<a href=""http://www.robvanderwoude.com"">http://www.robvanderwoude.com</a></p>\n\n</div>\n\n</body>\n</html>", "\n", vbCrLf )
Set objHTMLFile = objFSO.CreateTextFile( strHTMLFile, True, True )
objHTMLFile.Write( strHTMLCode )
objHTMLFile.Close
wshShell.Run strHTMLFile, 1, False
Abort 0
Sub Abort( intRC )
On Error Resume Next
Set wshShell = Nothing
Set objExec = Nothing
Set objFSO = Nothing
Set objRE = Nothing
Set objHTMLFile = Nothing
On Error Goto 0
WScript.Quit intRC
End Sub
Function Escape( strInput )
Dim strResult
strResult = Replace( strInput, "&", "&" )
strResult = Replace( strResult, ">", ">" )
strResult = Replace( strResult, "<", "<" )
Escape = strResult
End Function
Function SuperTrim( strInput )
Dim strResult
strResult = strInput
Set objRE = New RegExp
objRE.Pattern = "\s+$"
If objRE.Test( strResult ) Then strResult = objRE.Replace( strResult, "" )
objRE.Pattern = "^[\n\r]+"
If objRE.Test( strResult ) Then strResult = objRE.Replace( strResult, "" )
SuperTrim = strResult
End Function
Sub Syntax( )
strMsg = strMsg _
& "devcon_help.vbs, Version " & strScriptVer _
& "\nCreate an HTML help page for all commands for the current DEVCON version\n\n" _
& "Usage: devcon_help.vbs [ outputfile ]\n\n" _
& "Where: outputfile is the HTML file to be created (default: name\n" _
& " and location of this script, extension "".html"")\n\n" _
& "Note: DEVCON is a free Microsoft utility, part of the Windows Driver Kit:\n" _
& " https://www.microsoft.com/en-us/download/details.aspx?id=11800\n" _
& " See http://www.robvanderwoude.com/devcon.php for help on\n" _
& " getting it installed without the entire Windows Driver Kit.\n\n" _
& "Written by Rob van der Woude\nhttp://www.robvanderwoude.com"
WScript.Echo Replace( strMsg, "\n", vbCrLf )
Abort 1
End Sub
page last modified: 2024-04-16; loaded in 0.0068 seconds