Click here to Skip to main content
15,881,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
How Would I Check if a program has or needs a "runas admin" permission during runtime? using vb9, VB10, or VB11 beta. Thanks in advance for any answers, or (directions to an article), that could possibly resolve this little problem.
Sergey Alexandrovich Kryukov 10-Mar-12 19:22pm    
Using the source code of the program in question, or not?

1 solution

I don't think you can do it automatically, even though some static code analysis algorithm could help. You just need to understand what causes permission problems and write code accordingly. Also, you can simply test the code without elevated privileges, but it can give you 100% guarantee, as with any testing, as it is not always possible to exhaust all possible cases in testing.

Share this answer
rspercy65 11-Mar-12 9:45am    
The code that I am using checks the user for elavated permission(aka: Admin). This is limiting it to a select few which I think is wrong. I want everybody to be able to use the program. For now they will just have to right click for Properties, click compatibility tab and check the "runas" checkbox.
Sergey Alexandrovich Kryukov 11-Mar-12 13:32pm    
Do I understand you right: you have a problem running code with regular, non-elevating permissions? In this case, you should find out where you have exceptions. It can be as simple as working with some directories not legal in Windows 7. You need to fix such problems. If you cannot locate such problems, you can test the code -- under debugger, or log some information in strategic points and of course catch all exception of top of stack if each thread and log comprehensive exception information. For UI, you should handle all exception in the top event cycle and also lock at the stage of investigation.
rspercy65 11-Mar-12 17:39pm    
The code that Im using only checks for "ADMINS" and nothing else. Basically I want the ("program to check itself") for elavated permission and not the user, then display a message to the user to do the "Right-Click" thing and then click compatibility tab and check the "runas" checkbox.

Sorry for the inconvenience. I am thinking of just telling them in my article that the program needs to be "runas admin". Thanks for your time and patience.
Sergey Alexandrovich Kryukov 12-Mar-12 12:08pm    
You are welcome.
Wait a second... why would you just check it and nothing else? I don't see the purpose.
Any of the results of the check would not mean that the program actually trying to do anything that would require elevated permissions, as your original question asks about.
rspercy65 12-Mar-12 15:24pm    
Right now my app is forcing the user to get admin rights. I think I'll leave it at that. I think that trying to have the application check itself would be kind of foolish when it is being done already by asking the user to get 'admin rights' before (He or She) can run the app.

Once again, Thanx very much for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900