PowerShell script n/w in Administrator level

Get help with using AutoHotkey and its commands and hotkeys
ahkLily16
Posts: 3
Joined: 18 Jun 2017, 22:28

PowerShell script n/w in Administrator level

18 Jun 2017, 23:06

Hi all
Can't for the life of me get my script to work in a PowerShell session that has been run as Administrator.
Yet it works like a dream in a PS session that's opened normally with non-Admin privileges.

Code: [Select all] [Expand] [Download] (Untitled.ahk)GeSHi © Codebox Plus


My system is Windows 10 x64 v1703, PS Version 5.1, AHK v1.1.25.01

I've assumed that it is some kind of Run as Administrator issue. I've tried:
-RightClick > Run as Adminitrator when launching my .ahk file
-RightClick > Compile Script, then (.exe file) RightClick > Properties > Compatibility > Run this program as Administrator
-Tried the same Compatibility > Run this program as Administrator setting the .exe files in C:\Program Files\AutoHotKey
-Inserted code found at https://autohotkey.com/docs/commands/Run.htm#RunAs which perhaps seems to do the tasks I've tried beforehand
-Tested operation in fresh Windows 10 VM, tried again in Windows 8.1 PowerShell v4.0 VM

In all instances, I'm logged in using a Local Account of the Administrator type.

What have I missed? :?:
qwerty12
Posts: 449
Joined: 04 Mar 2016, 04:33
GitHub: qwerty12

Re: PowerShell script n/w in Administrator level

19 Jun 2017, 12:41

EDIT: You're welcome, ahkLily16 :-)

Hi,


ahkLily16 wrote:What have I missed? :?:


When you right-click PowerShell from the start menu and choose to run it as Administrator, the window's title becomes Administrator: Windows PowerShell.

You can use #IfWinActive ahk_exe powershell.exe instead or look at SetTitleMatchMode to make title matching work on substrings or, if you want to, regex it up.

Here's my modification to your script that tries to enable your PS hotkeys even if you start the command prompt first and then start PowerShell in it:

Code: [Select all] [Expand] [Download] (Untitled.ahk)GeSHi © Codebox Plus

Last edited by qwerty12 on 20 Jun 2017, 04:39, edited 1 time in total.
ahkLily16
Posts: 3
Joined: 18 Jun 2017, 22:28

Re: PowerShell script n/w in Administrator level

19 Jun 2017, 16:33

Yep, all those options worked perfectly. 10/10 mate :clap:
Swear I tried that #IfWinActive ahk_exe powershell.exe at the start of my troubleshooting! Only breaks when someone else isn't looking, right? /s
Thanks for this, much appreciated
ahkLily16
Posts: 3
Joined: 18 Jun 2017, 22:28

Re: PowerShell script n/w in Administrator level

19 Jun 2017, 16:36

Explains why my script would only work for a split second after opening the session, as it's window title takes a split second to rename itself to Administrator: Win...etc. :idea:

Return to “Ask For Help”

Who is online

Users browsing this forum: Bad husband, Bing [Bot], Class1, DarkKitten, geekgarage, Rastahammer and 41 guests