Powershell Read-Host Prompt

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
joshsullivan
Posts: 1
Joined: 08 Aug 2018, 07:23

Powershell Read-Host Prompt

08 Aug 2018, 07:45

Hi,

I currently have a powershell script that I would like to use with AHK that sends an email to a specified email address:

Code: Select all

$EmailFrom = "SETEMAIL"
$EmailTo = "SETEMAIL"
$Subject = Read-Host -Prompt 'Input Task Name'
$Body = $null
$SMTPServer = "PROVIDERSMTPSERVER"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("SMTP_USERNAME", "API_PASSWORD");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
This script when run in Powershell or ISE run perfectly, prompting the user for input which then edns up in the Subject line and the email is sent and received.

Once I try to invoke it with AHK it opens the Powershell window for a second and immediately closes it without giving me the chance to input anything and the email is never sent, here is the AHK script:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
#Persistent

^J::

psScript := "C:\Scripts\SendEmail.ps1"

Runwait, Powershell "%psScript%"
If you have any suggestions, I would greatly appreciate it. Thank you.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 303 guests