Jump to content

Run defined program fails to run..


Orkhayiq
 Share

Recommended Posts

Hey,

I've got a bit of code that was running well before when it was pointed to another .exe but now gives trouble when trying to run a different one.

When the user defines the .exe location on the first launch of the script, it writes to an .ini, then reads the written .ini path info then runs the program as it should.

But in the other case when the user has already defined the location and is launching the script for the second time, the script reads the ini and launches the .exe but then the program fails to fully launch. It'll appear in the Task Manager processes window for about 5 or so seconds then close without opening any window(the game).

Why does Func LaunchGame() fail to launch the game fully but the Func selectfile() works as it should?

This should be solvable by some coding right? ..it's not the games error I hope.. Is it something to do with using the FileOpenDialog?

Please excuse my coding, I'm new! :mellow:

Func LaunchGame()
    
$bfbc2config = @MyDocumentsDir&"\BFBC2Beta\??? - Prefs.ini"

$msgbox = MsgBox ( 262144+32+4, "|[< ??? - Tweaker | "&$Ver&" >]|", "The new settings were written successfully."&@CRLF&@CRLF&"Would you like to launch BFBC2 now?" )

            ; If No (7): Close msgbox
            If $msgbox = 7 Then 
            EndIf

              
            ; If Yes (6): Run Program
            If $msgbox = 6 then
                If FileExists ( $bfbc2config ) Then
                    $BFBC2Loc = IniRead ( $bfbc2config, "??? Launch", "Path", "" )
                    Run($BFBC2Loc)

                        ExitProgram()
                        
                Else
                            
                    selectfile()
                    
                EndIf
            EndIf
EndFunc



Func selectfile()
    

$bfbc2config = @MyDocumentsDir&"\BFBC2Beta\??? Tweaker - Prefs.ini"

    $Define = MsgBox ( 32+1, "|[< Creating Preferences File >]|", "??? Tweaker - Prefs.ini will be created in "&@MyDocumentsDir&"\BFBC2Beta"&@CRLF&@CRLF&"This file will store the tweaker's user-defined preferences."&@CRLF&@CRLF&"Press OK to define your BFBC2Game.exe location..")
        If $Define = 1 Then

            $fod = FileOpenDialog ("|[< Choose File >]|", @ProgramFilesDir&"\Electronic arts\Battlefield Bad Company 2", "Locate (BFBC2Game.exe)|Other (*.exe)|All files (*.*)", 2000390, "BFBC2Game.exe" )

            ; How do you write the .ini to the same folder that the script is running from without using a path?
            ; How do you only allow the file Steam.exe to be selected and if incorrect try again.
            If FileExists("BFBC2Game.exe") Then
                IniWrite ( $bfbc2config, "BFBC2 Launch", "Path", $fod )
                IniWrite ( $bfbc2config, "??? Tweaker", "Author", "Orkhayiq" )
                
                    $BFBC2Loc = IniRead ( $bfbc2config, "BFBC2 Launch", "Path", "" )
                    Run($BFBC2Loc)
                    
                        ExitProgram()
                    
                If $Define = 2 Then
                EndIf
            
            Else 
                $NotSelected = MsgBox ( 48+5, "|[< Error >]|", "You didn't select BFBC2Game.exe" )
                
                If $NotSelected = 4 Then
                    selectfile() 

                EndIf
                

            EndIf
        EndIf

EndFunc

Thanks in advance!

(..And if you're wondering, this isn't for any malicious/botting purposes. This is a segment of a script that writes graphics settings to a .ini so they don't have to be set in-game.)

Edited by Orkhayiq
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...