techahold/rustdeskinstall

using start-process instead of start

Closed this issue · 4 comments

CvH commented

I have to admit that I am far away from a skilled powershell user so maybe this isn't the best idea or I misunderstood the purpose :)

Currently it is used that way

Start "$env:ProgramFiles\RustDesk\RustDesk.exe" "--password $random_pass"

Start-Sleep -s 5

So rustdesk is started and a sleep guarding the process to hopefully finish before the 5secs are over.

Why not use Start-Process with -wait to wait till the process is finished ? So it really waits till the job is finished and avoids errors if it takes longer then the sleep.

Start-Process "$env:ProgramFiles\RustDesk\RustDesk.exe" -argumentlist "--password $random_pass" -wait
Start-Process "rustdesk-$restdesk_version-putes.exe" -argumentlist "--silent-install" -wait

I have had some varying results in the past with -wait at least with the sleep I know its doing what I want it to do, although it does mean on a fast machine it can take a while, I will do some testing on this, thanks :)

CvH commented

The problematic part is not that it takes a while, I had the case that 5sec sleep was not enough (HDD spin up ...) so the next command was started regardless if the other command finished or not.

From what I understand at PS "start" is not intended to get used in those cases at all.

I have a stripped down version of the script and I didn't saw any unwanted stuff from Start-Process, but like said

I am far away from a skilled powershell user

lol ok, ill do some tests and close this either way with the results of my tests.

tested and changed now