Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WinUtil's self-elevation when running windev.ps1 without administrator #2800

Closed

Conversation

Cryostrixx
Copy link
Contributor

@Cryostrixx Cryostrixx commented Sep 22, 2024

Contributor Note

I decided to close this PR because, after waiting a significant period without any feedback or review, it became clear that my contributions weren't valued. Seeing other PRs prioritized over mine reinforced this feeling, and I’ve chosen to step away from contributing. I hope the review process improves to be more inclusive of all contributors, regardless of their contributor status.
PR status: Permanently closed and won't be reopened. Reason: The head repository has been deleted and won't be restored.

Type of Change

  • New feature
  • Bug fix
  • Documentation update
  • Refactoring
  • Hotfix
  • Security patch
  • UI/UX improvement

Description

Problem

WinUtil Dev currently doesn't launch correctly when run as a non-elevated user.
The following error occurs when running irm https://christitus.com/windev | iex without elevation:
WinUtil Dev Launch Issue

Changes

Summary

  • Updated windev.ps1 to use Invoke-RestMethod <url> -OutFile <file_path> instead of using Invoke-RestMethod directly.
  • Updated windev.ps1 to use Start-Process instead of Invoke-Expression when launching the downloaded WinUtil script.
  • Updated windev.ps1 to no longer re-download WinUtil every time; now it only re-downloads when releases are modified.

Testing

I conducted thorough testing using both local execution and remote execution.
For remote execution, I used npm's http-server package to serve the script's directory with the following command:
http-server -p 4300 -c-1 C:\Users\#####\NoSync\Projects\Cryostrixx\forks\winutil\.staging\fix-windev-admin-elevation.

Results

Local Execution

Command: .\windev.ps1
Result: WinUtil launches successfully with no errors.
WinUtil Local Command Test - Without Arguments

Command: .\windev.ps1 -Config "C:\Users\#####\Documents\Configs\winutil.json"
Result: WinUtil launches successfully and imports my config with no errors.
WinUtil Local Command Test - With Arguments

Remote Execution

Command: iex "& { $(irm http://127.0.0.1:4300/windev.ps1) }":
Result: WinUtil launches successfully with no errors.
WinUtil Remote Command Test - Without Arguments

Command: iex "& { $(irm http://127.0.0.1:4300/windev.ps1) } -Config 'C:\Users\#####\Documents\Configs\winutil.json'"
Result: WinUtil launches successfully and imports my config with no errors.
WinUtil Remote Command Test - With Arguments

Impact

  • Revised the synopsis at the top of the script to clarify the changes made and provide basic usage examples.
  • Implemented the Get-WinUtilReleaseTag function to return the latest matching tag for WinUtil.
    • Supports both stable and pre-release tags, falling back to the latest tag when no releases are found.
  • Implemented the Get-WinUtilReleaseURL function to return the download URL for the latest release of WinUtil.
    • Supports stable and pre-release URLs, and uses the latest release URL when no releases are found.
  • Implemented the Get-LatestWinUtil function to download WinUtil to winutil.ps1 in the $env:TEMP directory.
  • Implemented the Get-WinUtilUpdates function for updates, ensuring WinUtil is only re-downloaded when modified:
    • Supports upgrading WinUtil if the version of the remote script is newer than the version of the downloaded script.
    • Supports downgrading WinUtil if the version of the remote script is older than the version of the downloaded script.
  • Implemented the Start-LatestWinUtil function for smoother launching of WinUtil using the appropriate process:
    • Windows PowerShell/PowerShell Core running in Windows Terminal.
    • Windows PowerShell/PowerShell Core running as a standalone app.
  • Corrected the argument support to allow passing the arguments -Run, -Config, and -Debug correctly.

Issues related to PR

Additional Information

None.

Checklist

  • My code adheres to the project's coding and style guidelines.
  • I have performed a self-review of my own code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no errors/warnings/merge conflicts.

Copy link
Contributor

@momcilovicluka momcilovicluka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello there @Cryostrixx ! 😊Nice work.
I left you a couple of suggestions to take into consideration.

windev.ps1 Outdated Show resolved Hide resolved
windev.ps1 Outdated Show resolved Hide resolved
windev.ps1 Outdated Show resolved Hide resolved
@Cryostrixx
Copy link
Contributor Author

