• 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.

How to get the path of installed P3D version via code from registry?

Messages
442
Country
malaysia
Hi,

I would like to get some info based on the code below. I wanted when running this script via .cmd, it will look for the registry of P3D installed on our pc and will copy the path and paste it to the red fonts in the codes below.
C:
@echo off
REM Batch Script for Prepar3D V4
REM Add the current Folder to the Addon Library (add-on.cfg)

set args=-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path=%cd%
call "C:\Lockheed Martin\Prepar3D v4\Prepar3D.exe" "%args%"

How can we do that?

Thank you.
 
try this as a start:

I don't know what you want as the args -> cd??

Code:
@echo off

rem Put registry entry for LM in tempFile
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Lockheed Martin\Prepar3D v4" /v SetupPath > tmpFile

REM Batch Script for Prepar3D V4
REM Add the current Folder to the Addon Library (add-on.cfg)
set args=-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path=%cd%
rem loops thru all three lines - last one is saved to LMHKLM
for /F "tokens=*" %%A in (tmpFile) do set LMHKLMtmp= %%A
rem echo %LMHKLMtmp%

Call :Display %LMHKLMtmp%

rem call P3D
rem call "C:\Lockheed Martin\Prepar3D v4\Prepar3D.exe" "%args%"
rem start "" "%LMHKLMtmp%Prepar3D.exe" "%args%"
start "" "%LMHKLMtmp%Prepar3D.exe"
set LMHKLMtmp=
del tmpFile
EXIT /B %ERRORLEVEL%

:Display
rem echo The value of parameter 1 is %1
rem echo The value of parameter 2 is %2
rem echo The value of parameter 3 is %3
rem echo The value of parameter 4 is %4
rem echo The value of parameter 5 is %5
rem echo The value of parameter 6 is %6

for /f "tokens=3*" %%A in ("%LMHKLMtmp%") do set LMHKLMtmp= %%A %%B
for /f "tokens=* delims= " %%a in ("%LMHKLMtmp%") do set LMHKLMtmp=%%a
echo %LMHKLMtmp%
EXIT /B 0
 
try this as a start:

I don't know what you want as the args -> cd??

Code:
@echo off

rem Put registry entry for LM in tempFile
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Lockheed Martin\Prepar3D v4" /v SetupPath > tmpFile

REM Batch Script for Prepar3D V4
REM Add the current Folder to the Addon Library (add-on.cfg)
set args=-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path=%cd%
rem loops thru all three lines - last one is saved to LMHKLM
for /F "tokens=*" %%A in (tmpFile) do set LMHKLMtmp= %%A
rem echo %LMHKLMtmp%

Call :Display %LMHKLMtmp%

rem call P3D
rem call "C:\Lockheed Martin\Prepar3D v4\Prepar3D.exe" "%args%"
rem start "" "%LMHKLMtmp%Prepar3D.exe" "%args%"
start "" "%LMHKLMtmp%Prepar3D.exe"
set LMHKLMtmp=
del tmpFile
EXIT /B %ERRORLEVEL%

:Display
rem echo The value of parameter 1 is %1
rem echo The value of parameter 2 is %2
rem echo The value of parameter 3 is %3
rem echo The value of parameter 4 is %4
rem echo The value of parameter 5 is %5
rem echo The value of parameter 6 is %6

for /f "tokens=3*" %%A in ("%LMHKLMtmp%") do set LMHKLMtmp= %%A %%B
for /f "tokens=* delims= " %%a in ("%LMHKLMtmp%") do set LMHKLMtmp=%%a
echo %LMHKLMtmp%
EXIT /B 0
Wow, thanks for the codes.

But, it is not adding the line into Addon Library. Another one, P3D starts just after running the batch file.

try this as a start:

I don't know what you want as the args -> cd??

I got 0 knowledge about this coding stuffs especially cmd batch codes.

I just need my scenery to be added automatically into the addon library. You may ask why am I doing so? I have all my scenery on my another drive (F). So, I wanted to run the scenery from the location itself without moving the addon.xml to the P3D addon default folder in C:\Users\Documents\Prepar3D v4 Add-ons. So, currently I need to change each path on the addon.xml file that match where I located my scenery. That's quite hard to do each and every time. So If I can get the code, it should be able to do it for me in just a click.

