8

I've got a situation where I am using the 64-bit version of Visual Studio Code to write/debug a powershell script. However, because of what the Powershell script is doing it needs to run within the 32-bit version of Powershell. It's using some libs to access an MS Access file, so I have yet to find a way to make things work within Powershell x64.

Is there a way to tell VS Code to run the 32-bit version of Powershell if VS Code itself is running as 64-bit? For example, can I modify the launch.json file to specify the path of powershell itself?

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "PowerShell",
            "request": "launch",
            "name": "PowerShell Launch Current File",
            "script": "${file}",
            "args": [],
            "cwd": "${file}"
        },
        ...
     ]
}
Sam Storie
  • 4,249
  • 4
  • 45
  • 73

2 Answers2

15

I found another method that's easier and seems to be provided by VSCode (although it might be an extension I added). In the main window there's a clickable element in the right side of the toolbar:

enter image description here

When you click that a menu appears near the top of the window with some powershell related options, including the ability to switch between x86 and x64:

enter image description here

Sam Storie
  • 4,249
  • 4
  • 45
  • 73
  • 2
    +1 The only extension I've got is PowerShell and an icon extension, so I'm willing to believe it's part of the PowerShell extension itself. – Bacon Bits Oct 06 '17 at 15:46
  • blarg. this just happened to me. i forgot it had been previously set to x86 for doing office related stuff. – KySoto May 06 '20 at 20:51
4

Assuming you have the PowerShell extension installed, you should be able to modify the powershell.powerShellExePath setting in VS Code Settings to "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe".

I believe you can also set "powershell.useX86Host": true. This was introduced in the PowerShell extension v0.5.0; I'm not sure how I missed it's inclusion!

However, it might be easier or better to install the 64-bit MS Access components and just use the 64-bit version.

Microsoft Access Database Engine 2010 Redistributable

Microsoft Access 2013 Runtime

Microsoft Access Database Engine 2016 Redistributable

I've no idea why the 2013 version has a different name, but as far as I can tell those are the same components for the different versions.

Bacon Bits
  • 28,812
  • 5
  • 55
  • 62
  • If you already have installed a 32-bit version of Office, you can not install the 64-bit MS Access components. That's a problem I ran into when I wanted to install the 64-bit components a while back, and I don't have a 64bit office at my disposal and no need to upgrade as the Office 2010 I'm using is still perfect what I'm doing with it, ok, except for this problem. – SuperDre Oct 28 '21 at 13:03
  • @SuperDre Not sure why that's not working for you, but I 100% have done it before. It was part of an application install we deployed across our network at a prior job, and it was always installed side-by-side with 32-bit Office (because that was installed on every workstation). – Bacon Bits Oct 29 '21 at 00:16
  • are you sure you were installing the x64 version next to the 32bit. as the message I get during installation is as clear as possible: "You cannot install the 64-bit version of MS ADE2010 because you currently have 32-bit office products installes. If you want to install 64-bit MS ADE 2010, you first need to remove the 32-bit installation of Office products." and then it tells me the 32-bit version I need to remove: "Microsoft Office Standard 2010". – SuperDre Nov 01 '21 at 12:37
  • I'm quite sure. It's been a long time, but I'm sure we either did [this](https://stackoverflow.com/q/42090394/696808) or [this](https://stackoverflow.com/q/37710776/696808) or [this](https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/How-to-install-64-bit-Microsoft-Database-Drivers-alongside-32-bit-Microsoft-Office.html) or [this](https://ginesys.atlassian.net/wiki/spaces/PUB/pages/66617405) or similar. – Bacon Bits Nov 02 '21 at 02:21
  • thanks for the extra info, [this](https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/How-to-install-64-bit-Microsoft-Database-Drivers-alongside-32-bit-Microsoft-Office.html) did the trick. But I see the 64bit ACE.OLEDB.12.0 driver is much slower as its 32-bit counterpart, so I'll now use the 32-bit ACE.OLEDB.12.0 driver and 32bit powershell instead of the Jet.OLEDB.4.0 driver. But at least now I can use both 32-bit as 64-bit. – SuperDre Nov 03 '21 at 12:03