Search code examples
pythonpython-3.xpowershelldirectoryassistant

How to open Powershell with python to it's default location?


I am trying to make a digital assistant that can open all apps. When I open the PowerShell the directory is set to where the python script is located. I all ready know how to open the command line to the right folder I just need the PowerShell.

What I'm using

  • Windows 10
  • Python 3.7.9
  • Os module
  • Thonny ide 3.3.6

What im trying to do is open PowerShell to

C:\Users\MyUsername>

What I've tried I use the command 'get-StartApps' in the Powershell to get all the app ids

This is what I've tried to use to open the PowerShell

import os
os.system('start Powershell ')

os.startfile(r'C//Users//'+str(os.path.expandvars("%userprofile%"))+'//AppData//Roaming//Microsoft//Windows//Start Menu//Programs//Windows PowerShell//Windows PowerShell.lnk')

I am unsure if app ids are the same on all computer so I will just give a example

import os
os.system('start explorer shell:appsfolder\{Id number}\WindowsPowerShell\v1.0\powershell.exe')

Just opens the file explorer but work to open other apps.

Also I would like this to work on all machines to so if you know how please tell me.


Solution

  • os.system('start /D'+ str(os.path.expandvars("%userprofile%"))+' powershell')