My 1st code in the theread above is working perfectly. Just that in case if I wanted to share my scenery to others (whom don't have any simple coding knowledge) they might have difficulty to change the path according to the location they saved the scenery. The location of P3D installed might get differ on each pc. So, I wanted the code to be able to retrieve the P3D path location automatically.

Therefore, without changing the whole code I written in the first thread, is that possible to just retrieve the file path of P3D from registry, change the path on the code and finally run the whole code so it will be added on the addon.cfg?
Code:
call "C:\Lockheed Martin\Prepar3D v4\Prepar3D.exe" "%args%"
 
Last edited:
Oh .... I thought you understood batch/cmd files.

the rem is a way to comment out (not allow the line to run)

so change

rem call P3D
rem call "C:\Lockheed Martin\Prepar3D v4\Prepar3D.exe" "%args%"
rem start "" "%LMHKLMtmp%Prepar3D.exe" "%args%"
start "" "%LMHKLMtmp%Prepar3D.exe"
to
rem call P3D
rem call "C:\Lockheed Martin\Prepar3D v4\Prepar3D.exe" "%args%"
start "" "%LMHKLMtmp%Prepar3D.exe" "%args%"
rem start "" "%LMHKLMtmp%Prepar3D.exe"


but path=%cd% I assume you have a set variable called cd somewhere. right?

so making this change should make your batch code work as it did. my code extracts the registry value folder name where P3D is
 
Oh .... I thought you understood batch/cmd files.

the rem is a way to comment out (not allow the line to run)
Hi Ron,

Thanks for the explanation. That gives me the rough idea how the codes work :)
so change

rem call P3D
rem call "C:\Lockheed Martin\Prepar3D v4\Prepar3D.exe" "%args%"
rem start "" "%LMHKLMtmp%Prepar3D.exe" "%args%"
start "" "%LMHKLMtmp%Prepar3D.exe"
to
rem call P3D
rem call "C:\Lockheed Martin\Prepar3D v4\Prepar3D.exe" "%args%"
start "" "%LMHKLMtmp%Prepar3D.exe" "%args%"
rem start "" "%LMHKLMtmp%Prepar3D.exe"

so making this change should make your batch code work as it did. my code extracts the registry value folder name where P3D is
Ah! Now the codes works as needed! Thank you very much!!!
but path=%cd% I assume you have a set variable called cd somewhere. right?
I have the addon.xml file on the same location where I locate this batch file. There is no any other variable than that in the codes. The whole code is the one I showed on the first thread up there.

Now, Is that possible we do the same to delete the inserted file path into the addon.cfg?
C:
@echo off

rem Put registry entry for LM in tempFile
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Lockheed Martin\Prepar3D v4" /v SetupPath > tmpFile

REM Batch Script for Prepar3D V4
REM Delete the current Folder from the Addon Library (add-on.cfg)
set args=-Configure: Category=Add-on Package, Operation=Del, FileLocation=ProgramData, Path=%cd%
rem loops thru all three lines - last one is saved to LMHKLM
for /F "tokens=*" %%A in (tmpFile) do set LMHKLMtmp= %%A
rem echo %LMHKLMtmp%call "REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Lockheed Martin\Prepar3D v4" /v SetupPath" "%args%"

Call :Display %LMHKLMtmp%

rem call P3D
rem call "C:\Lockheed Martin\Prepar3D v4\Prepar3D.exe" "%args%"
start "" "%LMHKLMtmp%Prepar3D.exe" "%args%"
rem start "" "%LMHKLMtmp%Prepar3D.exe"
set LMHKLMtmp=
del tmpFile
EXIT /B %ERRORLEVEL%

:Display
rem echo The value of parameter 1 is %1
rem echo The value of parameter 2 is %2
rem echo The value of parameter 3 is %3
rem echo The value of parameter 4 is %4
rem echo The value of parameter 5 is %5
rem echo The value of parameter 6 is %6

for /f "tokens=3*" %%A in ("%LMHKLMtmp%") do set LMHKLMtmp= %%A %%B
for /f "tokens=* delims= " %%a in ("%LMHKLMtmp%") do set LMHKLMtmp=%%a
echo %LMHKLMtmp%
EXIT /B 0
I have tried with the code above (changing the "Operation= Add" to Del or Delete or Erase) but it seems dont' work. It gives the following error:

1556509188151.png
 
The SDK says this about Operation:



This option specifies what task the content configuration system should perform.

  • Add
    This option will add a directory specified by the Path option to the Category option's associated configuration file. If the directory specified by Path already exists, then it is moved to the top. If the directory does not exist, then it is inserted with the highest priority.

  • Remove
    This option will remove the directory specified by the Path or title specified by the Title option to the Category option's associated configuration file. If the directory specified by Path does not exist, then nothing occurs.

  • Enable or Activate
    This option will set the active field to true on the entry whose directory is specified by the Path or whose friendly name is specified by Title.

  • Disable or Deactivate
    This option will set the active field to false on the entry whose directory is specified by the Path or whose friendly name is specified by Title.
 
The SDK says this about Operation:



This option specifies what task the content configuration system should perform.

  • Add
    This option will add a directory specified by the Path option to the Category option's associated configuration file. If the directory specified by Path already exists, then it is moved to the top. If the directory does not exist, then it is inserted with the highest priority.

  • Remove
    This option will remove the directory specified by the Path or title specified by the Title option to the Category option's associated configuration file. If the directory specified by Path does not exist, then nothing occurs.

  • Enable or Activate
    This option will set the active field to true on the entry whose directory is specified by the Path or whose friendly name is specified by Title.

  • Disable or Deactivate
    This option will set the active field to false on the entry whose directory is specified by the Path or whose friendly name is specified by Title.
Thank you very much!. Could you please share the link to that particular section on the online SDK?

Edit:
I manage to find out about it. The link is here:
http://www.prepar3d.com/SDKv4/sdk/add-ons/add-on_configuration_files.html#Options
 
Last edited:
Hi @ronh ,

Based on the above codes from SDK provided by @toprob, I was able to create the remove batch file. Thank you very much to both of you.

Now, is that possible to add both codes inside one batch file?

For example, it should work in this way:

1. If the addon is not added into the addon library before, then when we run the batch file, it will add the file path into addon library.
2. If it is already added, then it will remove the code from the addon library.
 
You can use an if statement

Code:
if  addon == ""
   set args=-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path=%cd%
else
   set args=-Configure: Category=Add-on Package, Operation=Del, FileLocation=ProgramData, Path=%cd%

this is not the real code just that you can set things or run things based on a condition.

You may want to read up on batch/cmd files
https://www.tutorialspoint.com/batch_script/

https://www.tutorialspoint.com/batch_script/batch_script_if_else_statement.htm
 
You can use an if statement

Code:
if  addon == ""
   set args=-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path=%cd%
else
   set args=-Configure: Category=Add-on Package, Operation=Del, FileLocation=ProgramData, Path=%cd%

this is not the real code just that you can set things or run things based on a condition.

You may want to read up on batch/cmd files
https://www.tutorialspoint.com/batch_script/

https://www.tutorialspoint.com/batch_script/batch_script_if_else_statement.htm
Thanks for the links and codes. Will try to find out about it.
 
Hi @ronh,

I have gone through the links you attached previously. Anyhow, I’m still confusing what should be the condition value on "" in the code you have provided?
Code:
if addon == ""
 
I guess you are trying to see if an addon is there or not.

so look for the folder for the addon - I assume %cd% will be there or not. I have not tested this.

Code:
If not exist %cd%
   set args=-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path=%cd%
else
   set args=-Configure: Category=Add-on Package, Operation=Del, FileLocation=ProgramData, Path=%cd%

buy why add if not there and delete if there?????
 
I guess you are trying to see if an addon is there or not.

so look for the folder for the addon - I assume %cd% will be there or not. I have not tested this.

Code:
If not exist %cd%
   set args=-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path=%cd%
else
   set args=-Configure: Category=Add-on Package, Operation=Del, FileLocation=ProgramData, Path=%cd%

buy why add if not there and delete if there?????
Hi @ronh ,

I tried your code, if the path exists in addon.cfg, it is removing it but when the path is not there, then it is not adding back the path when we re-run the batch file.
Code:
If not exist %cd%
   set args=-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path=%cd%
else
   set args=-Configure: Category=Add-on Package, Operation=Remove, FileLocation=ProgramData, Path=%cd%
start "" "%Dir%\Prepar3D.exe" "%args%"

Let me explain what the code should do when we run it. I have the addon.xml file on the same location where the batch file is located. So, when we run the batch file, it will look for the adon.xml and will set the path of the addon.xml location into the addon.cfg in C:\ProgramData\Lockheed Martin\Prepar3D v4. Let say if the path of the addon.xml is already written, then when we run the batch file, it will remove the path from the addon.cfg file.

