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.

AdrianM
  • 47
  • 2
  • 4
  • 13
  • What's provoking the question? – Bill_Stewart May 12 '13 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. – AdrianM May 12 '13 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. – Ansgar Wiechers May 12 '13 at 22:27
  • What does "policy being restricted" mean? What is the specific problem you're trying to solve? (Error message, etc.) – Bill_Stewart May 13 '13 at 01:48
  • 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 – AdrianM May 13 '13 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. – AdrianM May 13 '13 at 13:01
  • Do the following: 1. Open C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe as administrator (right-click it, choose Run as administrator). 2. Enter the following command at the PowerShell prompt: 'Set-ExecutionPolicy RemoteSigned' (no quotes). Choose Yes. Then try running your HTA again. – Bill_Stewart May 13 '13 at 14:37
  • My admin credentials do not work on this particular server. I'll contact the server owner regarding this. Thank you! Quite peculiar, why would the policy be restricted on syswow64 only? – AdrianM May 13 '13 at 15:13
  • @AdrianM Just because policies are set independantly for 32-bit PShell and 64-bit PShell. The guess is that it's too restrictive for 32-bit one on your system, I think. PS. Use `@SO-user-name` to notify people from comments ;-) BTW, what Windows versions do you need to target? – Ilya Kurnosov May 13 '13 at 15:29
  • @AdrianM Ilya Kurnosov is correct that the 32-bit and 64-bit PowerShell execution policies are independent. The best answer to your problem is to have a server admin configure the 32-bit PowerShell execution policy (like in my previous reply). This can also be done (and is perhaps best done) using a GPO. – Bill_Stewart May 14 '13 at 18:09

2 Answers2

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
    
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
0

It's possible that this will work.

objShell.Run "%SystemRoot%\system32\cmd.exe /c file.bat"
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • 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. – Ansgar Wiechers May 14 '13 at 11:33
  • 3
    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. – Bill_Stewart May 14 '13 at 18:07