0

Tomcat JvmMs option is added under below Windows registry entry for a Windows Tomcat service called "MyService"

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Apache Software Foundation\Procrun 2.0\MyService\Parameters\Java

I want to be able to programmatically edit the JVM Options added under above registry location. For eg lets say was set to value XX during service install and now i want to update it to YY later (Programmatically).

How can i use windows SC command? How should my command look like? Any example?

Helena
  • 444
  • 2
  • 15

1 Answers1

0

Not sure with sc.exe, but if you're open to using PowerShell, here's what worked for me. My use case was to add a -javaagent, but can be easily adapted to whatever your use case is. It does so in an idempotent manner.

$path = 'HKLM:\SOFTWARE\WOW6432Node\Apache Software Foundation\Procrun 2.0\Tomcat*\Parameters\Java'
$name = 'Options'
$appendString = '-javaagent:C:\path\to\agent.jar'
$currentValue = Get-ItemPropertyValue -Path $path -Name $name
$newValue = $currentValue -notlike "*$appendString*" + $appendString
Set-ItemProperty -Path $path -Name $name -Value $newValue
# Double check
Get-ItemPropertyValue -Path $path -Name $name
stevetu21
  • 160
  • 1
  • 8