Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

c++ - Is it possible for the executable to ask for Administrator rights? (Windows 7)

I am developing a partition disk program, and for me to read the \\.\PhysicalDrive0 I need admin rights.

I am wondering if it is possible, in the run time, for the program to gain admin rights? Is there any win api for that?

I want to do that because I want the program to execute with admin rights only when it is reading/writing the disk. For security reasons, I don't want the program to execute all the time with admin rights, because someone could find a bug (stack or heap overflow for example) in some module and execute arbitrary commands as adm.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You cannot acquire elevated privileges after the process has started. Your options are:

  1. Put the part of your application that requires elevated privileges into a separate process and manifest that with requireAdministrator.
  2. Run the part of your application that requires elevated privileges as an out-of-proc COM object.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...