0

I need to open regedit on remote computer, I script it in powershell but the Alt keys %(FC) was not sended to 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("~~")

if i try it on notpad, it's works but not on regedit !

Alban
  • 3,105
  • 5
  • 31
  • 46

1 Answers1

1

for send keys with powershell you should use wscript.shell like this:

$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-Process
Soheil
  • 837
  • 8
  • 17
  • this code not wirk on my Win8, regedit open properly but no sendkeys() – Alban Apr 14 '15 at 13:21
  • hello dear @Alban i test scrip in win2k12 r2 and i run powershell as administrator because when you want run regedit you may privilege because check with uac you should run as administrator or off uac – Soheil Apr 14 '15 at 16:48