How to determine if a Python script is being run right after startupon Windows

R

Ryan George

Hello!

I'm a newbie to Python (literally just started last Saturday), and I
coded a program that selects a random wallpaper from a directory and
swaps it with your current one (Windows only.)

What I'm looking to do is have it start up with Windows and
automatically swap the wallpapers. This part I have already coded, and
as far as I know, it should work. However, I want the user to be able
to access the GUI after this initial running of the program. The way
it is set up now, enabling "Start Up Mode" will cause the program to
cycle the wallpapers and then immediately exit.

My question is this: is there any way I can determine if the program
is being run directly after a startup on a Windows machine?

Thanks,
Ryan
 
S

Steven D'Aprano

My question is this: is there any way I can determine if the program is
being run directly after a startup on a Windows machine?

How would you, a human being, determine if the program was being run
directly after startup?

What counts as "directly"? Within 10 seconds? Before any other program
with a GUI? Before *any* other program, including background processes?
Before the Windows desktop loads?

You also said:

"What I'm looking to do is have it start up with Windows and
automatically swap the wallpapers. This part I have already coded, and
as far as I know, it should work."

As far as you know, it SHOULD work? How about trying it and finding out?

In any case, it sounds to me that what you need is two programs, one
which automatically sets the wallpaper at startup, and a second that is a
GUI.
 
R

Ryan George

Hello Stephen,

Thanks for the prompt response!
How would you, a human being, determine if the program was being run directly after startup?

I'm not going to claim that I am a computer systems expert; I don't
know a whole lot about what goes on in the Windows start up. I know
services and programs are started, Internet connections are made, and
connections to devices on your computer are tested. However, these are
all things that could happen at any time (programs: obviously;
Internet could disconnect; unplugging or plugging in a mouse, for
example). That's why I came here. Maybe someone knew something I
didn't.

I know you're trying to get me to come to my own conclusion of my own
accord, but I have been attacking this problem for 8 hours. If the
answer was within my knowledge, I believe would have discovered it by
now.
What counts as "directly"? Within 10 seconds? Before any other program with a GUI? Before *any* other program, including background processes? Before the Windows desktop loads?

Maybe I should have made my purpose clearer. What I want the program
to do is perform its normal function (ie: swap your wallpaper with a
random one from a given directory) automatically after Windows
completely starts up, and then exit so as not to remain in memory.
With this new information, the answer to all of these questions should
be obvious. Since it depends on calls to the Windows API, this program
should be one of the last things to start, if not THE last thing.
As far as you know, it SHOULD work? How about trying it and finding out?
Again, I probably should have been clearer. This functionality DOES
work. The program will swap the wallpapers, then exit. The only thing
I haven't tested is if it will work at start up, which would have
required a reboot of my computer, something I really didn't want to
have to do. I was in the process of coding other, more critical
features with around 20 different tabs opened in Firefox, as well as
participating communications with someone who was designing a logo for
me.

I will be testing it next time I boot my computer.
In any case, it sounds to me that what you need is two programs, one which automatically sets the wallpaper at startup, and a second that is a GUI.

Yes, that is an option. However, my previous wallpaper cycler was able
to do what I am describing without two separate programs and I have
just discovered how. It was a switch on the executable that isn't
present when you try to run the program normally. This was probably
the first thing I should have looked into and I don't know why I did
not.

As long as I can pass variables through a command line when executing
a Python script, I see no reason why this shouldn't work. This
technically isn't the system letting the program know that it is
running after a start up, but rather a user telling a program that "I
am running you after a start up." Little bit of a different approach,
but hey, whatever works right?
 
D

Dennis Verdonschot

Hi Ryan,

Maybe I'm missing something, but wouldn't creating a shortcut and
putting that shortcut in your Start - Programs - Startup section of
the Windows menu not work for this program? Or if really needed you
can edit the start-up programs in the registry.

If you add some logging ability to your program you can verify it has
been run and you can still use commandline arguments by changing the
shortcut.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top