Updating registry then running an application

I’ve been tasked with importing registry settings for TeamViewer then it needs to run a command against it’s exe to apply those settings. The commands provided by teamviewer look like this:

cd
start Windows\SysWOW64\reg.exe import “\XXXXXX\XXXXXXX\XXXXXXXX\TeamViewer_Settings.tvopt"
TIMEOUT 2
"C:\Program Files (x86)\TeamViewer\TeamViewer.exe” --ReloadSettings
exit

This is probably easy but I’m having trouble wrapping my head around a graceful way to do this. That .tvopt file will also need to be added to each endpoint. Would appreciate any advice.

The tvopt file is essentially a .reg file.

For creating and running the batch commands, I’d use the method I outlined at Tip: Running Commands and Saving Output (Windows)

As for the reg file, I’d also create that on the file with a set of createfile until commands similar to the ones I used there to create the batch file; just paste in the text and after the closing marker move it to a .tvopt file.

If the file contains any ‘{’ symbols replace them with ‘{{’ to escape them, so the ActionScript doesn’t take them as a relevance substitution

Thanks, Jason, apologies, this is feeling a bit over my head right now. Am I creating a .bat file and then uploading that to the console and running it with this? And the pathname for the tvopt file would be the default location where downloads are installed, I would assume. How do I path that out?

I believe the suggestion here is that you can create both the batch file as well as the .tvopt (or .reg) file directly within the actionscript (i.e. “on the fly”) then run it rather than performing a download then execution.

The super high-level actionscript flow might look something like:

  1. use createfile to create the .tvopt/.reg file (then rename it to desired name)
  2. use createfile to create the batch file (then rename it to desired name)
    • in terms of pathing, you can either move the files to a temporary location, or you can use relevance substitution to specify the path of the files
  3. execute the batch file

Essentially, since there are no binaries really (just batch & reg file) all of this can be embedded within the actionscript rather than including downloads (especially if the batch and reg files are small).

1 Like

You could host a copy of the .tvopt file on the server, add a prefetch or download command for it, and download the file as part of the action. But you’ll need to track the size/hash values of the file and update your fixlets when it changes.

Generally it’s easier to just build the file dynamically as part of the actionscript itself, that’s what I meant. Putting it all together, here is where I think you could start, just replace the content in the .reg file builder with what you actually need added to the registry

// build the .reg file
delete __createfile

createfile until BIGFIX_END_OF_FILE_MARKER_TAG
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Test]
"value"="I am a test value"
BIGFIX_END_OF_FILE_MARKER_TAG

delete myoptions.reg
move __createfile myoptions.reg

// build the script to import the .reg file and reload settings with TeamViewer
delete __createfile

createfile until BIGFIX_END_OF_FILE_MARKER_TAG
C:\Windows\SysWOW64\reg.exe import myoptions.reg
REM Restart TeamViewer to reload the settings.  Use "start" to prevent the script from waiting for TeamViewer to exit.
start "" "C:\Program Files (x86)\TeamViewer\TeamViewer.exe" --ReloadSettings
BIGFIX_END_OF_FILE_MARKER_TAG

delete GeneratedScript.cmd

move __createfile GeneratedScript.cmd


action uses wow64 redirection false

waithidden cmd.exe /c "GeneratedScript.cmd > "C:\Windows\Temp\ScriptOutput.txt" 2>&1"
1 Like