1

几周前,我刚开始自己​​学习 HTA 和 VBScript,因为我开始了这个工作程序。我还是个新手,如果这是一个愚蠢的问题,请原谅我。我已经搜索了两个小时,要么我不称职,要么我不知道如何搜索这个问题。

我需要这个脚本来检查三个文件;如果三个都存在,则脚本将继续执行,如果缺少一个,则会弹出一个对话框,告诉用户缺少哪个。我已经研究过五十种不同的方法来做这件事,但没有一个对我有用。以下方法是唯一不返回任何错误的方法,问题是它根本不做任何事情,它只是一个空白窗口。(我通过只检查一个文件来测试这个)

    <SCRIPT LANGUAGE="VBScript">

    ' Resize and center the window
    ' ==========================================================
        sub DoResize
            window.resizeTo 350,250
                screenWidth = Document.ParentWindow.Screen.AvailWidth
                screenHeight = Document.ParentWindow.Screen.AvailHeight
                    posLeft = (screenWidth - 350) / 2
                    posTop = (screenHeight - 250) / 2    
            window.moveTo posLeft, posTop
        end Sub

        DoResize()

</SCRIPT>

<TITLE>Test</TITLE> 
    <HTA:APPLICATION  
        Id="oInstall"  
        APPLICATIONNAME="Test" 
        SCROLL="no" 
        SINGLEINSTANCE="yes" 
        WINDOWSTATE="normal" 
        SELECTION="NO" 
        CONTEXTMENU = "NO" 
        BORDER="Dialogue" 
        BORDERStyle = "Normal" 
        INNERBORDER = "YES" 
        NOWRAP 
        SYSMENU = "YES" 
    > 

<HEAD> 
    <STYLE type=text/css>
    textarea {
        overflow: hidden;
        color: #ffffff;
        border: none;
        background-color: transparent;
    }
    </STYLE>
    <body background="c:\mount\windows\system32\aopentools\Images\MSCBG.bmp">
</HEAD>
<textarea name="ProgSect" rows=1 cols=16 readonly></textarea><img src="c:\mount\windows\system32\aopentools\images\mscind.gif">
<SCRIPT LANGUAGE="VBScript"> 

         Option Explicit

Sub Check

    ' Creating objects
    ' ==========================================================

        Dim WshShell
        Dim objFSO, outFile
        Dim filesys

        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set filesys = CreateObject("Scripting.FileSystemObject")
        Set oFSO=CreateObject("Scripting.FileSystemObject")

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

    If oFile=oFSO.FileExists("c:\users\jgainey\desktop\test.txt") Then

        BeginImage

    Else

        MsgBox "An Error Has Occurred" & vbNewLine & "EC03: Test.txt" & vbExclamation & "ERROR"
        Window.Close

    End If

End Sub

Sub BeginImage

    ' Creating objects
    ' ==========================================================

        Dim intWindowStyle
        Dim bWaitOnReturn
        Dim objShell
        Dim WshShell
        Dim objFSO, outFile
        Dim filesys

        Set objShell = CreateObject("Wscript.Shell")
        Set WshShell = CreateObject("WScript.Shell")
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set filesys = CreateObject("Scripting.FileSystemObject")
        set oFSO=CreateObject("Scripting.FileSystemObject")

            set oFile=oFSO.OpenTextFile("c:\users\jgainey\desktop\test.txt",1)
                text=oFile.ReadAll
                document.all.ProgSect.value=text

End Sub

        </SCRIPT> 
    </BODY> 
</HTML>

结果是一个带有我的背景图像、我的 .gif、我的文本区域的窗口,仅此而已,文本区域永远不会填充。当我删除 test.txt 文件时,没有弹出消息框,没有任何影响。

4

1 回答 1

1

您忘记设置事件以便 Sub Check 在页面加载时运行,如下所示:

<body background="c:\mount\windows\system32\aopentools\Images\MSCBG.bmp" onload="Check">

编辑

Sub Check 方法的无错误实现:

Sub Check

    ' Creating objects
    ' ==========================================================

        Dim oFSO
        Set oFSO = CreateObject("Scripting.FileSystemObject")

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

    If oFSO.FileExists("c:\users\jgainey\desktop\test.txt") Then

        BeginImage

    Else

        MsgBox "An Error Has Occurred" & vbNewLine & "EC03: Test.txt" & vbExclamation & "ERROR"
        Window.Close

    End If

End Sub
于 2013-08-23T14:26:27.757 回答