向所有用户发送的远程 Powershell 弹出消息不起作用 [英] Remote Powershell Popup message to all users not working

查看:37
本文介绍了向所有用户发送的远程 Powershell 弹出消息不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建远程 powershell 弹出消息时遇到了一些问题.

I'm having some issues creating a remote powershell popup message.

我有一个工作脚本,用于显示我想发送给远程用户的弹出消息.但是,每当我将它捆绑在 .ps1 脚本中并远程运行它时,它都不会向登录用户发送弹出消息.我知道脚本运行正确,因为我有脚本的其他部分可以正确执行.我能够在本地机器上运行弹出消息,所以这不是脚本错误.

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. 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.

脚本是:

    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()

我将它作为以以下方式调用的 .ps1 的一部分运行:

I'm running this as part of a .ps1 that is called in the following fashion:

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

我正在将脚本作为服务帐户从正在 Windows 7 企业台式机上执行命令的服务器运行.目标机器执行策略设置为不受限制,所以我知道这不是脚本执行策略问题.

I'm running the script as a service account from a server that's executing the commands on a Windows 7 enterprise desktop machine. 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.

推荐答案

您的预感是正确的.PowerShell 脚本在服务帐户的上下文中运行,不会对任何登录用户显示.(例如,如果您的脚本启动了 notepad.exe,它将仅针对服务帐户运行).

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. (for ex. if your script launched notepad.exe, it would run only for the service account).

当你在同一账户下本地运行命令时,你会看到它弹出.

You will see it pop up when you run the command locally under the same account.

@Adrian R 是正确的,您可以使用 msg.exe 发送消息,或者更友好的命令行:

@Adrian R is correct you can use msg.exe to send a message, or the more commandline friendly:

net send /users message

如果您想显示更复杂的内容(即完整的 Windows 表单)而不是经典的消息框,那么您需要在用户上下文中运行某些内容.一种方法是使用 PsExec-i(交互式选项)而不是使用 PowerShell 远程处理.

If you want to show something more complex (i.e. a full-on Windows form) instead of the classic message box, then you need to be running something in the user context. One way to do this is to use PsExec with the -i (interactive option) instead of using PowerShell remoting.

这篇关于向所有用户发送的远程 Powershell 弹出消息不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