啟動網頁的完整方法

啟動網頁的完整方法

在我的電腦 (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)

相關內容