代码之家  ›  专栏  ›  技术社区  ›  jERCle

小型VBScript在HTA中不起作用

  •  0
  • jERCle  · 技术社区  · 10 年前

    我正在使用下面的VBSript,它工作正常,但是当我尝试将它添加到我创建的.hta应用程序时,它无法正常工作。

    首先,MsgBox中未显示“strValue”,其次出现脚本错误,如“类型不匹配:'fso.FolderExists'”

    如果能得到任何帮助,我将不胜感激,因为我一直在努力解决这个问题。

    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
    
    1 回复  |  直到 10 年前
        1
  •  0
  •   JosefZ    10 年前

    仅两个侧边注释:

    • 查询 HTML 具有 GetStringValue 对于不同的 Windows脚本主机 可执行版本(32位对64位,如下一个示例所示);
    • CreateFolder 方法可能需要提升的权限。

    实例 :具有 strComputer = "." 以及下一修正案

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

    我在Windows 8上得到了下一个输出,64位:

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

    模拟输出(带窗口 echo )具有不同版本的 wscript.exe .

    sub LyncFix 在基本 hta (带有 msgbox 而不是 Wscript.Echo )和不同版本的 mshta.exe 如下所示:

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