我需要在远程计算机上打开regedit,我在powershell中编写了脚本,但Alt键%(FC)未发送到regedit
[void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
$Process = start-process regedit -PassThru
Start-Sleep -m 500
[Microsoft.VisualBasic.Interaction]::AppActivate($Process.id)
Start-Sleep -m 500
#[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
[System.Windows.Forms.SendKeys]::SendWait("%(FC)")
[System.Windows.Forms.SendKeys]::SendWait("$serverName")
[System.Windows.Forms.SendKeys]::SendWait("~~")如果我在notpad上试一下,它可以工作,但在regedit上不行!
发布于 2015-04-04 02:28:58
对于使用powershell发送密钥,您应该像这样使用wscript.shell:
$server="dc"
$user="user"
$password="password"
$a = New-Object -ComObject wscript.shell
[void] $a.run("regedit")
Start-Sleep 3
$a.SendKeys("%f")
Start-Sleep 2
$a.SendKeys("c")
Start-Sleep 1
$a.SendKeys("$server")
Start-Sleep 1
$a.SendKeys("{ENTER}")
Start-Sleep 1
$a.SendKeys("$user")
Start-Sleep 1
$a.sendkeys("{TAB}")
Start-Sleep 1
$a.SendKeys("$password")
Start-Sleep 1
$a.SendKeys("{ENTER}")
Start-Sleep 1
Get-Process -Name regedit | Stop-Processhttps://stackoverflow.com/questions/29433767
复制相似问题