1

Is it possible to check whether QGIS3 was started by executing qgis.bat or qgis.exe directly?

I want to do some checks in the qgis.bat before qgis starts and make sure that qgis is always started by calling the qgis.bat.

Edit1:

One idea is to set an environment variable in the qgis bat and check in the startup.py if this environmental variable is found:

bat-file:

set batchfilestart="YES"

python part

import os
try:  
    env_value = os.environ.get("batchfilestart")
    if env_value !="YES":
        print ("QGIS not started by calling the bat file")
        print (env_value)
    else:
        print("QGIS started by calling the bat file")
        print (env_value)
except KeyError: 
    print("Not exist environment value for %s" % "key_maybe_not_exist")

Is there a better way to make sure I can always run some checks before QGIS starts?

7
  • 1
    How about to add just a line with pause into qgis.bat? Then if you will see a message Press any key to continue . . . if you have launched the .bat file. Or rename qgis-bin.exe into foo.exe and edit the qgis.bat accordingly. At least for me foo.exe does not start at all but edited qgis.bat works. I was testing with the QSGeo4W installation.
    – user30184
    Commented Apr 29, 2019 at 13:59
  • @user30184: each user can pin qgis.exe to the taskbar or just run it manually. It's about rolling out QGIS for several persons where I want to make sure that all of them start QGIS3 only with the qgis.bat
    – Thomas B
    Commented Apr 30, 2019 at 6:48
  • Did you try renaming qgis-bin.exe into foo.exe? It seems that the renamed exe tries to find c:\osgeo4w\bin\foo.env which does not exist and Oops, looks like an error loading QGIS follows.
    – user30184
    Commented Apr 30, 2019 at 7:41
  • @user30184: renaming qgis-bin.exe or qgis-bin.env so they don't match anymore works to prevent calling qgis.exe directly but I am not sure if then really no neccessary settings get lost
    – Thomas B
    Commented May 2, 2019 at 6:39
  • 1
    Maybe you're aiming for something similar as gis.stackexchange.com/a/319225/51574, then.
    – das-g
    Commented May 6, 2019 at 11:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.