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

Run as Administrator Bug #1

Closed
brandleesee opened this issue Dec 8, 2015 · 12 comments
Closed

Run as Administrator Bug #1

brandleesee opened this issue Dec 8, 2015 · 12 comments

Comments

@brandleesee
Copy link

Despite Right Clicking and Run-ning as Administrator, the dialog kept instructing me to actually right click and click on "Run as Administrator".

Work around:
Right click on .bat file, and remove the following code:

:: Make sure the script is running as admin
call :ensure_admin

Once the above step was done, the script worked perfectly.

@rossy
Copy link
Owner

rossy commented Dec 10, 2015

Which Windows version? What happens when you run net session in an elevated Command Prompt?

I'll try to find a better way to check for Administrator privileges. The current method is admittedly a bit of a hack.

@AeliusSaionji
Copy link

Requires powershell to be installed, but this will have the script elevate itself.

set script=%~f0
@powershell -command "Start-Process cmd.exe -ArgumentList \"/C %script%\"" -verb RunAs

@AeliusSaionji
Copy link

mpv dropped XP support and powershell is bundled with vista+ so this should be fine.

@brandleesee
Copy link
Author

Windows 7.
Truth be told, since after my little tweaking all worked fine, I kept the installation as is.
As a matter of fact it is still installed and has completely replaced MPC-HC.

With regards to power shell: since I am not conversant with its command line parameters and functions and furthermore no instructions were given to actually use that as an alternative, then I cannot see how I was supposed to know that I could use it for its better powers.

@AeliusSaionji
Copy link

I was speaking to rossy.

@brandleesee
Copy link
Author

I answered rossy and wrote a comment on your comments because after all
yours did not have a clear indication of address.

rossy added a commit that referenced this issue Dec 29, 2015
This might be more reliable, since apparently there are situations where
`net session` doesn't work.

Could help with #1.
@rossy
Copy link
Owner

rossy commented Dec 29, 2015

Well, I changed ensure_admin to do something slightly different. @brandleesee, could you test it on your system?

@Link-Satonaka, I originally avoided using PowerShell to elevate because I would have to test with all PowerShell versions and the logic wouldn't be easy, for example, if it failed to elevate, I didn't want it to get caught in an infinite loop. It's definitely a possibility if I can get that stuff figured out, though. I'll have a look at it.

@brandleesee
Copy link
Author

@rossy Worked perfectly, cheers!

@rossy
Copy link
Owner

rossy commented Dec 29, 2015

Thanks for testing!

@rossy rossy closed this as completed Dec 29, 2015
@garoto
Copy link

garoto commented Oct 28, 2016

In case anyone ever have the need and is reading this, here's another "check for admin rights" method:

"%windir%\system32\reg.exe" query "HKU\S-1-5-19" >nul 2>&1

Seems to work as intended, but not sure how far it goes regarding Windows versions.

(from "Burf's Visual C++ Redist Installer" .bat file).

@rossy
Copy link
Owner

rossy commented Nov 3, 2016

@garoto That's actually pretty neat. It seems to work because S-1-5-19 is the well known SID for the LOCAL SERVICE user, hence the key always exists and it's never readable by non-admins. It also has no dependencies other than reg.exe, which this script needs anyway. I might go for that method if/when the openfiles.exe method breaks.

@garoto
Copy link

garoto commented Nov 4, 2016

Glad you found it useful rossy. And thanks for explaining what that regkey actually means/does. I had no clue :)

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

No branches or pull requests

4 participants