windows - 如何找出谁在运行 runas 应用程序?

标签 windows powershell batch-file command-line runas

背景:

在我的组织中,有一个应用程序用于某些关键功能,但它只有在以特定用户身份运行时才能发挥最佳作用。

原因是应用程序将其大量配置存储为本地用户 session ,因此它成为多用户噩梦,这意味着我们不得不重复大量工作。

我们已经分配了一个用户来运行该应用程序,并通过设置 runas 桌面快捷方式找到了解决方案。问题是我们发现应用程序无法同时运行超过一次。它只允许每个并发用户运行 1 个实例。

我用于应用程序的快捷方式代码:

C:\Windows\System32\runas.exe /user:mydomain\runas_user /savecreds "C:\Program Files\MyApp\MyApp.exe"

因此,我一直在尝试确定如何查看当前正在使用“runas”应用程序的用户,以便让他们优雅地关闭它。 任务管理器仅在用户名中显示“runas_user”,但我认为必须有某种方法来确定谁运行它或哪个用户 session 正在查看它。

问题:

有什么方法可以找出(最好使用 powershell 或其他脚本)当前正在运行该应用程序的用户?

最佳答案

Windows 安全事件日志应该显示这一点。所有 Windows 2008+ 身份验证事件都是事件 ID 4624(通过)或 4625(失败)。将其与登录类型相结合应该可以满足您的需求。

关于登录类型的大量详细信息来自 this PDF在 sans.org 上(大约从第 10 页开始)。我认为您最感兴趣的部分是“3.7 NewCredentials”:

Using RunAs command to start a program under a different user account with the /netonly switch, Windows records a logon/logoff event with logon type 9. When starting a program with RunAs using /netonly, the program executes on the local computer as the user currently logged on as but for any connections to other computers on the network, Windows connects to those computers using the account specified on the RunAs command. Without /netonly Windows runs the program on the local computer and on the network as the specified user and records the logon event with logon type 2

使用 PowerShell 获取事件 ID 和登录类型的快速而肮脏的方法:

$recentSecLog = 
Get-EventLog -LogName Security -Newest 1000 | Where {$_.EventID -match "4624|4625"}

$recentSecLog | Where {$_.message -match "Logon\sType:\s+9"}

关于windows - 如何找出谁在运行 runas 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37464349/

相关文章:

python - 带有 pyautogui 的 .pyx 脚本可以在spyder/cmd中运行,但不能在bat文件中运行

Windows Batch - 检查一个命令变量是否出现在另一个命令变量中

windows - 强制用户使用 Windows 服务登录

c++ - 从句柄获取文件路径

powershell - 计数不适用于 -include jpg

powershell - 复制项目缓慢 - 过滤和复制 5500 个文件需要 40 分钟?

batch-file - 更改 WMIC 结果的格式

.net - 同一台电脑上所有用户可写的文件夹

java - 如何在 Windows 上制作相同高度的 SWT 按钮、文本和标签?

powershell - 如何创建PSObject对象的新克隆实例