无法使用任何方法使用 python (3.8) 脚本打开 Microsoft Teams
Can't open Microsoft Teams with python (3.8) script using any method
我正在尝试制作一个脚本来自动登录 Microsoft Teams,除了必须打开应用程序的部分之外,我的所有代码都可以正常工作。奇怪的是,这能够打开除 MS Teams 之外的任何其他应用程序(Chrome、Notepad、Firefox、Edge 等)
相关代码如下:
def openfile():
if os.stat("stor.txt").st_size == 0:
name = filedialog.askopenfilename()
newfile = open("stor.txt", "w")
newfile.write(name)
else:
name = (open("stor.txt", "r").read())
os.startfile(name)
sleep(5)
keyboard.write(open("user.txt", "r").read())
keyboard.press("enter")
sleep(3)
keyboard.write(open("pass.txt", "r").read())
keyboard.press("enter")
我用 os.startfile
、os.system(start..)
和网络上的所有其他方法都试过了。没用。
当我尝试 运行 Teams 时,我传递给 os.startfile()
的值是 C:/Users/Raghav/AppData/Local/Microsoft/Teams/Update.exe
。
首先,我不建议您以明文形式存储您的密码。它不是很安全,如果另一个程序在正确的时间获得焦点,您的代码甚至会在其他地方输入您的密码!
团队应该在您第一次登录后记住您的凭据。我建议让它处理这部分。
无论如何,运行宁os.startfile("foo.exe")
就像双击foo.exe
一样。您传递的文件名是 C:/Users/Raghav/AppData/Local/Microsoft/Teams/Update.exe
,Update.exe
看起来不应该向我启动 Teams。
在我自己的“开始”菜单中检查 Teams 快捷方式,我发现事情有点复杂。此快捷方式 运行s Update.exe
并向其传递一些参数 :
C:\...\Update.exe --processStart "Teams.exe"
无法使用 os.startfile()
将参数传递给程序。请尝试 os.system()
:
os.system('C:/Users/Raghav/AppData/Local/Microsoft/Teams/Update.exe --processStart "Teams.exe"')
Python 中有 lots of other ways 到 运行 外部命令,但这可能是最简单的,因为您不需要 Teams 的输出流。如果成功,此命令 应该 return 0
如果失败,则应为其他值。
import os
os.system("C:\Users\Lenovo\AppData\Local\Discord\Update.exe --processStart Discord.exe")
对于有如上地址的应用,还有一些提示:
- 有时Discord.exe地址中的文件名有"Discord.exe"(双-引号)。 删除它。
- 在地址中使用双
\
而不是单个 \
。
一定会成功的 GO AHEAD ✔
我正在尝试制作一个脚本来自动登录 Microsoft Teams,除了必须打开应用程序的部分之外,我的所有代码都可以正常工作。奇怪的是,这能够打开除 MS Teams 之外的任何其他应用程序(Chrome、Notepad、Firefox、Edge 等)
相关代码如下:
def openfile():
if os.stat("stor.txt").st_size == 0:
name = filedialog.askopenfilename()
newfile = open("stor.txt", "w")
newfile.write(name)
else:
name = (open("stor.txt", "r").read())
os.startfile(name)
sleep(5)
keyboard.write(open("user.txt", "r").read())
keyboard.press("enter")
sleep(3)
keyboard.write(open("pass.txt", "r").read())
keyboard.press("enter")
我用 os.startfile
、os.system(start..)
和网络上的所有其他方法都试过了。没用。
当我尝试 运行 Teams 时,我传递给 os.startfile()
的值是 C:/Users/Raghav/AppData/Local/Microsoft/Teams/Update.exe
。
首先,我不建议您以明文形式存储您的密码。它不是很安全,如果另一个程序在正确的时间获得焦点,您的代码甚至会在其他地方输入您的密码!
团队应该在您第一次登录后记住您的凭据。我建议让它处理这部分。
无论如何,运行宁os.startfile("foo.exe")
就像双击foo.exe
一样。您传递的文件名是 C:/Users/Raghav/AppData/Local/Microsoft/Teams/Update.exe
,Update.exe
看起来不应该向我启动 Teams。
在我自己的“开始”菜单中检查 Teams 快捷方式,我发现事情有点复杂。此快捷方式 运行s Update.exe
并向其传递一些参数 :
C:\...\Update.exe --processStart "Teams.exe"
无法使用 os.startfile()
将参数传递给程序。请尝试 os.system()
:
os.system('C:/Users/Raghav/AppData/Local/Microsoft/Teams/Update.exe --processStart "Teams.exe"')
Python 中有 lots of other ways 到 运行 外部命令,但这可能是最简单的,因为您不需要 Teams 的输出流。如果成功,此命令 应该 return 0
如果失败,则应为其他值。
import os
os.system("C:\Users\Lenovo\AppData\Local\Discord\Update.exe --processStart Discord.exe")
对于有如上地址的应用,还有一些提示:
- 有时Discord.exe地址中的文件名有"Discord.exe"(双-引号)。 删除它。
- 在地址中使用双
\
而不是单个\
。
一定会成功的 GO AHEAD ✔