0

I'm using the following VBSript and it works fine, however when I a attempt to add it to a .hta app I've created, it does not function correctly.

Firstly, the 'strValue' does not show in the MsgBox and secondly script errors appear such as "Type mismatch: 'fso.FolderExists'"

Any help would be greatly appreciated as I've been struggling to figure this out.

sub LyncFix

dim oReg, strKeyPath, strValueName, strValue, oWS, userProfile

Const HKEY_LOCAL_MACHINE = &H80000002

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\C7376A18AE70EB645A6EA7E5F5CE44F9"
strValueName = "71B0EB18B3654D541B8975126E6C56DC"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
MsgBox "Folder required to resolve Lync Install prompt: " & strValue


Dim fso
Dim Folder

Set fso = CreateObject("Scripting.FileSystemObject")

If (fso.FolderExists(strValue)) Then
    MsgBox("The folder '" + strValue + "' already exists")
end If

If NOT (fso.FolderExists(strValue)) Then
    ' Delete this if you don't want the MsgBox to show
    MsgBox("Local folder doesn't exist, creating...")
    ' Create folder
    MsgBox("'" + strValue + "'" + " created")
    fso.CreateFolder(strValue)
    MsgBox("Please now try launching Lync again")
End If

end sub
jERCle
  • 111
  • 6
  • 1. I don't see `strComputer` value; 2. add `& vbNewLine & VarType(strValue) & vbTab & TypeName(strValue)` to first `MsgBox`. Then you could see values indicating _Variant_ subtype information about the `strValue` variable (in numeric and string form as well) – JosefZ Mar 13 '15 at 09:56
  • Apologies, I should have stated I have defined strComputer earlier in the hta in the same vbscript. Would it be beneficial for me to comment with the entire hta? – jERCle Mar 14 '15 at 10:24

1 Answers1

0

Two side-notes only:

  • querying HTML with GetStringValue method gives different results for different Windows Script Host executable versions (32 bit vs. 64 bit as manifested in next example);
  • CreateFolder method might require elevated privileges.

Example: with strComputer = "." and next amendment

  '
  oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  ' the amendment in 29026643.vbs as follows:
  Wscript.Echo VarType(strValue) & vbTab & TypeName(strValue)
  '

I have got next output on Windows 8, 64 bit:

==>%windir%\sysWOW64\cscript.exe D:\VB_scripts\SO\29026643.vbs
1       Null

==>%windir%\system32\cscript.exe D:\VB_scripts\SO\29026643.vbs
8       String

==>

Analogous output (with windowed echo) with different versions of wscript.exe.

Analogous output with sub LyncFix defined and used in a basic hta (with msgbox instead of Wscript.Echo) and with different versions of mshta.exe as follows:

==>%winDir%\sysWOW64\mshta.exe D:\VB_scripts\SO\29026643.hta

==>%winDir%\system32\mshta.exe D:\VB_scripts\SO\29026643.hta
JosefZ
  • 28,460
  • 5
  • 44
  • 83
  • Thank you! This kinda just flicked a switch in my head when I read this. I've been wrapping the hta in an exe file so I can run as admin. Wrapping it in a 64-bit exe resolved the issue. Thanks again! – jERCle Mar 15 '15 at 23:28