PowerShell脚本中的运行quser.exe在IDE中有效,但在作为服务运行时不起作用

问题描述 投票:0回答:1

如果我在控制台窗口或ISE中运行以下代码段,则该代码段将按预期工作,并列出本地计算机上的活动用户会话:

(Invoke-Expression "$env:windir\system32\quser.exe") -replace '\s{2,}', ',' | ConvertFrom-Csv

遗憾的是,这不是控制台应用程序,而是作为服务安装的PowerShell脚本。该服务作为LocalSystem(而不是LocalService)运行。当服务尝试运行此代码时,它将输出以下错误:

The term 'C:\Windows\system32\quser.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

我联系了Sapien支持人员,并被告知某项服务没有配置文件运行,并且没有对系统文件夹的执行访问权限。您需要授予服务帐户对exe及其支持DLL的执行访问权限,以及使用EXE的完整路径。

我已经证明(我认为)安全主体可以访问quser。我使用PSExen打开了以LocalSystem运行的PowerShell控制台,并成功运行了quser应用程序:

Running quser as NTAUTHORITY\LocalSystem

问题必须是我正在作为服务运行。有谁知道我如何在服务中访问/使用QUser?

我想真正的问题是,以LocalSystem运行的服务如何执行系统文件夹中的应用程序?

powershell cmd windows-services windows-console
1个回答
0
投票

我的猜测是,用于将PowerShell脚本作为服务运行的任何工具都是32位的,并且quser.exe中没有C:\Windows\SysWOW64

您可能可以通过运行C:\Windows\sysnative\quser.exe解决此问题。

如果是这种情况,我想说的是您得到的信息(“服务运行时没有配置文件,并且没有对系统文件夹的执行访问权限”)。

© www.soinside.com 2019 - 2024. All rights reserved.