简体   繁体   English

如何使用 python 脚本打开 Windows 10 应用程序?

[英]How can I open a Windows 10 app with a python script?

So, as you may know there are certain apps on Windows that can be installed from the app store, and are classified as Windows Trusted Apps.因此,您可能知道 Windows 上的某些应用程序可以从应用商店安装,并且被归类为 Windows 受信任的应用程序。 I am not sure, but I think these do not use the classic.exe format.我不确定,但我认为这些不使用classic.exe 格式。 So I am writing a python script to automate some stuff when I start my pc, and I need to start a certain Windows App, but I don't know how to do this as I don't know what I need to start to do so, and I also do not know where these files are located.所以我正在编写一个 python 脚本来在我启动我的电脑时自动化一些东西,我需要启动某个 Windows 应用程序,但我不知道该怎么做,因为我不知道我需要开始做什么所以,我也不知道这些文件在哪里。 Anyone can help?任何人都可以帮忙吗?

import os
os.system('start D:\\bharat\\sqldeveloper.exe') 

For Windows cmd this [start path/app.exe] will open the app so just use the full path of the exe of required file (make sure to use \\\\ in path while writing python script)对于 Windows cmd,此 [start path/app.exe] 将打开应用程序,因此只需使用所需文件的 exe 的完整路径(确保在编写 python 脚本时在路径中使用\\\\

In case anyone else ever faces the issue:万一其他人遇到这个问题:

you can start most windows apps in cmd with the following syntax:您可以使用以下语法在 cmd 中启动大多数 Windows 应用程序:

start [program]:

ex:前任:

start Netflix:

Keeping this in mind, to port to pythn simply use the following code:记住这一点,移植到 pythn 只需使用以下代码:

import os
os.system('start Netflix:')

replace with your program of choice and voila :)替换为您选择的程序,瞧:)

You can use this new technique, its called winapps its used for searching, modifying, and uninstalling apps.您可以使用这种新技术,它称为 winapps,用于搜索、修改和卸载应用程序。 Its download command on cmd windows is pip install winapps .它在 cmd windows 上的下载命令是pip install winapps

Finally, I found a way to run Windows Universal apps which downloaded via Windows Store or preinstalled.最后,我找到了一种运行通过 Windows 应用商店下载或预安装的 Windows 通用应用程序的方法。 Each Windows 10 Universal app has an AUMID which stands for 'Application User Model ID'.每个 Windows 10 通用应用程序都有一个AUMID ,代表“应用程序用户模型 ID”。

PowerShell Command to get all AUMID:获取所有 AUMID 的PowerShell命令:

get-StartApps

Output:输出:

 PS C:\\> get-StartApps Name AppID ---- ----- Skype Microsoft.SkypeApp_kzf8qxf38zg5c!App Snip & Sketch Microsoft.ScreenSketch_8wekyb3d8bbwe!App Mail microsoft.windowscommunicationsapps_8wekyb3d8bbwe!microsoft.w... Calendar microsoft.windowscommunicationsapps_8wekyb3d8bbwe!microsoft.w... Movies & TV Microsoft.ZuneVideo_8wekyb3d8bbwe!Microsoft.ZuneVideo OneNote for Windows 10 Microsoft.Office.OneNote_8wekyb3d8bbwe!microsoft.onenoteim Photos Microsoft.Windows.Photos_8wekyb3d8bbwe!App Video Editor Microsoft.Windows.Photos_8wekyb3d8bbwe!SecondaryEntry Maps Microsoft.WindowsMaps_8wekyb3d8bbwe!App Alarms & Clock Microsoft.WindowsAlarms_8wekyb3d8bbwe!App Voice Recorder Microsoft.WindowsSoundRecorder_8wekyb3d8bbwe!App Feedback Hub Microsoft.WindowsFeedbackHub_8wekyb3d8bbwe!App Xbox Game Bar Microsoft.XboxGamingOverlay_8wekyb3d8bbwe!App Camera Microsoft.WindowsCamera_8wekyb3d8bbwe!App Microsoft Store Microsoft.WindowsStore_8wekyb3d8bbwe!App Weather Microsoft.BingWeather_8wekyb3d8bbwe!App Cortana Microsoft.549981C3F5F10_8wekyb3d8bbwe!App Instagram Facebook.InstagramBeta_8xx8rvfyw5nnt!Instagram ...

So now, you can start any universal app via its AUMID like this:所以现在,您可以通过其 AUMID 启动任何通用应用程序,如下所示:

explorer shell:appsfolder\[AUMID]

For example, if you want to execute Skype :例如,如果要执行Skype

explorer shell:appsfolder\Microsoft.SkypeApp_kzf8qxf38zg5c!App

Now it's the time to back to Python:现在是时候回到 Python 了:

>>> import os
>>> os.system('start explorer shell:appsfolder\Microsoft.BingWeather_8wekyb3d8bbwe!App')

The Windows Weather App will execute. Windows Weather应用程序将执行。

Happy Coding快乐编码

Welcome to 2022!欢迎来到 2022!

You can simply make use of PYPI module AppOpener .您可以简单地使用 PYPI 模块AppOpener

# pip install AppOpener
from AppOpener import run
run("word") #Opens word
run("excel, notepad") # Opens excel & notepad

Visit AppOpener's documentation here .在此处访问 AppOpener 的文档

Not only windows apps, you can also open any application installed in your system不仅 windows 应用程序,您还可以打开系统中安装的任何应用程序

# pip install AppOpener
from AppOpener import run
run("whatsapp") #Opens whatsapp if installed
run("whatsapp, telegram") # Opens whatsapp & telegram

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM