64-bit Admin problems - conflict with AHKU64?

Discussion, questions and support.
Posts: 9
Joined: Sat Apr 08, 2017 3:55 pm

64-bit Admin problems - conflict with AHKU64?

PostPosted by burque505 » Sun Apr 09, 2017 6:57 pm

Hi, I use 64-bit AHK_L generally. I frequently have to add "RunAs, Administrator" to my scripts to make them work, especially with MS Office programs.
I believe FastKeys is AHK_H U32 internally, but of course I could be wrong.
Scripts I put in "C:\Program Files (x86)\FastKeys\Scripts\" generally run fine from a FastKeys command or script, but I can't get them to run elevated, if at all at least not with any consistency. For example, a script I have to insert some rich text in an MS Word document works fine if I double-click it (i.e. it gets executed by C:\Program Files\Autohotkey.exe), and runs elevated since I have "RunAs, Administrator" in it. In FastKeys, I've tried both pasting the entire script into a Command window, and running the script from a Script Window. No joy. This is probably a deal-breaker for me if I can't find a workaround.
Here's the script, if it might give a clue:
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.
#Persistent
RunAs, Administrator
FilePath := "C:\test\AHK_test\WL-RTF.docx"

:*:;irtf::
oDoc := ComObjGet(FilePath)
oDoc.Range.FormattedText.Copy
oDoc.Close(0)
Send, ^v
Send, {Backspace}
return


Thanks in advance for all help.

Site Admin
User avatar
Posts: 642
Joined: Sat Mar 02, 2013 9:02 pm

Re: 64-bit Admin problems - conflict with AHKU64?

PostPosted by Marko » Sun Apr 09, 2017 8:07 pm

Could you try setting FastKeys to run in Administrator mode (Preferences/Functions/Run as Administrator)?

You could also try adding this code to the beginning of the script:
Code: Select all
 if not A_IsAdmin
 {
  Run *RunAs "%A_ScriptFullPath%"
  ExitApp
 }

Posts: 9
Joined: Sat Apr 08, 2017 3:55 pm

Re: 64-bit Admin problems - conflict with AHKU64?

PostPosted by burque505 » Sun Apr 09, 2017 8:35 pm

Code: Select all
     if not A_IsAdmin
     {
      Run *RunAs "%A_ScriptFullPath%"
      ExitApp
     }


at the beginning of the script did not work, and in fact threw an error.
I set the preferences for functions to Run as Administrator (thanks, I hadn't noticed that), but when I hit "save" the program crashed.
I have FastKeys itself set to always run elevated, by the way.

Win7, SP1, 64-bit, 64-bit Office 2016.

Are there any plans for a 64-bit version of the program?

Posts: 9
Joined: Sat Apr 08, 2017 3:55 pm

Re: 64-bit Admin problems - conflict with AHKU64?

PostPosted by burque505 » Wed Apr 12, 2017 4:39 pm

Thanks, Marko, I'm getting there. I believe part of the failure was my "copy" settings within Word.
I'm still going to have to find out how to tell Word to "Use Source Formatting" or live with selecting the control manually, but I'll get there.
It works either with the code from Marko at the top, or with "RunAs, Administrator", so that's a relief.

Code: Select all
if not A_IsAdmin
     {
      Run *RunAs "%A_ScriptFullPath%"
      ExitApp
  }
;~ RunAs, Administrator
#SingleInstance
#Persistent
FilePath := "C:\test\AHK_test\WL-RTF.docx"
oDoc := ComObjGet(FilePath)
oDoc.Range.FormattedText.Copy
oDoc.Close(0)
Send, ^v
return
Escape::ExitApp


Regards,
burque505

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest