Hi there. I just wanted to show you a simple and easy way of how you can Elevate your program to Administrator rights (and still run with Userrights if the user denies it).
Needed Variables
Code Private identity As Principal.WindowsIdentity = Principal.WindowsIdentity.GetCurrent()
Private principal As Principal.WindowsPrincipal = New Principal.WindowsPrincipal(identity)
Private isElevated As Boolean = principal.IsInRole(Principal.WindowsBuiltInRole.Administrator)
Next we need our Elevate function. Then we have to check if the user is Admin and if not, restart our program with Administrator rights.
Code Sub ElevateAdmin()
Dim proc As New ProcessStartInfo
proc.UseShellExecute = True
proc.WorkingDirectory = CurrentDirectory
proc.FileName = Assembly.GetExecutingAssembly().Location
proc.Verb = "runas"
Try
Process.Start(proc)
Catch
Return
End Try
End Sub
if not iselevated then
ElevateAdmin()
end if
its worked. thank you so much... :)
What's the different to the IDE setting?
h t t p : / / s14.directupload .net/images/141108/ahhgavre .png
Hey can you explain how to use the code, where to put it. im using vb2010. take some screenshots please.
So much fail in the code.
Return in the catch block? why? lol
And why it's on a Try block ? Why not check if the file exists first? since it's running, it will exist...
Why put shellexecute = true when it's default?
Why you didn't use Application.ExecutablePath instead of reflection crap?
Why you didn't use Application.StartupPath instead of CurrentDirectory?
(Nov 8, 2014 01:55 PM)He B TeMy Wrote: So much fail in the code.
Return in the catch block? why? lol
And why it's on a Try block ? Why not check if the file exists first? since it's running, it will exist...
Why put shellexecute = true when it's default?
Why you didn't use Application.ExecutablePath instead of reflection crap?
Why you didn't use Application.StartupPath instead of CurrentDirectory?
Because this code is really really old and I just found it on my HardDrive. thought I could share it as it is nothing ub3r mega private but it's not posted here.
And the difference to the IDE Settings is just, that you can elevate on button press or just when you need it :)
DO NOT DEAL WITH THIS MEMBER
I haven't seen this posted before (since I've been a member anyway) so it's a pretty good share IMO. Thanks OP for this ;) I won't be needing it (I don't think anyway) but I'm sure other will benefit from it ;)
(Nov 8, 2014 04:26 PM)nuk Wrote: I haven't seen this posted before (since I've been a member anyway) so it's a pretty good share IMO. Thanks OP for this ;) I won't be needing it (I don't think anyway) but I'm sure other will benefit from it ;)
thanks for the kind words :)
That's why I post this kind of stuff
(Nov 8, 2014 04:13 PM)imi-tat0r Wrote: Because this code is really really old and I just found it on my HardDrive. thought I could share it as it is nothing ub3r mega private but it's not posted here.
And the difference to the IDE Settings is just, that you can elevate on button press or just when you need it :)
What IDE settings ? Do you even have a clue what the code does?
yes I do...
You can set
Code <requestedExecutionLevel level="asInvoker" uiAccess="false" />
to
Code <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
in the IDE which starts the program either in Standardmode (Usermode if UAC enabled) or as Administrator
with my code you can run your program in usermode and just elevate it to Administrator rights if you absolutely have to...
Why do you want to get with administrator rights if your application doesn't need to have them...?
I think it's quite useless and most likely drops the trust of your application.
for example a registry cleaner.
You do not need administrator rights to access HKCU. But if the user decides to clean his HKLM you can elevate your tool.
Easy as that. I just found this in a project I was working on ~2 years ago so I thought I would share this.
If you don't need it then don't use it. But there is absolutely no reason to trash this thread with stupid posts...
(Nov 9, 2014 11:40 AM)imi-tat0r Wrote: for example a registry cleaner.
You do not need administrator rights to access HKCU. But if the user decides to clean his HKLM you can elevate your tool.
Easy as that. I just found this in a project I was working on ~2 years ago so I thought I would share this.
If you don't need it then don't use it. But there is absolutely no reason to trash this thread with stupid posts...
I am not trashing this thread with a stupid post. I just don't see the use of it why you want to check it.
Why wouldn't you just let it open as admin, what can be the harm of that?
Just put a message: "To keep this tool 100% functional you need to run it with administrator rights"
I don't see why you want to switch it.....
this is an OPINION not a THREAD TRASHING COMMENT.
if you act like that, just don't post stuff at all.
if you ask for it you can get it....
(Nov 9, 2014 12:33 PM)hellomen Wrote: I am not trashing this thread with a stupid post. I just don't see the use of it why you want to check it.
Why wouldn't you just let it open as admin, what can be the harm of that?
Just put a message: "To keep this tool 100% functional you need to run it with administrator rights"
I don't see why you want to switch it.....
this is an OPINION not a THREAD TRASHING COMMENT.
if you act like that, just don't post stuff at all.
if you ask for it you can get it....
I was not talking about your post only..
You do not see a use of that. Some people might. So let them use it and if you do not need it do not post anything. Not that hard I guess oO
(Nov 9, 2014 01:07 PM)imi-tat0r Wrote: I was not talking about your post only..
You do not see a use of that. Some people might. So let them use it and if you do not need it do not post anything. Not that hard I guess oO
If I do not need it, I am still allowed to give criticism.
I am neither saying they aren't allowed to use it.
You let me think about me a few weeks/months ago, couldn't handle criticism and just started "raging" bitching it off me.
It doesn't get you good trust me....
|