Results 1 to 3 of 3

Thread: [RESOLVED] Opening a game with a button

  1. #1

    Thread Starter
    Addicted Member evo74's Avatar
    Join Date
    Aug 2012
    Location
    Mars
    Posts
    133

    Resolved [RESOLVED] Opening a game with a button

    i'm making my final version of my software and i have a big problem i want to open a game with a button, sounds simple but i can't, i tryed shell, process.start, peocess.start("cmd", "/c or /k") and even system.diagnostics and all of them have the same problem they open it but the game crashes on startup or if is a luncher any of the file requested aren't opened in others words is like opening the .exe file of the game with no external files, but i don't have this problem with any program only with games
    Last edited by evo74; Jun 19th, 2013 at 04:52 AM. Reason: write mistake

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Opening a game with a button

    The most common reason for this issue is the working directory. When you run an EXE from the commandline, its working directory will be the folder containing the EXE. If you run an EXE by calling Process.Start, its working directory will be the working directory of your current process by default, which will probably be the folder containing the EXE of the current program but may have been changed. What you need to do is set the working directory of the new process explicitly. To that end, create a ProcessStartInfo object, configure it appropriately and then pass it as an argument to Process.Start. Note that, if you have the path of the EXE to run, you can use the IO.Path.GetDirectoryName method to get the path of the folder containing it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member evo74's Avatar
    Join Date
    Aug 2012
    Location
    Mars
    Posts
    133

    Re: Opening a game with a button

    thx jmcilhinney that worked like a charm
    Code:
    Dim Game1 As New ProcessStartInfo
    Game1.FileName = My.Settings.GamePath1
    Game1.UseShellExecute = True
    Game1.WindowStyle = ProcessWindowStyle.Normal
    Game1.WorkingDirectory = IO.Path.GetDirectoryName(My.Settings.GamePath1)
    Dim Game1proc As Process = Process.Start(Game1)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width