ajinzrathod
ajinzrathod

Reputation: 950

Check if app is running from startup in python

I have made an application in python named Swaminarayan.exe. I wanted my program to start when my PC boots. So I created a shortcut named Swaminarayan.lnk and added it to:

C:\Users\<Current User>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\

But my application behaves differently when the app is in AUTO_START and when Not in AUTO_START. How can I detect if my app is running from shortcut or not.

Can I do something like this?

if AUTO_START:
    // do this
else:
    // do that

Any help is appreciable. Thanks in advance :)

Upvotes: 1

Views: 643

Answers (1)

AKX
AKX

Reputation: 169124

Add a command line parameter to the startup shortcut (in its Properties box), e.g. --startup.

Then you can use e.g.

import sys
# ...
is_startup = ('--startup' in sys.argv)

or if your program grows and you end up using e.g. argparse:

import argparse
# ...
ap = argparse.ArgumentParser()
ap.add_argument('--startup', action='store_true', default=False)
args = ap.parse_args()
if args.startup: ...

Upvotes: 1

Related Questions