Skip to content

Instantly share code, notes, and snippets.

@ril3y
Created December 26, 2024 22:35
Show Gist options
  • Save ril3y/ddfd436e0644315ce2b0f82c3b77b9dc to your computer and use it in GitHub Desktop.
Save ril3y/ddfd436e0644315ce2b0f82c3b77b9dc to your computer and use it in GitHub Desktop.
A powershell script that will launch firecontrol with java not the provided exe. This is to possible make an agent to extend firecontrol
function Launch-FireControl {
# Define paths
$javaPath = "C:\Users\riley\AppData\Local\FireControl\runtime\bin\java.exe"
$appDir = "C:\Users\riley\AppData\Local\FireControl\app"
$configFile = "$appDir\FireControl.cfg"
# Check if configuration file exists
if (-Not (Test-Path $configFile)) {
Write-Error "Configuration file not found: $configFile"
return
}
# Read the config lines
$config = Get-Content $configFile
# Extract classpath
$classPaths = ($config | Select-String "app.classpath=" | ForEach-Object {
# Each line is something like: app.classpath=$APPDIR\foo.jar
$line = $_.Line
$value = $line.Substring($line.IndexOf("=") + 1).Trim()
$value -replace '\$APPDIR', $appDir
}) -join ";"
Write-Host "Classpath: $classPaths"
# Extract Java options
$javaOptions = ($config | Select-String "java-options=" | ForEach-Object {
# Each line might look like: java-options=--add-exports=javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED
# Grab everything after the first '='
$line = $_.Line
$option = $line.Substring($line.IndexOf("=") + 1).Trim()
$option
})
# Ensure `-Dfile.encoding=UTF-8` is included, if desired
if (-Not ($javaOptions -contains "-Dfile.encoding=UTF-8")) {
$javaOptions += "-Dfile.encoding=UTF-8"
}
Write-Host "Java Options: $($javaOptions -join ' | ')"
# Extract the main class
$mainClass = ($config | Select-String "app.mainclass=" | ForEach-Object {
$line = $_.Line
$line.Substring($line.IndexOf("=") + 1).Trim()
})
Write-Host "Main Class: $mainClass"
# Verify the Java path
if (-Not (Test-Path $javaPath)) {
Write-Error "Java executable not found: $javaPath"
return
}
# Verify the classpath is not empty
if (-not $classPaths) {
Write-Error "Classpath is empty. Check FireControl.cfg."
return
}
# Build the full command array
$command = @()
$command += $javaPath
$command += $javaOptions
$command += "-cp"
$command += $classPaths
$command += $mainClass
Write-Host "Executing Command: $($command -join ' ')"
# Now actually run it
& $javaPath @javaOptions -cp $classPaths $mainClass
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment