简体   繁体   English

向所有无法使用的用户发送远程Powershell弹出消息

[英]Remote Powershell Popup message to all users not working

I'm having some issues creating a remote powershell popup message. 我在创建远程Powershell弹出消息时遇到一些问题。

I've got a working script that displays the popup message that I want to send to a remote user. 我有一个工作脚本,该脚本显示了要发送给远程用户的弹出消息。 However, whenever I bundle it up in a .ps1 script and run it remotely it does not send a popup message to the logged in user. 但是,每当我将其捆绑到.ps1脚本中并远程运行时,它都不会向已登录的用户发送弹出消息。 I know the script is running correctly, as I have other parts of the script that execute correctly. 我知道脚本可以正确运行,因为脚本的其他部分可以正确执行。 I was able to run the popup message on a local machine, so it is not a script error. 我能够在本地计算机上运行弹出消息,因此这不是脚本错误。

The script is: 脚本是:

    Add-Type -AssemblyName System.Windows.Forms
    $Form = New-Object system.Windows.Forms.Form
    $Form.Text = 'ALERT!'
    $form.ControlBox = $false; 
    $Image = [system.drawing.image]::FromFile('\\filepath') 
    $Form.BackgroundImage = $Image 
    $Form.BackgroundImageLayout = 'Stretch'
    $Form.Width = (680)
    $Form.Height = (550) 
    $OKButton = New-Object System.Windows.Forms.Button 
    $OKButton.Location = New-Object System.Drawing.Size(500,445) 
    $OKButton.Size = New-Object System.Drawing.Size(100,50) 
    $OKButton.Text = 'Accept'
    $OKButton.Font = New-Object System.Drawing.Font('Times New Roman',18) 
    $OKButton.Add_Click({$Form.Close()}) 
    $Form.Controls.Add($OKButton) 
    $Form.Add_Shown({$Form.Activate()}) 
    [void] $Form.ShowDialog()

I'm running this as part of a .ps1 that is called in the following fashion: 我将其作为.ps1的一部分运行,该文件以以下方式调用:

Invoke-WmiMethod -Class Win32_Process -ComputerName $computer -Name Create -ArgumentList "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe \\$computer\C$\folder\script.ps1

I'm running the script as a service account from a server that's executing the commands on a Windows 7 enterprise desktop machine. 我正在从Windows 7企业台式机上执行命令的服务器上将脚本作为服务帐户运行。 The target machine execution policy is set to unrestricted so I know it is not a script execution policy issue. 目标计算机执行策略设置为不受限制,因此我知道这不是脚本执行策略问题。

I have a hunch that the reason that it is not popping up on the target machine is because the account that is running the script and the account that is logged into the target machine are different, however I could be incorrect. 我直觉它没有在目标计算机上弹出的原因是因为运行脚本的帐户和登录到目标计算机的帐户不同,但是我可能不正确。

Your hunch is correct. 你的预感是正确的。 The PowerShell script is running in the context of the service account, and won't show up for any of the logged in users. PowerShell脚本在服务帐户的上下文中运行,并且不会对任何已登录的用户显示。 (for ex. if your script launched notepad.exe, it would run only for the service account). (例如,如果您的脚本启动了notepad.exe,它将仅针对服务帐户运行)。

You will see it pop up when you run the command locally under the same account. 在同一帐户下本地运行命令时,您会看到它弹出。

@Adrian R is correct you can use msg.exe to send a message, or the more commandline friendly: @Adrian R是正确的,您可以使用msg.exe发送消息,或更友好的命令行方式:

net send /users message

If you want to show something more complex (ie a full-on Windows form) instead of the classic message box, then you need to be running something in the user context. 如果要显示更复杂的内容(例如完整的Windows窗体)而不是经典消息框,则需要在用户上下文中运行某些内容。 One way to do this is to use PsExec with the -i (interactive option) instead of using PowerShell remoting. 一种方法是将PsExec-i (交互式选项)一起使用,而不是使用PowerShell远程处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM