1

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!

  • Worth noting, all files are in the same folder. OS: Windows 7 64bit, User: Local built-in Administrator, UAC: disabled. File **%windir%\system32\sysprep\sysprep.exe** can be launched from Windows explorer as well as from command prompt – Nikolai Peskov Feb 27 '16 at 11:10
  • I know you say UAC is disabled but that doesn't stop the restrictions on elevation. Have you tried running the hta through a elevated *(Run As Administrator)* command prompt to make sure you have the elevated admin context? – user692942 Feb 29 '16 at 09:25
  • Lankymart, thank you for your comment. I was about desperate that someone would have a look at my cry for help... thank you over again. Yes, I have tried HTA from the elevated command prompt but it doesn't work too. I'm confused that the same script when being called from another script and HTA application, gives different results. I can't explain this behavior any other way than the IE settings. I also note that scripts cause an error "file not found" if they copy files from **%windir%\system32\sysprep\** and is called from HTA – Nikolai Peskov Feb 29 '16 at 12:01
  • There is nothing to be confused about one is being called from the Web Browser another from MSHTA the security models are different. – user692942 Feb 29 '16 at 12:05

0 Answers0