Hello, @momcilovicluka! Thank you for the feedback! I wanted to let you know that I plan to retain a small amount of my original comments and code, but I’m currently working on adding your suggestions to the script.

@Cryostrixx Cryostrixx marked this pull request as draft September 23, 2024 17:50
@Cryostrixx
Copy link
Contributor Author

Cryostrixx commented Sep 23, 2024

Hello, @momcilovicluka! I implemented your changes, thanks so much for the feedback!
I've requested another review so you can take a look and verify that they are implemented correctly.

@Cryostrixx Cryostrixx marked this pull request as ready for review September 23, 2024 18:22
Copy link
Contributor

@momcilovicluka momcilovicluka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Good work and fast response. I tested running it with config and run argumetns and it is working. Also tested with old version and without winutil.ps1 in temp, and i saw no problems. Only thing i couldn't test is if pre-release is being detected correctly due to there being no pre-releases hosted.
Other tnan that, LGTM! 😊

windev.ps1 Show resolved Hide resolved
windev.ps1 Outdated Show resolved Hide resolved
@Cryostrixx Cryostrixx changed the title Fix windev.ps1 self-elevation logic and refactor code Fix windev.ps1 admin elevation logic and refactor the code Sep 24, 2024
@Cryostrixx Cryostrixx changed the title Fix windev.ps1 admin elevation logic and refactor the code Fix windev.ps1: Self-elevate with administrator permissions Sep 24, 2024
@Cryostrixx Cryostrixx changed the title Fix windev.ps1: Self-elevate with administrator permissions Fix windev.ps1 self-elevation when running script without administrator Sep 24, 2024
@Cryostrixx Cryostrixx changed the title Fix windev.ps1 self-elevation when running script without administrator Fix WinUtil's self-elevation when running windev.ps1 without administrator Sep 24, 2024
@Cryostrixx
Copy link
Contributor Author

Cryostrixx commented Sep 24, 2024

Hello, @momcilovicluka! I've finalized the PR with four out of the five changes you suggested. If the changes look good to you, could you please approve them? I've really appreciated all of your feedback so far and want to make sure everything is correct.
Note: If you don't know how to approve it all you have to do is click Approve instead of Comment when reviewing the changes.
I hope this helps!

@momcilovicluka
Copy link
Contributor

Hi @Cryostrixx 👋. Thank you for the kind words, you are really wholesome. I turned of the pc for the day as it's nighttime in my timezone, but I'll make sure to review first thing in the morning. I assume you already tested the changes in different ways to ensure everything is working correctly, so you can work on something else in the meantime. I'll review in about 8 hours.

@Cryostrixx
Copy link
Contributor Author

Cryostrixx commented Sep 24, 2024

Hi @Cryostrixx 👋. Thank you for the kind words, you are really wholesome. I turned of the pc for the day as it's nighttime in my timezone, but I'll make sure to review first thing in the morning. I assume you already tested the changes in different ways to ensure everything is working correctly, so you can work on something else in the meantime. I'll review in about 8 hours.

You're correct, I did that testing during development, I had to simulate the pre-release condition for the testing but considering the rest of the functionality was tested and verified as working it's safe to say pre-releases would work as well.

windev.ps1 Outdated Show resolved Hide resolved
Copy link
Contributor

@momcilovicluka momcilovicluka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I just tested it for safety sake and it seems to be working fine. Given that you already tested it thoroughly and i have no complaints about the code, you implemented everything very well.

LGTM!

@Cryostrixx Cryostrixx changed the title Fix WinUtil's self-elevation when running windev.ps1 without administrator Fix WinUtil Dev's self-elevation when running windev.ps1 without administrator Sep 25, 2024
@Cryostrixx Cryostrixx changed the title Fix WinUtil Dev's self-elevation when running windev.ps1 without administrator Fix WinUtil's self-elevation when running windev.ps1 without administrator Sep 25, 2024
@Cryostrixx Cryostrixx closed this Sep 29, 2024
@Cryostrixx Cryostrixx deleted the fix-windev-admin-elevation branch September 29, 2024 02:29
@Cryostrixx Cryostrixx restored the fix-windev-admin-elevation branch September 29, 2024 19:07
@Cryostrixx Cryostrixx deleted the fix-windev-admin-elevation branch September 29, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not loading Dev
3 participants