This is just to avoid we move/delete the whole scenery files each time when we don't need the scenery to be loaded by the sim. If we need the scenery to be run again, we just need to run the batch file and the path will be added into the addon.cfg.
 
Not ignoring you, just not enough time to work on your issue. I've moved over to X-Plane and FlightGear mostly now.
 
Not ignoring you, just not enough time to work on your issue. I've moved over to X-Plane and FlightGear mostly now.
Is it? Thats ok. I suspect there are some small mistakes somewhere on the above code. But not sure what is that. If could find it, the code will work amazingly.
 
Getting closer,

but the remove part needs more work. Still not understanding your requirements. mine is an exe so I need to look for the exe within the add-on.cfg file not where the files are.

Code:
@echo off

rem Put registry entry for LM in tempFile
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Lockheed Martin\Prepar3D v4" /v SetupPath > tmpFile

rem Batch Script for Prepar3D V4
rem Add the current Folder to the Addon Library (add-on.cfg)
rem you need to add in the name of the exe or addon here
if exist "%cd%\add-on.xml" (
   set args=-Configure: Category=Add-on Package, Operation=Remove, FileLocation=ProgramData, Path=""%cd%""
) else (
   set args=-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path=""%cd%""
)
rem loops thru all three lines - last one is saved to LMHKLM
echo %args%
for /F "tokens=*" %%A in (tmpFile) do set LMHKLMtmp= %%A

Call :Display %LMHKLMtmp%

rem call P3D
start "" "%LMHKLMtmp%Prepar3D.exe" "%args%"
set LMHKLMtmp=
del tmpFile
EXIT /B %ERRORLEVEL%

:Display

for /f "tokens=3*" %%A in ("%LMHKLMtmp%") do set LMHKLMtmp= %%A %%B
for /f "tokens=* delims= " %%a in ("%LMHKLMtmp%") do set LMHKLMtmp=%%a
echo %LMHKLMtmp%
EXIT /B 0

double quotes are needed around "%cd%" due to the path may have spaces in it.
 
Here is another option. This checks the add-ons.cfg file for the path

Code:
@echo off

rem Put registry entry for LM in tempFile
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Lockheed Martin\Prepar3D v4" /v SetupPath > tmpFile

rem Batch Script for Prepar3D V4
rem Add the current Folder to the Addon Library (add-on.cfg)
rem you need to add in the name of the exe or addon here
rem if exist "%cd%\add-on.xml" (
rem   set args=-Configure: Category=Add-on Package, Operation=Remove, FileLocation=ProgramData, Path="%cd%"
rem ) else (
rem    set args=-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path="%cd%"
rem )

    find /c "%cd%" "C:\ProgramData\Lockheed Martin\Prepar3D v4\add-ons.cfg"
    if %errorlevel% equ 1 goto notfound
    echo found
    set args="-Configure: Category=Add-on Package, Operation=Remove, FileLocation=ProgramData, Path=%cd%"
    goto done
    :notfound
    echo notfound
    set args="-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path=%cd%"
    goto done
    :done
   
rem loops thru all three lines - last one is saved to LMHKLM
echo %args%
for /F "tokens=*" %%A in (tmpFile) do set LMHKLMtmp= %%A

Call :Display %LMHKLMtmp%

rem call P3D
start "" "%LMHKLMtmp%Prepar3D.exe" ""%args%""
set LMHKLMtmp=
del tmpFile
EXIT /B %ERRORLEVEL%

:Display

for /f "tokens=3*" %%A in ("%LMHKLMtmp%") do set LMHKLMtmp= %%A %%B
for /f "tokens=* delims= " %%a in ("%LMHKLMtmp%") do set LMHKLMtmp=%%a
rem echo %LMHKLMtmp%
EXIT /B 0

Also you mention scenery so the -configuration should be a category of Scenery not Add-on Package. Is this true?
 
double quotes are needed around "%cd%" due to the path may have spaces in it.
Thanks for the info.
Also you mention scenery so the -configuration should be a category of Scenery not Add-on Package. Is this true?
The -configuration can be "Add-on Package" because we are using addon.xml to insert the scenery into the sim.

Here is another option. This checks the add-ons.cfg file for the path

Code:
@echo off

