我有三个文件:
测试.vbs
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
st = ""
windir = objShell.ExpandEnvironmentStrings("%windir%")
stCommand = windir & "\System32\sysprep\sysprep.exe"
CheckFile
progx86 = objShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%")
stCommand = progx86 & "\Internet Explorer\iexplore.exe"
CheckFile
MsgBox st
Sub CheckFile
st = st & "File for test: " & stCommand & vbcrlf
If objFileSystem.FileExists(stCommand) Then
st = st & "********** File exists!!!!!"
Else
st = st & "********** I cannot find the file :-("
End If
st = st & vbcrlf & vbcrlf & vbcrlf
'objShell.Run chr(34) & stCommand & chr(34),,True
End Sub
MyTEST1.hta
<html>
<head>
<title>Test HTA</title>
<HTA:APPLICATION
APPLICATIONNAME="My TEST"
SCROLL="no"
VERSION="1.0"/>
</head>
<script type="text/vbscript">
Sub Window_OnLoad
Set oShell = Createobject("WScript.Shell")
oShell.Run "test.vbs",,True
Self.Close
End Sub
</script>
<body>
<b>My TEST</b>
</body>
</html>
MyTEST2.vbs
Set oShell = Createobject("WScript.Shell")
oShell.Run "test.vbs",,True
我在新安装的 Windows 7 上启动文件。执行MyTEST2.vbs会产生可预测的结果: MyTEST2.vbs: FileExists 适用于 IExplore.exe 和 Sysprep.exe 应用程序
但是执行MyTEST1.hta会产生不同的结果: MyTEST1.hta: FileExists failed on Sysprep.exe
谁能解释造成这种差异的原因是什么?我的目标是从 VBScript 调用Sysprep.exe,而后者又从 HTA 调用。我坚持下去,我会很感激你的帮助。
提前谢谢了!