0

I am creating an application for an Arma 3 server that directly launches the game and connects the user to a specific server. The problem that I am encountering, being the relatively new VB coder that I am, is that the Arma3battleye.exe directory (the .exe used to launch the game) may be installed in different directories depending on where the user originally installed it. I've developed the code to connect the user to the server if they've installed Arma in the normal location:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Process.Start("C:\Program Files (x86)\Steam\steamapps\common\Arma 3\arma3battleye.exe", "2 1 -noSplash -skipIntro -useBE -noPause -world=empty -connect=192.99.36.80 -port=2505 -mod=@Exile;@AlRayak;@AllInArmaTerrainPack;@CUP Units;@CUP Vehicles;@CUP Weapons;@CBA_A3;@TRYK's Multi-Play Unifrom's pack")

End Sub

However, after researching for many hours, I cannot determine how to have the program automatically determine the install directory of the arma3batteye.exe and then execute it with all of the correct start parameters included. Any solutions or pointers to help solve this problem would be greatly appreciate.

TLDR: What is the easiest way to program an application to automatically find the install directory of a given .exe and then execute it with the given parameters as I've done above?

Edit: Another thread similar to mine asks a similar question (how to view/get to the steam folder without hard coding it. They arrive at the conclusion that if you do (for winx32):

Dim strSteamInstallPath as String = My.Computer.Registry.GetValue(
"HKEY_LOCAL_MACHINE\SOFTWARE\Valve\Steam", "InstallPath", Nothing)

Or using this registry location for winx64:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Valve\Steam

and then were to create a button using Process.Start that it would allow you to ultimately view the directory. At this point I haven't discovered a way for that to translate into being able to execute the battleyearma3.exe from within that steam directory with the proper parameters. While it seems this code may be useful in arriving at the solution I'm looking for, I can only get the program to view the general steam directory at this time.

edit: Solution posted at bottom. Thanks to @VisualVincent who was really the one that allowed me to complete this. It really should be you having posted the correct answer, not me.

John James
  • 45
  • 2
  • 7
  • Not an elegant solution but, you could code a section where on first use the user will browse to the exe. This path can then be saved for subsequent use. – Mych Feb 23 '16 at 08:14
  • Or you can search the entire HD for the exe and save it for subsequent use. Is there a shortcut on their desktop you could parse? Or a registry entry describing the location? – Andrew Mortimer Feb 23 '16 at 08:16
  • Possible duplicate of [Find steam games folder](http://stackoverflow.com/questions/34090258/find-steam-games-folder) – Visual Vincent Feb 23 '16 at 09:49
  • I tried using a registry key to locate the arma3battleye.exe, however only the arma3.exe is located in the registry. (Need to launch arma3battleye.exe with parameters 2 1 so that the anti-cheat launches as well as the game. @Andrew Mortimer Would you mind pointing me in the right direction for allowing the user to establish the directory and then saving this for next use? – John James Feb 23 '16 at 18:43
  • The `HKEY_LOCAL_MACHINE\SOFTWARE\Valve\Steam` registry key should _for example_ point to the `%ProgramFiles%\Steam` directory. From there you can use `IO.Path.Combine()` to go through all the folders. – Visual Vincent Feb 24 '16 at 00:53
  • `Dim BattleyePath As String = IO.Path.Combine(, "SteamApps", "common", "Arma 3", arma3battleye.exe")` – Visual Vincent Feb 24 '16 at 00:54
  • @VisualVincent I've located the proper steam registry location to: `HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Valve\Steam` for x64 OS (like mine) However when I dim: `Dim BattleyePath As String = IO.Path.Combine("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Valve\Steam", "SteamApps", "common", "Arma 3", "arma3battleye.exe")` And create button: `Process.Start(BattleyePath, "2 1 -noSplash.....etc` I get `An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll Additional information: The system cannot find the file specified` Thanks for your great help so far! – John James Feb 24 '16 at 12:14
  • @VisualVincent What I have noticed from browsing another thread is that if I do `Dim strSteamInstallPath as String = My.Computer.Registry.GetValue( "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Valve\Steam", "InstallPath", Nothing)` and execute the same button with strSteamInstallPath I can get the Steam directory to open at least. I'm not sure that this helps much but I feel that there may be a logical connection here that I'm not skilled enough to pin point. – John James Feb 24 '16 at 12:22
  • Take your `strSteamInstallPath` variable and put it as the first parameter of `IO.Path.Combine()` in your first comment. You cannot do `IO.Path.Combine("HKEY_LOCAL...` because the function doesn't read the registry, you will end up with a path like this (which is why you get the exception): `HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Valve\Steam\SteamApps\common\Arma 3\arma3battleye.exe`. – Visual Vincent Feb 25 '16 at 09:19
  • This would be the correct way: `Dim BattleyePath As String = IO.Path.Combine(strSteamInstallPath, "SteamApps", "common", "Arma 3", "arma3battleye.exe")` – Visual Vincent Feb 25 '16 at 09:20

2 Answers2

0

I would use the registry... You add a key like HKEY_LOCAL_MACHINE\Software\Arma3\ServerPath = "..." when you install the server.

And whenever you need to start the client, you check up the path from that registry key.

Martin Verjans
  • 4,675
  • 1
  • 21
  • 48
0

So with the comments and tips you gave me (especially @VisualVincent) I managed to piece enough stuff together to solve my issue. Thanks to everyone for the help:

First I declared 2 variables. The first one (BattleyePath) goes into the registry as far as I can get it to dig. Executing this variable on its own will open the users steam directory. I then declared a second variable (BattleyePath2) which uses IO.Path.Combine get to the directory the users Arma3.exe is installed in:

Dim BattleyePath As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Valve\Steam", "InstallPath", Nothing) Dim BattleyePath2 As String = IO.Path.Combine(BattleyePath, "SteamApps", "common", "Arma 3", "arma3battleye.exe")

I added a couple buttons to close the program and mute the sound:

`Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Me.Close() End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

    My.Computer.Audio.Stop()

End Sub`

Finally I created the button that actually launches the game:

`Private Sub Button4_Click_1(sender As Object, e As EventArgs) Handles Button4.Click

    Process.Start(BattleyePath2, "2 1 -noSplash -skipIntro -useBE -noPause -world=empty -connect=192.99.36.80 -port=2505 -mod=@Exile;@AlRayak;@AllInArmaTerrainPack;@CUP Units;@CUP Vehicles;@CUP Weapons;@CBA_A3;@TRYK's Multi-Play Unifrom's pack")

End Sub`
John James
  • 45
  • 2
  • 7