Sign in to follow this  
Followers 0
katech

Compiled script throws errors on build computer

13 posts in this topic

OK, first off I will admit that this has really got me puzzled. I created a script that runs perfectly on the computer that I used to develop it on, until I compile it that is. As soon as I compile it, it fails to execute a FileCopy command due to apparent path issues. The really puzzling thing is that the compiled script works just fine on other computers, just not my own! Again, the uncompiled script runs fine on my computer. At no point am I receiving any error during compilation. I am running Windows 7, 64bit, and am thus compiling as a 64bit application. All of the GUI portions of the script work without issue. Only the FileCopy and ShellExecute commands are having issues once compiled. Both are contained in the function that I have pasted below. The values are passed in to the function using this command: LaunchApp(_GUICtrlComboBox_GetEditText($FolderCombo), $radioval2), which gets the folder value from a dropdown combo box and a radio button respectively.

When executed after compiling, this function is throwing the following 2 errors:

1. It throws a message box stating "An error occurred copying the config file" (per my code in case there was an errro during the copy process).

2. It then throws an error for the ShellExecute command stating that it cannot find the executable, even though the path in the error box is exactly correct.

I have added a number of MsgBox entries as part of my troubleshooting in order to verify that my variables aren't getting stomped on during execution, but all of the values check out. The fact that it runs perfectly on my system uncompiled is what is really throwing me.

Here is the function in question:

Func LaunchApp($Folder,$radioval2)
    Local $LaunchPath, $AppName, $Envr, $CopyStat, $ConfigName
    $AppName="test.exe"
    Select
        Case $radioval2 = 0
            $Envr=" /start"
            $ConfigName="test.exe.config.default"
        Case $radioval2 = 1
            $Envr=" /start /c:ct"
            $ConfigName="test.exe.config.ct"
        Case $radioval2 = 2
            $Envr=" /start /c:qa1"
            $ConfigName="test.exe.config.qa1"
    EndSelect

    $CopyStat = FileCopy($AppPath & $Folder & $ConfigName, $AppPath & $Folder & "test.exe.config", 1)
    MsgBox(0, "CopyStat", $CopyStat)
    MsgBox(0, "Source Path", $AppPath & $Folder & $ConfigName)
    MsgBox(0, "Dest Path", $AppPath & $Folder & "test.exe.config")

    If $CopyStat=0 then
        MsgBox(48, "File Error", "An error occurred copying the config file.")
    EndIf
    $LaunchPath=$AppPath & $Folder & $AppName

    If ProcessExists("Test.exe") Then
        MsgBox(48, "Test", "Test is already running." & @CRLF _
        & @CRLF _
        & " You must close Test before launching again.")
        Return
    EndIf
    ;MsgBox(0, "LaunchPath", $LaunchPath)
    ;MsgBox(0, "Envr", $Envr)
    ;MsgBox(0, "AppPath", $AppPath & $Folder)
    Local $pid=ShellExecute($LaunchPath, $Envr, $AppPath & $Folder)

EndFunc

Any ideas or advice that you can give me will be greatly appreciated. I should also mention that it actually does work a few times. After about 3 launches, it then fails on every successive attempt.

Share this post


Link to post
Share on other sites



I'd throw in a few FileExists statements, with error msgs.

ShellExecute can fail, if I remember rightly, because of spaces in a non-quoted path/filename.

Then again, sometimes your security software will allow uncompiled scripts to execute, but not executables, unless given permission ... especially if it detects changes, and UPX is involved.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

@katech

Welcome to the forum.

btw.

please use code tags when you post your code - here is HOWTO


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks @Knight Templar, on your suggestion, I completely disabled my real time virus scanning (Microsoft Security Essentials). Sadly, it had no impact. So, I then decided to boot into safe mode and test there with a new build where I actually have the ShellExecute commented out, and I'm simply throwing up a message box with the $CopyStat result. Normally, I can only invoke the function 3 or 4 times before receiving a 0 return value, and once it fails, it fails every time thereafter until I close and relaunch the app.

