Search Results for 'sendkeys'

Welcome Forums Search Search Results for 'sendkeys'

Viewing 15 results - 16 through 30 (of 42 total)
  • Author
    Search Results
  • #96384
    rubi12
    Participant
    Topics: 1
    Replies: 1

    Hi,

    I would like to run the following power shell script on a remote computer

    FunctionSet-Speaker($Volume){$wshShell=new-object-comwscript.shell;1..50|%{$wshShell.SendKeys([char]174)};1..$Volume|%{$wshShell.SendKeys([char]175)}}

    Set-Speaker – Volume 10

    I have tried to use the Invoke command without success, any suggestions on how to make it work on a remote computer?

    Kevin
    Participant
    Topics: 4
    Replies: 0

    I want to have a script log into Jenkins automatically. Using I.E. I have inspected some elements to create a PowerShell script to do almost everything that I want it to do. My script will launch I.E. and fill out the username and password correctly. How do I get the "Login" button to be clicked? I would rather not use SENDKEYS.

    Here is my script:

    $username = "jdoe";
    $password = "strongpassword";
    $loginUrl = "http://jenkinsserver:8080/"

    $ie = New-Object -com internetexplorer.application;
    $ie.visible = $true;
    $ie.navigate($loginUrl);
    while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; } #wait for browser idle

    ($ie.document.getElementsByName("j_username") | select -first 1).value = $username;
    ($ie.document.getElementsByName("j_password") | select -first 1).value = $password;
    ($ie.document.getElementsByName("login") | select -first 1).click();

    #88292
    Participant
    Topics: 2
    Replies: 1000
    Points: 1,980
    Helping Hand
    Rank: Community Hero

    This has been possible ever since the VBScript days.
    It's called SendKeys, though it does get panned by many over the years. I've had no real issues in using it.

    In PowerShell, it is just doing this.. Say, some Windows UI

    ### Start PowerUser Menu
    [void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
    [System.Windows.Forms.SendKeys]::SendWait("^{ESC}+X")

    A quick search using your favorite search engine, using the strings

    'VBScript SendKeys'
    'PowerShell SendKeys'

    ... Will provide you a long list of articles to choose from.

    Also take a look at the WASP module, here:
    'wasp.codeplex.com'

    #76647
    Dimitri
    Participant
    Topics: 1
    Replies: 1

    Hello friends, how are you? πŸ™‚
    Please see if you can help me ... I use Posh-ssh to manage Mikrotik routerboards and it works perfectly. However now I want to
    Also automate configuration of switches (in my scenario, they are all
    HP 2530-24G). I can connect normally via posh-ssh (it appears in the
    Log switch as logged), however, any command I try
    Invoking it does not recognize ... I believe it is by the following: – In that
    Swich template, when I log in for the first time, it is necessary to press the
    Enter to be able to fully start the session .... However I do not know how
    Invoking this command by posh / powershell .... do you have any ideas?
    I found something in this sense but I do not know how to use:

    # $ Test = new-object -c wscript.shell
    # $ Test.sendkeys ("{ENTER}")

    Note: I am invoking the commands as follows:

    Invoke-SSHCommand -Command "system-view" -SessionId 0
    #70805
    Del
    Participant
    Topics: 22
    Replies: 19
    Points: 0
    Rank: Member

    You're correct. I tried to invoke the SendKeys didn't work on all of the AD machines.
    Instead I used "InteropServices"; interface "IAudioEndpointVolume" and It works πŸ™‚

    As for Mic. I found some good C# examples ..

    #70735
    Keymaster
    Topics: 13
    Replies: 4872
    Points: 1,870
    Helping HandTeam Member
    Rank: Community Hero

    So, because I know there's no PowerShell command for this, I searched ".NET record microphone". You might try that – there are some good examples. You're going to need to translate from C# or VB, because you're basically going to be coding .NET.

    FWIW, I also searched ".net set volume" and got some good results, which might give you something more reliable than that SendKeys approach you're using. That's almost 20 years old and isn't going to be reliable across a lot of different systems.

    Del
    Participant
    Topics: 22
    Replies: 19

    I'm working on a script, to go and unmute the speaks on a local or remote computer, send a message using [Speech] Class
    I'll show you the code below. But I was wondering if it's possible to use PowerShell to capture a (Record) Microphone input ??

    # Set Speaker function
    Function Set-Speaker($Volume) {
    $wshShell = new-object -com wscript.shell;1..50 | % {$wshShell.SendKeys([char]174)};1..$Volume | %{$wshShell.SendKeys([char]175)}}
    Set-Speaker -Volume 50
    #
    Invoke-Command -ComputerName $PC -scriptblock {

    Add-Type -AssemblyName System.speech
    $talker = New-Object System.Speech.Synthesis.SpeechSynthesizer
    $talker.speak("Hi there .. Your your password expires today. Please change your password now")
    }

    #67303
    Ian Hicks
    Participant
    Topics: 1
    Replies: 0

    I've been working on this script and it works on my PC but I am positive it can be broken if the timing is changed slightly.

    The first problem is I can't figure out how to sendkeys to the program in order to make it start running and simultaneously keep the program from closing via the /w or | out-null commands. When I try to add the out-null lines the script will still close the app before it is done running.

    The 2nd issue is that I have inserted pauses in order to navigate the apps via sendkey commands but obviously this is gonna cause a problem if the app run speed varies even slightly.

    So yeah..... I am sure there are other problems that will arise but these are the two I can see right now. Any advice would be greatly appreciated. Thank you.

    & start "C:\program.lnk"
    sleep 1
    $wshell = New-Object -ComObject wscript.shell;
    $wshell.AppActivate('C:\program.lnk')
    Sleep 1
    $wshell.SendKeys('{right}')
    Sleep 1
    $wshell.SendKeys('~')
    Sleep 1
    $wshell.SendKeys('{right}')
    Sleep 1
    $wshell.SendKeys('~')
    sleep 5
    get-process program | %{ $_.closemainwindow() }
    & start "C:\program.lnk"
    Sleep 3
    $wshell.SendKeys('~')
    sleep 5
    get-process program | %{ $_.closemainwindow() }
    $wshell.SendKeys('{right}')
    Sleep 3
    $wshell.SendKeys('~')
    & start "C:\program.lnk"
    sleep 3
    $wshell = New-Object -ComObject wscript.shell;
    $wshell.AppActivate('C:\program.lnk')
    sleep 1
    $wshell = New-Object -ComObject wscript.shell;
    $wshell.SendKeys('{tab}')
    sleep 1
    $wshell.SendKeys('{tab}')
    sleep 1
    $wshell.SendKeys('{tab}')
    sleep 1
    $wshell.SendKeys('{tab}')
    sleep 1
    $wshell.SendKeys('~')
    sleep 1
    $wshell.SendKeys('~')
    sleep 200
    get-process program | %{ $_.closemainwindow() }
    sleep 2
    & start "C:\program.lnk"
    $wshell = New-Object -ComObject wscript.shell;
    sleep 10
    $wshell.SendKeys('~')
    sleep 10
    $wshell.SendKeys('~')

    Kevin
    Participant
    Topics: 4
    Replies: 0

    I am using System.Windows.Forms and New-Object to have a pop up GUI from my PowerShell script. The pop up often appears behind the PowerShell ISE window. It is hidden this way. Is there a trick to make it always come to the front? I was thinking of using SendKeys. But I want other users to use it. There is no telling where they might click. I might be able to do something with SendKeys. But I think someone else has encountered this problem before.

    #59148
    Participant
    Topics: 0
    Replies: 61
    Points: -11
    Rank: Member

    Hi

    I'm not any means expert on SendKeys so I don't comment on that, but I would recommend to save and get the password otherwise. Seems that the password is now in plain text in that .txt file.

    Also if you want to "save some time" move the $executable inside the if so it would only be executed when needed. Also I would change all "Outlook" text to $process so when you change $process you don't need to type those into the subject and body etc.

    One approach to this could be also Try Catch Finally, where you could try if it is running then do what you need to do and in Catch you'll do what you'll need to do when it is not running and if needed add Finally where you could always send mail/make log files what has happened. Of course if mail send is only wanted when it is not running then add it to Catch and skip Finally, or make logging there has it been running or not.

    Jake

    #59107
    Participant
    Topics: 1
    Replies: 1
    Points: 0
    Rank: Member

    Alright, well this is to check for a process, if its not running, start it, and in one case, automatically log into the software. I've managed to cobble this together by googling and its my first effort at doing anything at all in PowerShell. On the plus side, it works exactly as I want it, I was just wondering if there are any possible undesirable effects this might have.

    You'll have to forgive the mass of sendkeys, there was no other way of getting it to run the program via a launcher. If I ran the executable directly it would start but be unresponsive to input so I was forced to navigate the launcher and start the software from there.

    $process = "TheProgram"
    $check = Get-Process $process
    
    if(!($check)) {
    
    add-type -AssemblyName System.Windows.Forms
    
    $encrypted = get-content C:\cred.txt
    $user = "UserName"
    $Password = ConvertTo-SecureString -string $encrypted
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $Password
    ConvertFrom-SecureString $Password
    $NonSecure = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))
    
    #Unfortunately I didn't know of a way to make powershell interact directly with the software, the provider "doesnt support powershell" and wouldnt help me
    #So the below is a set of keystrokes with as little time as possible between them to allow for windows to load and such
    
    Invoke-Item "C:\Program Files\TheFile\WithTheProgram\LauncherExecutable.exe"
    start-sleep -Seconds 2
    
    [System.Windows.Forms.SendKeys]::SendWait(β€œ{Right}{Right}”)
    Start-Sleep -Seconds 1
    
    [System.Windows.Forms.SendKeys]::SendWait(β€œ(+{F10})”)
    Start-Sleep -Seconds 1
    
    [System.Windows.Forms.SendKeys]::SendWait(β€œ{R}{Enter}”)
    Start-Sleep -Seconds 8
    
    [System.Windows.Forms.SendKeys]::SendWait(β€œ$user{Tab}$NonSecure{Enter}”)
    Start-Sleep -Seconds 10
    
    [System.Windows.Forms.SendKeys]::SendWait(β€œ{Enter}”)
    
    #With an email message to the IT Dept stating that the program needed relaunching
    
    Send-MailMessage -From "The Automated PC" -To "IT Dept" -Subject "TheProgram has been restarted" -Body "TheProgram was not running on MachineName and has been restarted." -SMTP "mail.com"
    }
    
    #Then more of the same with outlook
    #Although the $check variable is identical to above the script broke if it wasn't redefined here for the next section though I have no idea why
    
    $process = "outlook"
    $check = Get-Process $process
    $executable = "C:\Program Files (x86)\Microsoft Office\Office14\outlook.exe"
    
    if(!($check)) {
    Start-Process $executable
    
    Send-MailMessage  -From "The Automated PC" -To "IT Dept" -Subject "Outlook was restarted" -Body "Outlook was not running on MachineName and has been restarted." -SMTP "mail.com"
    }
    #57233
    Participant
    Topics: 2
    Replies: 4
    Points: 0
    Rank: Member

    Ok, I found a work around. The best way for me to paste at the cursor location is to send the CTRL+v keys directly. Here is a MWE. Thank you again for your help!

    # Load System.Windows.Forms to use SendKeys
    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    
    # Copy some text to the clipboard
    "Testing again: 1, 2, 3..." | clip.exe
    
    # Delay for 2 seconds while moving the cursor
    Start-Sleep -s 2
    
    # Paste using CTRL+v 3 times just for verification
    [System.Windows.Forms.SendKeys]::SendWait("^{v}") 
    [System.Windows.Forms.SendKeys]::SendWait("^{v}") 
    [System.Windows.Forms.SendKeys]::SendWait("^{v}") 
    
    # Finish up with the command window
    Write-Host "Done!"
    Read-Host "Press enter to close this window..."
    
    Keymaster
    Topics: 13
    Replies: 4872
    Points: 1,870
    Helping HandTeam Member
    Rank: Community Hero

    Have a look at SendKeys in .NET. There've also been several posts to that effect here... https://powershell.org/forums/search/sendkeys/

    #41920
    Keymaster
    Topics: 13
    Replies: 4872
    Points: 1,870
    Helping HandTeam Member
    Rank: Community Hero

    Apologies – very few of us seem to be working on GUI automation using PowerShell. SendKeys is actually part of the .NET Framework's Visual Basic libraries, not PowerShell per se. Unfortunately, PowerShell isn't really designed with GUI automation in mind, so I'm not sure we're going to be a lot of help to you.

    Amar Helloween
    Participant
    Topics: 23
    Replies: 17

    Hi All,

    I am using Send keys in powershell . For example [System.Windows.Forms.SendKeys]::SendWait("%{TAB}") I am using it in my script as "ALT+TAB" – Switch screen.

    Now the requirement is there is a text box in a webpage. I want to send Numeric values using Send keys in powershell to that text box in webpage. Please guide me on this.

Viewing 15 results - 16 through 30 (of 42 total)