r/learnpython • • Dec 24 '24

How to run a .exe daily?

Hello, all! Recently I have forgotten to fill my clock in in my job, so that I came up with the idea of developing a automatic clock-in/clock-out system in Python which is not that hard. I could use the Task Scheduler, however, I do not want to donwload Pycharm or any IDE on my company's device. The solution I have is to convert .py to a .exe, but how could I use Windows Task Scheduler with a .exe considering the code must have images to work?

0 Upvotes

28 comments sorted by

29

u/ninhaomah Dec 24 '24

You need not have any IDE to run .py program.

"how could I use Windows Task Scheduler with a .exe considering the code must have images to work" <-- ? If Task Scheduler can't run .exe then we are doomed.

1

u/Diasdasemana Dec 28 '24

Lol you are right, but it turns out a I was using Pyautogui library to find images, the .exe alone could not handle that. I have just given up since it was too much work for something that could be easily solved by an alarm.

28

u/rednerrusreven Dec 24 '24

Not to be that guy, but that will get you fired. How can they know? If you're clocking in and out at the same time every day. What if you randomize it by 15 minutes? Works until you're on PTO and forget to turn it off and clock in and out on your company computer while being gone.

Unless you're work is cool with this (which I assume it's not since you don't even want them to know you have Python.) this is a risky solution to your problem.

Also, I'm not an expert on Windows, but your work system may prevent you from running .exe files that don't have a proper certificate. So you may not even be able to run your file.

But other than that, good luck and keep us posted.

3

u/Diasdasemana Dec 28 '24

Wow! I really had not thought of that. That would be really risky indeed, as u/The-Mathematician said, I have given up, it was much more complex than it should be just to do something that could be easily solved by an alarm. Thank you so much for your response!

13

u/The-Mathematician Dec 25 '24

Agreed. In my opinion, you're better off putting an alarm on your phone or putting a 1 minute meeting on Outlook to remind yourself.

2

u/rotatingvillain Dec 25 '24

You have missed the i in "be able to ruin your life".

1

u/Cainga Dec 25 '24

You could add some logic at the start to skip the program if on weekends, holidays and vacations.

3

u/stahkh Dec 25 '24

If anybody finds out, which is trivial unless you really make an effort to make this fool proof (which will take you considerably more time than just clocking in manually for a few lifetimes), you will no doubt get fired as it will be considered cheating your employer. There will be strong belief that your made this not to get rid of mundane chore but to lie about working hours.

1

u/Diasdasemana Dec 28 '24

Indeed, I do not think that would cause any problem since I don't exacly fill the hours I am in and out, but that would be risky anyway. Thank you for telling me!

5

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 Dec 24 '24

but how could I use Windows Task Scheduler with a .exe considering the code must have images to work?

Easy; it should just work as-is.

In practice it depends on where the program looks for the images, but it shouldn't matter where they are, you can configure Task Scheduler to run it, and either hardcode where your program looks for the images (presumably they're somewhere near the program) or you can implement command-line arguments and let Task Scheduler set the location.

1

u/General-Jaguar-8164 Dec 24 '24

What do you mean with “the code must have images to work”?

-4

u/Diasdasemana Dec 24 '24

I am using pyautogui library and I am using images of the page for the arrow (mouse) to find it and click on it. Without these images the program can no longer find where to click. I am trying to solve it by using coordenates, but have no idea id it will work.

4

u/unhott Dec 25 '24

Coordinates will be bad. Someone can accidentally make the application not full screen, or it may open slightly offset from the last use, or the browser zoom level may change.

If you use selenium and/or beautiful soup, you may be able to come up with something more robust, but that can add challenges to development.

Make sure whatever you're doing doesn't get you into trouble.

1

u/Diasdasemana Dec 28 '24

Yep, it happened just as you said. I spent more time than I am proud of trying to find the exact positions for each element, when I ran the program in my company's device, it turned out to be all messed up because the screen is smaller.

5

u/Rustysporkman Dec 24 '24

Website scraping should let you directly identify interactable elements without having to mess with their position on the screen. Maybe look into that?

1

u/Agitated-Soft7434 Dec 25 '24

Selenium would definitely be a good way to control the browser in this case.

1

u/stiicky py me a river Dec 25 '24

I did something similar a long time ago but using powershelI

basically the script could open an instance of IE, then use the element IDs to select and fill in the login credentials, click on buttons to clock in, etc.. also ran on a scheduler

It was pretty easy and worked like a charm...not sure if the same would word in Edge tho

5

u/vilette Dec 24 '24

do not shutdown the computer

2

u/shinitakunai Dec 25 '24

Python can be portable. Just use the script on that.

3

u/cmcau Dec 24 '24

I run a few Python scripts - some hourly, some daily. Just on a Linode VM with all the required libraries and crontab to schedule the execution.

1

u/Puma_202020 Dec 25 '24

With Pyinstaller, you can use --onefile and it will package everything into a single EXE.

1

u/unnamed_one1 Dec 25 '24

Transfer that .exe to another computer and it will trigger (corporate) antivirus software as long as you don't sign it.

1

u/PMMeUrHopesNDreams Dec 25 '24

Instead of a .exe could you write a batch file or powershell script that launches your Python script and have task scheduler run that?

1

u/HydraDragonAntivirus Dec 25 '24

You can use cx_freeze if you need convert .exe

1

u/[deleted] Dec 25 '24

So you're asking for help, on reddit, to fashion an exploit that relies on compromising the security of a system to which you do not have admin permission, in order to manipulate records solely to your own personal advantage?!

Don't even let me know how that works out.

1

u/ElYummi Dec 25 '24

I have something like that for automatic file saving. You need to create a .bat file which would tun the python scrip (it is like a scrip for cmd commands and very easy you can find how to do it on google) and then use the Windows task programmer so that it runs the .bat file everyday. Again, the details are not complicated and can find it easily on google