Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Implement Run as Administrator in Project.

Joined
Feb 4, 2014
Messages
962
Reaction score
36
Hi guys, could someone help me or teach me how to put or what to put in my C++ project the function for Run as Administrator?

BTW I'm Using VS 2003 Only :)

Scenario, I made a program (.exe) but before running it must be set to Run as Administrator (in compatibility button), i just want to include the Run as Administrator in my EXE program so user will no need to SET it manually :)

Hope someone will help, thanks :)
 
[emoji848]
Legend
Joined
Dec 3, 2011
Messages
2,232
Reaction score
1,518
What you're searching for is called "UAC Execution Level". Applications can require windows to be invoked as someone else than the current user. Mostly that is as administrator or system. Such information is stored in the manifest file each application has.

I don't use VS 2003 but in VS 2012+ (any VS with property sheets) you can set this trigger in the Linker Options:

Maddox - Implement Run as Administrator in Project. - RaGEZONE Forums


A similar option should exist in VS 2003 :)
 
Joined
Feb 4, 2014
Messages
962
Reaction score
36
I use VS 2003 cause my source is made of it.

in VS 2003 it has no option about that Manifest File, i think its not yet included/plugin.

Thanks for response :)
 
[emoji848]
Legend
Joined
Dec 3, 2011
Messages
2,232
Reaction score
1,518
You should consider upgrading your source to an up-to-date VS version, specially if you target up-to-date operating systems. The auto update works quite well and you might have to fix smaller issues, but it's worth it.

As VS 2003 was released even before Windows Vista, where the typical User Account Control was introduced, this option might be not available in VS2003 or it has a different name. Iirc Windows XP had a "run as administrator" option as well. A google search didn't help much, but you should be looking for things that are manifest file related.

Possible Linker Flag: /MANIFESTUAC:level=requireAdministrator
How the entry in the manifest files should look like: <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

As VS 2003 targets XP I don't think there is anything that you can do apart from a runtime error message if the application is not executed as administrator.
 
Joined
Feb 4, 2014
Messages
962
Reaction score
36
About upgrading my source VS2003 to newer VS what was the possible disadvantage/s?


Hmmm just thinking to install VC9 but when i search i cant find install of VC9, it it exist?

Why VC9?- I just found other source made in VC9 but i need to modify it to transfer other code from my VC3.

is it VC9 has manifest file?

thanks.
 
[emoji848]
Legend
Joined
Dec 3, 2011
Messages
2,232
Reaction score
1,518
The biggest disadvantage is that you might have to apply small adjustments to meet later C++ standards (c++11,14,17). The huge advantage is that you have access to new features and API. Though I'm not an expert on that so don't take my word for granted. I upgraded a VC6 (Visual Studio 6, 1998) source to VS2013 and I had to change some WINAPI calls together with some scoping issues. That's it.

VC9 should be VS 2008 which does not have manifest UAC support yet, I think. According to MSDN documentation versions the manifest stuff starts with VS 2010, aka VC10. Source:

But why not go VS2015 in the first place? If you're already upgrading, why not to the latest version? I'd personally recommend either VS2013 or VS2015 at the moment. With those you can also be sure to use the options that I shared in my first reply.
 
Joined
Feb 4, 2014
Messages
962
Reaction score
36
I see so maybe ill try to upgrade my source to 2013 first, btw thanks for your reply, it helps a lot.

you can closed my topic now.

Thanks again and God Bless :)
 
Skilled Illusionist
Joined
Jan 8, 2012
Messages
332
Reaction score
149
Changing UAC Level in Visual Studio will not do it properly. Use the following function:


Code:
bool SetAdminPrivilege()
{
	HANDLE TokenHandle;

	if(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&TokenHandle) == 0)
	{
		return 0;
	}

	LUID luid;

	if(LookupPrivilegeValue(0,SE_DEBUG_NAME,&luid) == 0)
	{
		CloseHandle(TokenHandle);
		return 0;
	}

	TOKEN_PRIVILEGES tp;

	memset(&tp,0,sizeof(tp));

	tp.PrivilegeCount = 1;

	tp.Privileges[0].Luid = luid;

	tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

	if(AdjustTokenPrivileges(TokenHandle,0,&tp,sizeof(tp),0,0) == 0)
	{
		CloseHandle(TokenHandle);
		return 0;
	}

	CloseHandle(TokenHandle);
	return 1;
}

Code:
if(SetAdminPrivilege() == 0)
	{
		MessageBox(0,"Could not open program!","Error",MB_OK | MB_ICONERROR);
		return 0;
	}

Enjoy!
 
Back
Top