asheroto / winget-install

Install winget tool using PowerShell! Prerequisites automatically installed. Works on Windows 10/11 and Server 2019/2022.
https://bit.ly/winget-install
GNU General Public License v3.0
272 stars 33 forks source link

Added prompt to reinstall winget when it is already present #42

Closed darchap closed 4 months ago

darchap commented 4 months ago

I've updated the if statement to check if winget is already installed. Users can still initiate the script with the "-Force" argument, or choose to reinstall winget directly without relaunching the script. Additionally, I've incorporated a do-while loop and converted the user input to lowercase to ensure that the input is always correct.

image image

darchap commented 4 months ago

At first glance I would suggest to add a countdown and if the user does not provide any input in lets say 5 seconds, the script will terminate.

Nevertheless I'm not quite sure if that approach will meet the requirement you mentioned above "If you could find a way to ask to reinstall but not pause script execution"

asheroto commented 4 months ago

Agreed, temporarily pausing script execution with a countdown as you mentioned is fine, we just don't want to pause it indefinitely. 😊 Not sure if that's possible though.

darchap commented 4 months ago

Yeah I need to figure out how to implement that, but I will try anyways. Thanks!!

darchap commented 4 months ago

I’ve managed to get it working. The only way I found was by creating an auxiliary function called Wait-ForKeyPress, which I think the name explains itself. I didn't know where to place this aux function, so it is above the original "if" statement, feel free to move it if you accept this PR in the end. I've also changed the version to 4.0.6 if you don't mind.

So, with all these modifications, if winget is installed and no -Force parameter detected, the script will terminate unless the 'y' key is pressed. I’ve added a 15-second timeout so that people who are executing this for the first time can read the warning and press the key before it terminates.

image image

asheroto commented 4 months ago

Thanks for working on this, but I've decided not to implement it.

The goal of PowerShell scripts is to minimize user interaction. Previously I had implemented an automatic Wait at the end of the script, and received many complaints from administrators describing how it impeded work flow because it delayed the time in which the script executed. When combined with other scripts, every second adds up.

As mentioned before, if this script were used solely by single-user environments, I could see how this would be advantageous and would implement it. But since the majority of users are systems Administrators who run the script without user interaction, this would delay script timing.