[英]Get logged on username in Excel VBA - not the account running Excel (using RunAs)
[英]How to get username of logged-in user when application started with RUNAS
我用一個簡短的 RUNAS 腳本來啟動 Excel/MS Access:
runas .netonly /user:%id% "C:\Windows\System32\cmd.exe /c START excel.exe /r"
現在我的問題是:如何在 VBA (xls?accdb) 中獲取此應用程序 (,) 的登錄用戶名? 有辦法嗎?
您可以使用:
RunAs /netonly /user:%id% "C:\Windows\System32\cmd.exe /c START MSACCESS.exe """d:\Path\Your Database Name.accdb""" /cmd %id%"
然后,在 VBA 中,使用Command
讀取值:
id = VBA.Command
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.