0

In my script I ask the user for a variable called asset $asset=Read-Host "Please enter the asset tag"

I am trying to use my powershell script to send a specific line of text to a window. The window name is always a cmd window with a name like " \\<asset>: cmd "

Im not sure if this was possible but I was going to try and use sendkeys to have a line like "\network\path\name of file.cmd"

Can I do this?

rangerr
  • 261
  • 2
  • 5
  • 13
  • Use AutoIt instead of Powershell for this IMO. The next best option is to launch the app from Powershell. Then you have access to STDIN and STDOUT for the app. The last and worst option is to use the WScript object to SendKeys to the app. – EBGreen Apr 21 '14 at 15:40
  • Here's how to use the SendKeys method of the Windows Script Host Shell object: http://stackoverflow.com/questions/17849522/how-to-perform-keystroke-inside-powershell/17851491#17851491. Is this what you were looking for? – Adi Inbar Apr 21 '14 at 17:13

1 Answers1

0

Maybe like this from Powershell.

$asset=Read-Host "Please enter the asset tag"
$tag = "\\" + $asset + ": cmd"
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
[Microsoft.VisualBasic.Interaction]::AppActivate("$tag")
Start-Sleep -m 300
[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
[System.Windows.Forms.SendKeys]::SendWait("Did it work ?")
Knuckle-Dragger
  • 6,644
  • 4
  • 26
  • 41