Solved Scripting from vbscript to hta

November 12, 2015 at 19:06:39
Specs: Windows 7
I have 2 scripts, one is vbscript and the other a hta script. I am new to scripting and am stuck. My VB script work but I needed the option to make some choices with checkboxes so am working to move to hta. Everything works except writing to a file. my vb script is:

Dim fso, logFile, scriptDir, objshell, RegLocate, RegLocate1, RegLocate2

'----------Install the patches and write results to log file--------------

scriptDir = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))
Set fso = CreateObject("Scripting.FileSystemObject")
Set logFile = fso.OpenTextFile(scriptDir & strComputerName & "Patch_Install_log.log", 8, True)

logFile.WriteLine "==============================================================================="
logFile.WriteLine Now()
'=======================================================================

' Please place the updates in a folder and modify the below folder path
spPatchFolder_A228 = "\\someshare\somefolders"
spPatchFolder_A240 = "\\someshare\somefolders"
spPatchFolder_A242 = "\\someshare\somefolders"
spPatchFolder_A245 = "\\someshare\somefolders"

'=======================================================================

InstallPatches(spPatchFolder_A228)
InstallPatches(spPatchFolder_A240)
InstallPatches(spPatchFolder_A242)
InstallPatches(spPatchFolder_A245)

logFile.WriteLine "==============================================================================="

Set fso = Nothing
Set logFile = Nothing
WScript.Quit


Function InstallPatches(sFolder)
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
Set folder = objfso.GetFolder(sFolder)
Set files = folder.Files
For each sFile In files
If Ucase(Right(sFile.name,3)) = "CAB" Then
'pkgmgr /ip /m:<path><file name>.cab /quiet
i=objShell.Run ("pkgmgr /ip /m:" & Chr(34) & sfolder & "\" & sFile.name & chr(34) & " /quiet")
If i = 0 Or i = 3010 Then
logFile.WriteLine chr(34) & folder & "\" & sFile.name & chr(34) & " installation completed Successfully"
Else
logFile.WriteLine chr(34) & folder & "\" & sFile.name & chr(34) & " installation failed. Exit Code: " & i
End If
End If
If Ucase(Right(sFile.name,3)) = "EXE" Then
'cmd.exe /c <file name>.exe /quiet /norestart
i=objShell.Run ("Cmd.exe /c" & Chr(34) & sfolder &"\"&sFile.name &chr(34) &" /quiet /norestart", 1, True)
If i = 0 Or i = 3010 Then
logFile.WriteLine chr(34) & folder & "\" & sFile.name & chr(34) & " installation completed Successfully"
Else
logFile.WriteLine chr(34) & folder & "\" & sFile.name & chr(34) & " installation failed. Exit Code: " & i
End If
End If
If Ucase(Right(sFile.name,3)) = "MSP" then
'msiexec /p <file name>.msp /qb!"
i=objShell.Run ("msiexec.exe /p "& chr(34) & sfolder & "\" & sFile.name & chr(34) & " /qb", 1, True)
If i = 0 Or i = 3010 Then
logFile.WriteLine chr(34) & folder & "\" & sFile.name & chr(34) & " installation completed Successfully"
Else
logFile.WriteLine chr(34) & folder & "\" & sFile.name & chr(34) & " installation failed. Exit Code: " & i
End If
End If
If Ucase(Right(sFile.name,3)) = "MSU" then
'wusa.exe <file name>.msu /quiet /norestart
i=objShell.Run ("wusa.exe " &Chr(34)& sfolder &"\"& sFile.name & chr(34) &" /quiet /norestart", 1, True)
If i = 0 Or i = 3010 Then
logFile.WriteLine chr(34) & folder & "\" & sFile.name & chr(34) & " installation completed Successfully"
Else
logFile.WriteLine chr(34) & folder & "\" & sFile.name & chr(34) & " installation failed. Exit Code: " & i
End If
End If
Next
For Each Subfolder in folder.SubFolders
InstallPatches(Subfolder)
Next
Set objfso = Nothing
Set objShell = Nothing
Set folder = Nothing
Set files = Nothing
End Function

I am trying to get the file logging to work with my hta script but the wscript always causes an error. Can you offer and guidance?


See More: Scripting from vbscript to hta

Report •


#1
November 13, 2015 at 08:17:15
Well, you're not going to have access to the implicitly defined WScript, because you're no longer using the WScript/CScript engine. Instead, you're using IE as the script engine. That shouldn't matter to you, though, because the only WScript line I see is "WScript.Quit".

How To Ask Questions The Smart Way


Report •

#2
November 13, 2015 at 16:38:38
I see the wscript in this section too, which is where the errors begin:

scriptDir = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))
Set fso = CreateObject("Scripting.FileSystemObject")
Set logFile = fso.OpenTextFile(scriptDir & strComputerName & "Patch_Install_log.log", 8, True)

I understand wscript does not work and that it now uses IE engine so how does one rewrite the code of the logging for this section to work with the new engine?


Report •

#3
November 14, 2015 at 06:21:56
✔ Best Answer
Options!

1) The same way you'd do it if you were writing JavaScript for a webpage. With window.location. Note you'll have to do a little work to get it in a usable state.

2) Use HTA's CommandLine property. Note that what you get back is less predictable than the other methods, and may not, in fact, have the path you seek.

3) Realize that when you run it through Explorer, the current directory will be set to the script's directory, so replace the string manipulation with ".\". Note that if you start the HTA through any other means, your current directory might be wrong.

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •

Related Solutions


Ask Question