2

I'd like to compile a program which simply kills a task after a previously executed program has quit. This doesn't work without admin privileges.

I'm aware that you can choose "Run program as administrator" from the compatibility tab in the properties of the executable, but if possible I'd like to avoid the necessarity of doing so when distributing the program.

I'm using GCC 4.8.1 on Windows 8.1 to compile.

Edit: About 5 years later I'd propably have gone with system("tskill <processname>") in this situation, since it doesn't require admin rights on user processes. Alternatively some hack using runas/vbscript.

McSebi
  • 129
  • 2
  • 11
  • 2
    Does it have anything to do with the process of compiling? You have to write _code_ that does it, to my mind. – ForceBru May 16 '16 at 17:07
  • Look at `runas` windows shell command. It's really not about `gcc`. – Eugene Sh. May 16 '16 at 17:10
  • I was asking if there was a possibility to add something to the code which tells GCC to make the executable require admin rights – McSebi May 16 '16 at 17:12
  • 2
    You can't write code that tells the compiler to give the application it's compiling administrator rights. Such rights are requested of and granted by the operating system. – lurker May 16 '16 at 17:16
  • Operating system is who allows/denies administrator rights to a program. So you have to pass through the "Run program as administrator" or there should be a trick to allow malware to be installed into your system. This is the reason of the "Run program as administrator" menu option. To make user think twice before doing possible damage to a system. – Luis Colorado May 17 '16 at 05:42

1 Answers1

3

It looks like this may have already been figured out - you might want to look here and see if any of this helps: Embed manifest file to require administrator execution level with mingw32

From what I can tell by reading that question, it seems that requiring administrator rights to open an application is not something you have to do in code, but instead involves the resources in the compiled executable. That is not something I am too familiar with, but it looks like the link I gave can get you started down the right path.

Community
  • 1
  • 1
Random Davis
  • 6,662
  • 4
  • 14
  • 24
  • 1
    Thanks, you're right. I was able to archieve it by simply adding a random resouce file. Don't ask me why this works, since it contain's nothing related to UAC but just the version number... – McSebi May 16 '16 at 17:33
  • 1
    Glad you solved it. So you didn't have to put the `` in the resource file? That's odd. If you gave more information on how you solved it, it might be more helpful to people in the future with the same question. Also, if you figured it out based on my answer I'd appreciate having my answer accepted. – Random Davis May 16 '16 at 17:55
  • I'm still not entirely sure why my program sometimes compiled with forced elevated execution level, but what you/the other poster suggested is working reliably. – McSebi May 20 '16 at 11:24