简体   繁体   English

使用 RUNAS 启动应用程序时如何获取登录用户的用户名

[英]How to get username of logged-in user when application started with RUNAS

I use to start Excel/MS Access with a short RUNAS script:我用一个简短的 RUNAS 脚本来启动 Excel/MS Access:
runas .netonly /user:%id% "C:\Windows\System32\cmd.exe /c START excel.exe /r"

Now my question: how could I get the logged-in username for this application(,) in VBA (xls? accdb)?现在我的问题是:如何在 VBA (xls?accdb) 中获取此应用程序 (,) 的登录用户名? Is there a way?有办法吗?

You can use:您可以使用:

RunAs /netonly /user:%id% "C:\Windows\System32\cmd.exe /c START MSACCESS.exe """d:\Path\Your Database Name.accdb""" /cmd %id%"

Then, in VBA, read the value with Command :然后,在 VBA 中,使用Command读取值:

id = VBA.Command

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

相关问题 在Excel VBA中登录用户名 - 而不是运行Excel的帐户(使用RunAs) - Get logged on username in Excel VBA - not the account running Excel (using RunAs) 我用 2016 excel 创建了 EXCEL VSTO 模板。 我需要知道如何在 Excel 模板中获取登录用户的用户名和密码 - I have created EXCEL VSTO template with 2016 excel . I need to know how could I get UserName and Password of logged in User in the Excel Template 如何在 Excel 中获取登录用户的 email 地址 - How to get logged user's email address in Excel 如何在VBA中获取用户名? - How to get username in VBA? 启动应用程序时的VBA类型不匹配 - VBA Type Mismatch when application is started 如果管理员用户注销,则服务器上的Excel应用程序无法正常工作 - Excel Application on server not working if admin user is logged out Excel 从“环境(“用户名”)”中获取用户名的位置? 以及如何编辑它? - Where does Excel get Username from in "Environ("Username")"? And how to edit it? 获取当前用户的工作站名称登录到主机 - Get Current user's Workstation name logged into Host computer 获取Excel office-js加载项中的当前登录用户 - Get current logged user in Excel office-js add-in UserForm1 没有被检测为普通用户,但在记录时作为管理员是 - UserForm1 not being detected as a Normal User but yes as a Administrator when Logged as such
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM