Launching Sysprep from HTA with Run method fails

232 views Asked by At

I have three files:

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>

MyTEST2.vbs

Set oShell = Createobject("WScript.Shell")
oShell.Run "test.vbs",,True

I launch the files on the newly installed Windows 7. Execution of MyTEST2.vbs gives predictable result: MyTEST2.vbs: FileExists works good for both applications IExplore.exe and Sysprep.exe

But execution of MyTEST1.hta produces different result: MyTEST1.hta: FileExists fails on Sysprep.exe

Can anyone explain what the reason for this difference? My goal is to call Sysprep.exe from VBScript which in turn would be called from HTA. I'm stuck with it and I'd appreciate any your help.

Many thanks in advance!

0

There are 0 answers