Jump to content

Run() not working in compiled script running as Administrator


Recommended Posts

This is driving me crazy. My goal is to open a .pdf with whatever the default program is to open that type of file. The .pdf will be inside of the compiled exe and then installed to the temp directory using fileinstall(). When the program exits the .pdf will be deleted from the temp directory (If there is an easier way to open a file that was compiled into an exe, please let me know). Some information:

OS: Windows 8.1 64-bit

Autoit version: v3.3.12.0

Default PDF reader: Adobe Reader 11

Script location: Documents folder

The script that I am using this for is more complex, but I have narrowed down what the problem is. This is the script I am testing:

#RequireAdmin

$path = @TempDir & "\Help.pdf"
Run(@ComSpec & " /k start " & $path)

This works fine. When I run it, Adobe Reader pops up with my file. I am requiring admin because the more complicated script does as well and that seems to be causing the problem. The issue comes when I try running the compiled script. Command Prompt pops up, but Adobe Reader does not. When I look at the process list in task manager there are two processes named "Adobe Reader (32 bit)". When I end both of these, and enter

start C:\<path to temp dir>\Help.pdf

 into the cmd window that the program opened, the processes comes up again but nothing else. If I end both of them again and try running cmd as admin and then enter 

start C:\<path to temp dir>\Help.pdf

my file is displayed.

I have tried this using different .pdf files in many different locations with no difference. I have also tried running Adobe Reader directly using:

#RequireAdmin

Run("C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe")

Same results as before. Works compiled, but not uncompiled.

One more thing. I have also tried doing this using ShellExecute(C:\<path to temp dir>\Help.pdf). This has the same results.

I hope someone can help me because this has me absolutely befuddled...

 

-DakotaSamuel

Edited by DakotaSamuel
Link to comment
Share on other sites

 

#RequireAdmin

FileInstall ( 'Help.pdf', @TempDir & '\' )
MsgBox ( 262144, 'Help.pdf', 'FileExists : ' & FileExists ( @TempDir & '\Help.pdf' ) )
ShellExecute ( @TempDir & '\Help.pdf' )

Have tried compiled and not .

And pdf is well open by his default prog.

 

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Try ShellExecute instead of Run

Yes, I have tried that and there is no difference. Thank-you for the suggestion though. :-/

 

Have tried compiled and not .

And pdf is well open by his default prog.

I know right? There is no reason it shouldn't be working.

 

I am going to try compiling it and running it on a few different computers and report back with anything I find.

 

-DakotaSamuel

Edited by DakotaSamuel
Link to comment
Share on other sites

This just keeps getting better and better. I uninstalled Adobe Reader and ran the compiled script again. When I uninstalled, my default program had changed to a PDF Converter. This opened the file fine. I installed the latest version of Adobe Reader (from here) and tried again. Same results as before. I then tried it on another computer. This one is Windows 10 64-bit. I ran the script, but as a default pdf viewer had not yet been picked, it opened with program chooser. When I chose a program, the file opened. I installed the latest version of Adobe Reader on the machine, and same as before nothing happens when the script is run. 

I also repeated this process on two other computers. One was Windows 7 64-bit, and the other was Windows 8 64-bit. 

So it appears that my problem can be summarized as this: A compiled autoit script running in administrator on a 64-bit machine cannot open the latest version of Adobe Reader.

But it works with any other PDF reader, or if the script is not compiled, or if the script (compiled or uncompiled) does not require administrator.

Help? Please? :blink:

 

-DakotaSamuel

Link to comment
Share on other sites

I just tried opening it using this method:

;this was butchered from various help files.

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$path = 'C:\file.pdf'

$mainGUI = GUICreate("PDF viewed as IE object",720,480)
GUISetStyle(BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_SIZEBOX, $WS_POPUP, $WS_SYSMENU))
$oIE = ObjCreate("Shell.Explorer.2")
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 0,720 ,480)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
$oIe.Navigate($path)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Same as before. Works unless it is compiled. Do you think one of you could send me your compiled script that is working? I am thinking there might be an issue with my version of Autoit, so I would like to try it with yours and see if it works. Last night I updated to v3.3.14.1, but still nothing. 

 

My goal is to distribute my program, so I am trying to make my script display a help file to help people figure out how to use it. I thought the easiest way to do that would be to save it as a PDF and have my program open it. It is proving to be not so easy. I have literally spent over 20 hours simply trying to make a script open a PDF.:think: Perhaps there is a better way I should/could be doing this? I am new to this so I don't know how it is commonly done.

 

-DakotaSamuel

Edited by DakotaSamuel
Link to comment
Share on other sites

If you're using RunAs to run it as an administrator, you don't need #RequireAdmin in the script being ran.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks for the suggestion @KingBob. I am assuming I would replace my Run() commands that require administrator rights with that? I suppose that could work, but I would have to prompt the user for their username and password with a textbox or something which I don't want to have to do since my program already gets detected by Windows defender (my next thing to try to fix), and I think asking the users to enter their credentials might make them even more nervous. 

But I think I might have gotten it working. I used the _RunWithReducedPrivileges UDF by @Ascend4nt to open the PDF as a normal user and it worked! Going to have to do some more testing to make sure though.

 

-DakotaSamuel

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...