gpt4 book ai didi

powershell - 在PowerShell脚本中运行quser.exe可以在IDE中运行,但不能作为服务运行

转载 作者:行者123 更新时间:2023-12-03 00:59:05 25 4
gpt4 key购买 nike

如果我在控制台窗口或ISE中运行以下代码段,则该代码段将按预期运行,并列出本地计算机上的 Activity 用户 session :
(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支持人员,并被告知A服务运行时没有配置文件,并且没有执行访问系统文件夹的权限。您需要授予服务帐户对exe及其支持DLL的执行访问权限,以及使用EXE的完整路径。

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

Running quser as NTAUTHORITY\LocalSystem

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

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

最佳答案

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

在这种情况下,您可以通过运行C:\Windows\Sysnative\quser.exe在64位操作系统上解决此问题(有关详细信息,请参阅文档中的File System Redirector)。

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

关于powershell - 在PowerShell脚本中运行quser.exe可以在IDE中运行,但不能作为服务运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58644632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com