簡體   English   中英

如何使用 python 打開 Powershell 到它的默認位置?

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

我正在嘗試制作一個可以打開所有應用程序的數字助理。 當我打開 PowerShell 時,目錄設置為 python 腳本所在的位置。 我都准備好知道如何打開命令行到正確的文件夾我只需要 PowerShell。

我正在使用什么

  • Windows 10
  • Python 3.7.9
  • 操作系統模塊
  • 托尼 ide 3.3.6

我想做的是打開 PowerShell 到

C:\Users\MyUsername>

我嘗試過使用 Powershell 中的命令“get-StartApps”來獲取所有應用程序 ID

這是我試圖用來打開 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')

我不確定所有計算機上的應用程序 ID 是否相同,所以我只舉一個例子

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

只需打開文件資源管理器,但可以打開其他應用程序。

此外,我希望這適用於所有機器,所以如果你知道如何請告訴我。

嘗試這個:

os.system('start /D "C:/Users" powershell')

啟動命令的 /D 開關設置 powershell 打開的路徑。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM