• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Batch Script issue - P3Dv4 Scenery Activation

Rotornut44

Resource contributor
Messages
658
Country
us-florida
[SOLVED]



Hello,
I know enough batch script to get me by in most cases, but lately I've had to start pulling information from the registry. My current knowledge of scripting just doesn't seem to suffice anymore.

A few weeks ago, I pieced together the following bit of code to check the version (if there is a version) of SODE installed on a users computer. So far it seems to be working flawlessly.

setlocal
set CheckVersion=1.5.1
for /f "tokens=3" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\12bPilot\SimObject Display Engine" /v Version ^| find /i "Version"') do set Version=%%a
if "%Version%"=="%CheckVersion%" (
goto movefiles
)




Today, I have attempted to use some of this code to pull a registry value for P3Dv4 in order to activate an Object Library after running it's installer. A snippet of the script follows:

reg query HKLM\Hardware\Description\System\CentralProcessor\0 | find /i "x86" > nul
if %errorlevel% == 1 goto systemx64

:systemx86
for /f "tokens=3" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Lockheed Martin\Prepar3D v4" /v SetupPath ^| find /i "SetupPath"') do set p3dPath=%%a
goto checkpath

:systemx64
for /f "tokens=3" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Lockheed Martin\Prepar3D v4" /v SetupPath ^| find /i "SetupPath"') do set p3dPath=%%a

:checkpath
if not exist "%p3dPath%Prepar3D.exe" goto abort
"%p3dPath%Prepar3D.exe" "-Configure: File=Scenery, Operation=Add, Path=Emerald Scenery Design/EOLv2, Title=EOLv2, Required=False, Active=True"



The script works as it should up until it jumps to :systemx64. From there it tells me that the system cannot find the specified registry key or value.


Any ideas? My best guess is that I'm doing something that the for command doesn't like. This is being tested under Windows 10.

Edit: I have also tried "tokens=1-2*" (This part is a bit confusing for me atm)
 
Last edited:
I have determined that I need to use either "tokens=3" or "tokens=3,*" in order for the FOR command to start reading from the correct part of the registry, however, my current dilemma is that the path I'm trying to pull from the registry has a space in it. The /f in the FOR command breaks the path at this space, cutting it off.

I need to figure out how to preserve this space in the path. I have been playing with "delims=" but no matter what I set it to, the batch immediately crashes when it reaches that line of script..


Edit: I (somehow) got it to work by reverting back to the original code that worked in Windows 7: (Even though this code didn't seem to work when I tried it this morning)

:systemx64
for /f "tokens=1-2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Lockheed Martin\Prepar3D v4" /v SetupPath ^| find /i "REG_SZ"') do set p3dPath=%%c

This code works when I run the file manually as administrator or not, but the second I allow my Installer to launch the Batch file, it immediately says it cant find the registry key.

What..? o_O


Edit#2:
I'm not even sure why I didn't think of this before, but I just came to the realization that I have no need to pull values from the registry when my batch file IS LOCATED IN THE P3DV4 DIRECTORY. :censored:

Prepar3D.exe "-Configure: File=Scenery, Operation=Add, Path=Emerald Scenery Design/EOLv2, Title=EOLv2, Required=False, Active=True"

Launching that code in a batch file from the main P3Dv4 directory worked wonders.

What a waste of a day. :(
 
Last edited:
Back
Top