How to Keep My PowerShell Script Running Smoothly?

0
32
Asked By CuriousCat42 On

I'm handling a small sys-admin role at my business and have a task to record a voice signature during a web app session using a PowerShell script. The script checks for a specific title bar in Edge, records audio with ffmpeg, encrypts it with gnupg, and uploads it with curl. I've faced reliability issues: startup items crash, Task Scheduler often misses triggers, and multiple script instances spawn unexpectedly. The lid closing while recording seems to lead to the most problems. I'm considering whether creating a service is a better solution, but I'm not familiar with that. Any advice on improving the reliability of this process? Is NSSM safe to use with Windows 11?

5 Answers

Answered By DevFan72 On

Honestly, I think you're better off writing a small C# application. It’s more suited to long-running tasks compared to PowerShell. PowerShell's learning curve is gentler, but for this task, C# would be more dependable.

CuriousCat42 -

I’ll consider that, thanks for the tip! I want something that can handle these processes better.

Answered By CodeWiz88 On

I agree that making this function as a service would definitely help with stability. Crafting a simple C# service can run your script on startup and handle errors more gracefully. You could get the code structure from Github and modify it to fit your needs.

CuriousCat42 -

That sounds promising! Can a Windows service also access the WindowTitle from a user's process?

Answered By PowerShellPro On

You might try implementing a while loop in your script to keep it running. Just make sure to handle exceptions carefully and maybe include a slight delay to prevent crashes. It's messy, but it might maintain stability during lid openings.

CuriousCat42 -

I’ve been trying that, but sometimes it still crashes. Task Scheduler is inconsistent, which complicates things further.

Answered By SysAdmin101 On

Using NSSM can be a good option to turn your script into a service. Just keep in mind that while it hasn’t been maintained recently, many find it works fine on Windows 11 for handling background tasks without crashing.

CuriousCat42 -

Is it really safe to use NSSM? I’ve heard mixed reviews since it seems outdated.

Answered By TechGuru99 On

Have you thought about using a web solution instead? It seems like this task could be handled more reliably within the web app itself rather than relying on a script.

User229 -

Unfortunately, we can’t modify the carrier provided web app, which is why I need a script.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.