-3

okay~ i have searched for this question ,but the ans always solved C++ or C#

i want to fopen ("C:\\myfile.txt","w"); it will permission denied . how can i compile a C program can run as admin without any manual setting? i'm using wxDEV-C++ 7.4.2. any ideas ?

/* fopen example */
#include <stdio.h>
int main ()
{
  FILE * pFile;
  pFile = fopen ("C:\\myfile.txt","w");
  if (pFile!=NULL)
  {
    fputs ("fopen example",pFile);
    fclose (pFile);
  }
  return 0;
}

first , thx lurker fixed my poor English title . its a big help.

sec, what i mean is a program can trigger UAC pop out ,then user can just give a single click to agree to run as admin,so user won't need to right click run as admin.

thx SoronelHaetir had solve my question .

郭維倫
  • 39
  • 6

2 Answers2

2

If you want your program to run as admin without needing to do the right click and select run as administrator you will need to embed a manifest that tells the OS to run your program with administrator credentials. This will still pop up the UAC window asking the user if they want to allow the program to run.

You can read about the application manifest format at https://msdn.microsoft.com/en-us/library/aa374191(v=vs.85).aspx

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
1

This is simply not possible without being a hacker and utilizing weaknesses in the OS. The whole point of permission handling is that a program should not be able to decide that it should be run as admin.

klutt
  • 30,332
  • 17
  • 55
  • 95