Passing varaible to external powershell inside AHK Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
shadad
Posts: 32
Joined: 23 Jun 2018, 05:21

Passing varaible to external powershell inside AHK

25 Jun 2018, 00:46

Hi there :D

am preparing a long script to retrieve the LAPS password in to a variable and print it to a msgbox. i have this nice script that do the job silently and print the result to msgbox perfectly. however, when i replaced the server name by the variable %VAR% which i set it before its not working and shows nothing. its only work if i mention the computer name as string but not as %VAR% variable! i think the %VAR% is not replaced or passed to that command for some reason.

can any one advice? :roll:

Code: Select all

DetectHiddenWindows On
VAR = exampleServerNEW
Run %ComSpec%,, Hide, pid
WinWait ahk_pid %pid%
DllCall("AttachConsole", "UInt", pid)
WshShell := ComObjCreate("Wscript.Shell")
exec := WshShell.Exec("powershell.exe -command ""Get-AdmPwdPassword -ComputerName %VAR% |  foreach { $_.Password }""")
output := exec.StdOut.ReadAll()
MsgBox %output%
DllCall("FreeConsole")
Process Close, %pid%
return
shadad
Posts: 32
Joined: 23 Jun 2018, 05:21

Re: Passing varaible to external powershell inside AHK  Topic is solved

26 Jun 2018, 01:43

Got it myself :D. damn this took almost 3 days/

after long testing the script work perfect. all if i have to do is changing my code from this :

Code: Select all

exec := WshShell.Exec("powershell.exe -command ""Get-AdmPwdPassword -ComputerName %VAR% |  foreach { $_.Password }""")
to this :

Code: Select all

exec := WshShell.Exec("powershell.exe -command Get-AdmPwdPassword "-ComputerName VAR "|  foreach { $_.Password }")

I need to dig deep to find out why the reason. testing and assuming is not what i like. am still new to Autohotkey scripts but am learning.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, jameswrightesq and 279 guests