0

I have a .hta application and the below code.

By default, the below command opens file.bat in C:\Windows\ syswow64 \cmd.exe

How do I get it to open with C:\Windows\ system32 \cmd.exe?

A workaround would be to open the .hta file with C:\Windows\system32\mshta.exe instead of the syswow64 one, but I would like to see other ideas.

Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "file.bat"

Many thanks in advance.

10
  • What's provoking the question? Commented May 12, 2013 at 16:46
  • 1
    The batch file opens a powershell script. For some reason, the powershell script works fine in system32 cmd but fails to execute on syswow64 cmd due to policy being restricted. Commented May 12, 2013 at 17:25
  • 1
    C:\Windows\system32\cmd.exe is the 64-bit version and C:\Windows\Syswow64\cmd.exe is the 32-bit version, confusing as it may seem. Commented May 12, 2013 at 22:27
  • 1
    I have batch file which runs a powershell script on the exchange server. When opening the batch file manually (double click on the file), it gets launched in system32 cmd\powershell and works properly. When launching it from a .hta file (eg: hyperlink or button), the batch file launces in syswow64 and says that cannot perform that action due to policy restriction. Apparently, on system32 the policy is RemoteSigned and on syswow64 is Restricted... hope this helps... I'm not really familiar with these to be honest Commented May 13, 2013 at 12:35
  • 1
    Hmm. Investigated a bit further and it seems even if I get the batch file to run in system32 CMD the result is the same. One solution that I found is to create a batch file that runs the .hta file in system32 mshta.exe, and then launching the script batch from hta will work fine. Commented May 13, 2013 at 13:01

2 Answers 2

2

Apparently C:\Windows\system32\cmd.exe actually runs C:\Windows\SysWOW64\cmd.exe when launched from a 32-bit environment.

Thus, as Bill Stewart and Ilya Kurnosov suggested, you'll have to adjust the execution policy for your 32-bit PowerShell. There are 3 ways to do this:

  • Set the execution policy globally with a system or domain policy. However, this route doesn't seem viable for you, since you said you don't have admin privileges on the server in question.

  • Set the execution policy per-user by manually starting C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe on the server and running the command Set-ExecutionPolicy RemoteSigned. This must be done for each user and won't work if the excution policy is locked with a group policy (see above).

  • Bypass the execution policy on the command line by adding -ExecutionPolicy Bypass to the PowerShell call in file.bat:

    powershell.exe -ExecutionPolicy Bypass -NoLogo -File file.ps1
    
Sign up to request clarification or add additional context in comments.

2 Comments

Credit for the suggestion should go to @Bill_Stewart, actually. I just made a tiny comment on his suggestion.
I don't know how to choose his answer as he only posted comments
0

It's possible that this will work.

objShell.Run "%SystemRoot%\system32\cmd.exe /c file.bat"

2 Comments

I thought it would, too, but from a 32-bit HTA the command actually launches the 32-bit cmd.exe, despite explicitly calling the 64-bit executable.
You're not explicitly calling the 64-bit cmd.exe from a 32-bit executable if you specify %SystemRoot%\system32\cmd.exe, because %SystemRoot%\system32 gets redirected automatically to %SystemRoot%\SysWOW64 by the WOW64 file system redirector.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.