AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1620254
Accepted
Ξένη Γήινος
Ξένη Γήινος
Asked: 2021-01-24 19:28:38 +0800 CST2021-01-24 19:28:38 +0800 CST 2021-01-24 19:28:38 +0800 CST

如何启动 PowerShell 运行命令并将变量传递给新进程?

  • 772

我目前正在编写一个脚本,该脚本可以在一次运行中对我的 Windows 10 20H2 操作系统进行所有黑客攻击。

我正在使用 PowerShell 7.0.4 x64,我想在 Admin 中运行脚本pwsh,我发现一些注册表项需要更改 TrustedInstaller 权限,我找到了一个解决方案:使用psexec -S启动一个pwsh进程来运行具有TrustedInstaller权限的命令,不幸的是我不知道如何将变量传递给新进程,并使其自动退出psexec以继续执行脚本。

我将以此为例:

$TiSvc=@(
"PrintWorkflowUserSvc"
"RmSvc"
"SCardSvr"
"SecurityHealthService"
"Sense"
"SgrmBroker"
"wscsvc"
)
$TiSvc | %{Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$_" -Name Start -Type DWord -Value 4}

如果没有TrustedInstaller特权,该命令将失败并出现拒绝访问错误。

现在,要解决这个问题,请使用psexec运行命令(我已将SysInternals文件夹放入path):

$PwSh=(Get-Process -Id $pid).path
PsExec -S $PwSh ???

我想在当前会话中设置[array]变量$TiSvc,我不知道如何传递$TiSvc给新pwsh会话并运行此命令:

$TiSvc | %{Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$_" -Name Start -Type DWord -Value 4}

并且命令执行完毕后,退出新的pwsh会话,退出psexec继续脚本执行;

我怎样才能做到这一点?任何帮助表示赞赏。

windows-10 command-line
  • 1 1 个回答
  • 1329 Views

1 个回答

  • Voted
  1. Best Answer
    Ξένη Γήινος
    2021-01-24T20:30:22+08:002021-01-24T20:30:22+08:00

    将您想要运行的任何命令放在TrustedInstaller与脚本文件相同的路径中的文本文件中,确保PsExec.exe在 中Path,然后使用以下命令:

    $PwSh=(Get-Process -Id $pid).path
    psexec -S $pwsh -file $psscriptroot\tiworker.txt
    

    在另一个PowerShell进程中运行需要 TrustedInstaller 权限的命令,执行完成后进程会自动退出,让主脚本继续执行。


    修复了导致 PowerShell 进程在没有 TrustedInstaller 权限的情况下启动的小错误。


    上述方法不知何故无法正常工作,就像我尝试运行这些命令时一样:

    Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\WinDefend" -Name "Start" -Type DWord -Value 4
    Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\WdBoot" -Name "Start" -Type DWord -Value 4
    Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\WdFilter" -Name "Start" -Type DWord -Value 4
    Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\WdNisDrv" -Name "Start" -Type DWord -Value 4
    Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\WdNisSvc" -Name "Start" -Type DWord -Value 4
    

    我得到了错误:

    Set-ItemProperty: Attempted to perform an unauthorized operation.
    

    如果我使用reg add

    ERROR: Access is denied.
    

    然而,他们之前的命令都返回了:

    The operation completed successfully.
    

    特别是这些命令:

    Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows Defender" -Name "DisableAntiSpyware" -Type DWord -Value 1
    Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows Defender" -Name "DisableRoutinelyTakingAction" -Type DWord -Value 1
    Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows Defender" -Name "ProductStatus" -Type DWord -Value 0
    Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows Defender\Real-Time Protection" -Name "DisableAntiSpywareRealtimeProtection" -Type DWord -Value 1
    Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows Defender\Real-Time Protection" -Name "DisableRealtimeMonitoring" -Type DWord -Value 1
    Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows Defender\Scan" -Name "AutomaticallyCleanAfterScan" -Type DWord -Value 0
    Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows Defender\Scan" -Name "ScheduleDay" -Type DWord -Value 8
    Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows Defender\UX Configuration" -Name "AllowNonAdminFunctionality" -Type DWord -Value 0
    Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows Defender\UX Configuration" -Name "DisablePrivacyMode" -Type DWord -Value 1
    

    当以管理员身份而不是 TrustedInstaller 身份运行时,每个都将返回此错误:

    Set-ItemProperty: Requested registry access is not allowed.
    

    使用 运行时PsExec,不会产生此错误。

    但是这个错误:

    Set-ItemProperty: Attempted to perform an unauthorized operation.
    

    仍然会生成。

    我想这是因为PsExec依赖于远程的东西,我禁用了“远程协助”、“远程桌面”和“远程注册表”;

    我使用NSudoLC.exe并成功禁用了 Windows Defender,没有出现错误:

    NSudoLC.exe -U:T -P:E $pwsh -file $home\desktop\tisvc.txt
    

    使用NSudo上述两种错误时都不会产生。

    • 0

相关问题

  • VMware Workstation USB 仲裁服务无法自动启动

  • 如何在域和 Linux 活动目录中启用指纹传感器

  • 资源管理器侧面板中的桌面外壳快捷方式

  • 为什么我不能将文件从 Android 发送到 Windows 10?

  • 在多个文件上打开方式?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve