Powershell script with response and no window?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AtleastItried
Posts: 51
Joined: 03 Mar 2017, 04:51

Powershell script with response and no window?

18 Nov 2018, 04:51

I want to run a command in Powershell and use the response in Autohotkey. I have found a lot of information on how to run a powershell script, but none saying how I can use the reponse from it in Autohotkey.

I have tried

Code: Select all

MsgBox % ComObjCreate("WScript.Shell").Exec("powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -noProfile -nologo dir").StdOut.ReadAll()
But this still flashes a window for a very brief time. I loop this command for every 25ms, so letting a window blink that often is not a valid solution.
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Powershell script with response and no window?

18 Nov 2018, 09:27

@AtleastItried, try this code. You'll need stdout2var.ahk, which I'm also including. There are various workarounds like PSRun.exe or some VBScript stuff, but I don't think there's any reason not to just use AHK.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

psex := "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -noProfile -nologo dir"

#Include stdout2var.ahk

msgbox % StdOutStream(psex)
stdout2var.ahk
(5.82 KiB) Downloaded 245 times
Regards,
burque505
shmurva
Posts: 1
Joined: 29 Aug 2023, 14:04

Re: Powershell script with response and no window?

29 Aug 2023, 18:53

Hello. Thanks for your script! I spent some time and rewrote the script for AutoHotKey v2

Code: Select all

#Requires AutoHotkey v2.0

#Include stdout2var_v2.ahk

MsgBox StdOutStream('powershell.exe -command "echo `'Hello Привет`'"', 'cp866')
Attachments
stdout2var_v2.ahk
(6.06 KiB) Downloaded 45 times

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: macromint, Spawnova and 342 guests