Home > Software engineering >  How to get username of logged-in user when application started with RUNAS
How to get username of logged-in user when application started with RUNAS

Time:10-08

I use to start Excel/MS Access with a short RUNAS script:
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)? Is there a way?

CodePudding user response:

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:

id = VBA.Command
  • Related