However, booted into safe mode, I invoked the function about 50 times with success every time! Therefore, I know for certain that something else on my system is interfering with both the copy function and the ShellExecute (they always either succeed or fail in unison). My problem is that since it was not my antivirus, I'm not sure where to look next. Any ideas? Has anyone ever run into a situation other than antivirus where an uncompiled script runs perfectly, but after compiling it fails on that same computer? My compiled script seems to run fine on everyone else's computer, just not on the dummies computer that created the blasted thing! (sigh....)

Booted back into normal mode with AV still disabled, it failed after 3 attempts, which is pretty typical. Therefore, simply rebooting had no impact whatsoever. If you have any thoughts on what else to check for, I'm all ears.

Thanks for your help,

katech

Edited by katech

Share this post


Link to post
Share on other sites

$AllUsersPath = EnvGet ("ALLUSERSPROFILE")
$AppPath = $AllUsersPath & "TestAppTest"

$Folder = the folder name selected in the ComboBox by the end user, which is a list of version folders under the $AppPath

$AppName = "Test.exe"

Therefore,

$LaunchPath = $AppPath & $Folder & $AppName

Ultimately, this utilty is nothing more that a launcher that allows the user to select a unit type and version that they want to run in the GUI, and then click the Launch button to kick off the app using the parameters selected within the GUI. For some reason, once compiled, the utility can no longer find the files in question, even though the paths all resolve correctly. The copy fails because the exe can't find the files, where the uncompiled script has no issue.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You say ShellExecute throws an error saying it cannot find the file.

How exactly do you know this, there is no indication what @error means other than it failed in the helpfile?

What is the return value of Shellex...

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Your solution may be as simple as giving permission via each folder's security tab (right-click -> Properties).

Or perhaps you need to just give your program Full permissions in the same way.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

@JohnOne, I know that the ShellExecute command cannot find the executeable because it is throwing an explicit error stating such. The exact text of the error dialog states: "Windows cannot find 'C:ProgramDataTestAppTestv1384Test.exe'. Make sure you typed the name correctly, and then try again."

Keep in mind that it actually succeeds 2 or 3 times, and then suddenly throws the error on every subsequent attempt. Once it fails, it never succeeds again. I originally suspected that one of the path variables was getting trashed, but the full path in the error message is exactly correct.

@Knight Templar, this is not an access rights issue to the files, as I am logged into the machine with admin rights and have full control over the directories and files in question. Also, access is not an issue when executed as an au3 file. On your suggestion, I attempted launching the compiled app as administrator, but this yeilded no difference in outcome.

Share this post


Link to post
Share on other sites

@JohnOne, I know that the ShellExecute command cannot find the executeable because it is throwing an explicit error stating such. The exact text of the error dialog states: "Windows cannot find 'C:ProgramDataTestAppTestv1384Test.exe'. Make sure you typed the name correctly, and then try again."

Keep in mind that it actually succeeds 2 or 3 times, and then suddenly throws the error on every subsequent attempt. Once it fails, it never succeeds again. I originally suspected that one of the path variables was getting trashed, but the full path in the error message is exactly correct.

@Knight Templar, this is not an access rights issue to the files, as I am logged into the machine with admin rights and have full control over the directories and files in question. Also, access is not an issue when executed as an au3 file. On your suggestion, I attempted launching the compiled app as administrator, but this yeilded no difference in outcome.

 

If you restart the program after your first failed attempt at running the program does it start to work again? Are you using FileRead or FileClose anywhere in your script?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

@Computergroove,

Yes, if I close the program and relaunch, it works for another 2 or 3 launches, then starts to fail again. I am not using FileRead or FileClose anywhere in the script. However, I am using IniRead and IniWrite, but I am assuming that these functions are handling the read and close operations within the functions themselves. Also, these calls are reading from and writing to an entirely different file that what I am attempting to launch (but I get your point, obviously something is screwing up my file pointers or something).

Share this post


Link to post
Share on other sites

Can you comment out any portion of the program that changes anything in the ini file and see if the problem persists? You basically have a broken object is what I'm thinking. Track it down. Worst case scenario open a new tab in Scite and copy and paste section by section and test 3+ times until it happens again. This is what makes programming challenging (and rewarding).


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

What is strange is that it appears your OS is throwing the error and not your script.

I think the way ShellExecute works has been changed in recent releases as I don't think it used to return PID.

I don't think an error should be thrown by the OS either if it cannot find the file.

I think that part is a bug.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
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
Sign in to follow this  
Followers 0