我有三个文件:
test.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>
&#13;
MyTEST2.vbs
Set oShell = Createobject("WScript.Shell")
oShell.Run "test.vbs",,True
我在新安装的Windows 7上启动文件。 执行 MyTEST2.vbs 可获得可预测的结果: MyTEST2.vbs: FileExists works good for both applications IExplore.exe and Sysprep.exe
但 MyTEST1.hta 的执行会产生不同的结果: MyTEST1.hta: FileExists fails on Sysprep.exe
任何人都可以解释这种差异的原因是什么?我的目标是从VBScript调用 Sysprep.exe ,然后从HTA调用它。我坚持下去,感谢你的帮助。
非常感谢提前!