rem Put registry entry for LM in tempFile
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Lockheed Martin\Prepar3D v4" /v SetupPath > tmpFile

rem Batch Script for Prepar3D V4
rem Add the current Folder to the Addon Library (add-on.cfg)
rem you need to add in the name of the exe or addon here
rem if exist "%cd%\add-on.xml" (
rem   set args=-Configure: Category=Add-on Package, Operation=Remove, FileLocation=ProgramData, Path="%cd%"
rem ) else (
rem    set args=-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path="%cd%"
rem )

    find /c "%cd%" "C:\ProgramData\Lockheed Martin\Prepar3D v4\add-ons.cfg"
    if %errorlevel% equ 1 goto notfound
    echo found
    set args="-Configure: Category=Add-on Package, Operation=Remove, FileLocation=ProgramData, Path=%cd%"
    goto done
    :notfound
    echo notfound
    set args="-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path=%cd%"
    goto done
    :done
 
rem loops thru all three lines - last one is saved to LMHKLM
echo %args%
for /F "tokens=*" %%A in (tmpFile) do set LMHKLMtmp= %%A

Call :Display %LMHKLMtmp%

rem call P3D
start "" "%LMHKLMtmp%Prepar3D.exe" ""%args%""
set LMHKLMtmp=
del tmpFile
EXIT /B %ERRORLEVEL%

:Display

for /f "tokens=3*" %%A in ("%LMHKLMtmp%") do set LMHKLMtmp= %%A %%B
for /f "tokens=* delims= " %%a in ("%LMHKLMtmp%") do set LMHKLMtmp=%%a
rem echo %LMHKLMtmp%
EXIT /B 0

Thanks for the codes. I think now I can make it work as I needed.

I have made some changes from your previous codes to find the registry and added the latest codes to add and remove from the addon.cfg file.

Code:
@Echo Off
REM Batch Script for Prepar3D V4
REM Search for the installation path of Prepar3D v4 in registry
If Defined PROCESSOR_ARCHITEW6432 (
    Start "" /D "%__CD__%" "%SystemRoot%\SysNative\cmd.exe" /C "%~f0"&Exit /B)
SetLocal EnableExtensions DisableDelayedExpansion
Set "Key=HKLM\SOFTWARE\Lockheed Martin\Prepar3D v4"
Set "Val=SetupPath"
Set "Dir="
For /F "Tokens=2*" %%A In ('Reg Query "%Key%" /V "%Val%" 2^>Nul'
)Do Set "Dir=%%~B"
If Not Defined Dir GoTo :EOF
If "%Dir:~-1%"=="\" Set "Dir=%Dir:~,-1%"

REM Add or Remove the current Folder To or From the Addon Library (add-on.cfg)
find /c "%cd%" "C:\ProgramData\Lockheed Martin\Prepar3D v4\add-ons.cfg"
if %errorlevel% equ 1 goto notfound
echo found
set args="-Configure: Category=Add-on Package, Operation=Remove, FileLocation=ProgramData, Path=%cd%"
goto done
:notfound
echo notfound
set args="-Configure: Category=Add-on Package, Operation=Add, FileLocation=ProgramData, Path=%cd%"
goto done
:done
start "" "%Dir%\Prepar3D.exe" "%args%"
Thank you very much for the help!
 
I'm not sure what you are trying to add, but you said:

I just need my scenery to be added automatically into the addon library. You may ask why am I doing so? I have all my scenery on my another drive (F). So, I wanted to run the scenery from the location itself without moving the addon.xml to the P3D addon default folder in C:\Users\Documents\Prepar3D v4 Add-ons.

So I would think you are adding scenery to the scenery.cfg file and the SDK says:

and

[Content] The following command will add an entry named My Scenery to the scenery configuration to use scenery inside C:\Program Files\My Company\My Scenery Product\data. (example only - you would put your F: drive path) The required option dictates that this item cannot be deleted from the Scenery Library UI.

Prepar3D.exe "-Configure: Category=Scenery, Operation=Add, Path=C:\Program Files\My Company\My Scenery Product\data, Title=My Scenery, Active=True"

An Add-on package would have an exe or dll, do you have a program to install?
 
The required option dictates that this item cannot be deleted from the Scenery Library UI.
This is the reason I did not use scenery as the category.

I don’t have exe or dll. I just have addon.xml where this option can be disabled via the addon manager inside the sim itself.
 
Back
Top