启动网页的完整方法

启动网页的完整方法

在我的计算机(Windows 10)上,我有一个管理用户和一个标准用户。

我在管理员用户帐户上启动 chrome。然后我锁定我的帐户并登录到我的标准用户帐户。然后我以管理员身份运行 cmd,并提示 UAC。当我启动 chrome(启动 chrome)时,什么也没发生。我在下面附加了 --enable-logging --v=1 的堆栈跟踪。当我以标准用户身份运行 cmd 且没有提升权限时,我仍然能够启动 chrome。

[1044:4904:0723/141901.799:ERROR:disk_cache.cc(184)] Unable to create cache
[1044:4904:0723/141901.799:ERROR:shader_disk_cache.cc(606)] Shader Cache Creation failed: -2
[1044:10988:0723/141901.800:ERROR:process_singleton_win.cc(411)] Lock file can not be created! Error code: 32
[1044:10988:0723/141901.800:ERROR:chrome_browser_main.cc(1292)] Failed to create a ProcessSingleton for your profile directory. This means that running multiple instances would start multiple browser processes rather than opening a new window in the existing process. Aborting now to avoid profile corruption.

从高层次上讲,我需要一种万无一失的方法来启动网页。显然,用户使用多种浏览器,因此仅使用 chrome 的解决方案不可行。我使用 start 从 cmd 启动网页https://www.stackoverflow.com/据我了解,使用的是默认浏览器(在我的可重现示例中是 chrome)

一个实际用例是标准用户安装某些软件。软件安装程序使用 UAC 以管理员权限运行,因此安装程序现在在管理员用户帐户下运行。安装程序会启动一个网页,其中详细介绍了有关该软件的信息。该网页实际上并未启动,因为管理员用户在其 Windows 帐户上打开了 chrome。因此,这是一个边缘情况,甚至不适用于大多数只有一个 Windows 帐户的机器。

答案1

import subprocess
url = "https://stackoverflow.com/"
args = ["start", "/wait", url, "&", "exit", "/b", "%errorlevel"]
completed = subprocess.run(args, stdout=subprocess.PIPE, shell=True)
print("exit status", completed.returncode)

相关内容