This question is not as simple as telling me to use runas; Please read the question before answering.
When I use C on UNIX/Linux and want to write a program to run with elevated privilege, I use this flow:
- program starts.
- process lowers privilege using setuid().
- process does unprivileged work.
- process raises privilege using setuid().
- process does privileged work such as opening a restricted file.
- process lowers privilege using setuid().
The critical part of the flow is that the process lowers its privilege immediately after starting and only raises its privilege long enough to do the corresponding work.
How can I do a similar thing on Windows using Java?
My specific use case is that I want to read and write protected files such that the only way for the user of the program to access the files is thru my Java program. I do not want to run the entire process with Administrator privilege just to protect a couple of files.