几周前,我刚开始学习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文件没有消息框弹出时,没有任何影响。
发布于 2013-08-23 14:26:27
您忘记设置事件,以便在页面加载时运行Sub检查,如下所示:
<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 Subhttps://stackoverflow.com/questions/18404593
复制相似问题