Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: Need to give admin rights to session 1 exe

30 May 2011   #1
praveen yadav

Windows 7 Ultimate x64
Need to give admin rights to session 1 exe

Need to give admin rights to session 1 exe so that this exe can create new files and registry.

i have used the below code to launch an application in session 1(ex: abc.exe) from session 0(ex:Myapp.exe).
I wish to give admin priveleges to abc.exe as this exe in-turn creates a file in C:\. But its failing to create a new file in C:\ as it is returning an ACCESS_DENIED Error, as it doesnt have the admin rights.

void ExecuteProc(DWORD sessionId)
HANDLE hToken, hProcess, hPToken, hUserTokenDup;
HDESK hdesk = NULL;
HWINSTA hwinsta = NULL, hwinstaSave = NULL;
BOOL bResult = FALSE;
sessionId = WTSGetActiveConsoleSessionId();
BOOL bQuery = false;
bQuery = WTSQueryUserToken(sessionId, &hToken) ;
DWORD dwErr1;
// Initialize the STARTUPINFO structure.
// Specify that the process runs in the interactive desktop.
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb= sizeof(STARTUPINFO);
si.lpDesktop = TEXT("winsta0\\default");
LUID luid;
if (!LookupPrivilegeValue(NULL,SE_DEBUG_NAME,&luid))
printf("Lookup Privilege value Error: %u\n",GetLastError());
tp.PrivilegeCount =1;
tp.Privileges[0].Luid =luid;
tp.Privileges[0].Attributes =SE_PRIVILEGE_ENABLED;
int dup = GetLastError();
//Adjust Token privilege
SetTokenInformation(hUserTokenDup, TokenSessionId,(void*)sessionId,sizeof(DWORD));
if (!AdjustTokenPrivileges(hUserTokenDup,FALSE,&tp,sizeof(TOKEN_PRIVILEGES),(PTOKEN_PRIVILEGES)NULL,NULL))
int abc =GetLastError();
printf("Adjust Privilege value Error: %u\n",GetLastError());
if (GetLastError()== ERROR_NOT_ALL_ASSIGNED)
printf("Token does not have the provilege\n");
// Launch the process in the client's logon session.
wchar_t lpCommandLine[] = L"C:\\abc.exe";
bResult = CreateProcessAsUser(
hUserTokenDup, // client's access token
NULL, // file to execute
lpCommandLine, // command line
NULL, // pointer to process SECURITY_ATTRIBUTES
NULL, // pointer to thread SECURITY_ATTRIBUTES
FALSE, // handles are not inheritable
NULL, // pointer to new environment block 
NULL, // name of current directory 
&si, // pointer to STARTUPINFO structure
&pi // receives information about new process
int _tmain(int argc, _TCHAR* argv[])
DWORD sessionId = 0;
return 0;

NOTE: abc.exe tries to create a new file in C:\ but it failed to do so as it require admin rights.
please give your valuabe inputs.

My System SpecsSystem Spec
30 May 2011   #2

Windows 7 Ultimate x64

I think this will help:

Run as Administrator
  1. Right-click on the exe in Windows Explorer, go to Properties.
  2. On the Compatibility tab, tick the checkbox at the bottom that says "Run this program as an administrator".
  3. Click OK, then try running it. It should bring up the UAC prompt.
Hope that helps a bit, at least...
My System SpecsSystem Spec

 Need to give admin rights to session 1 exe

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar help and support threads
Thread Forum
"Unable to elevate to admin rights" error, when admin user
I am trying to download Adobe Digital Editions and I keep receiving the error message Unable to elevate to administrative rights, error 786 I am the admin! I have turned off the password, I have right clicked on the program and chosen 'run as admin'-then nothing happens. Any help would be...
admin user lost some admin rights
I can't delete a file from the desktop. When I try, it says to get the rights from the specified admin user (which I'm logged on). The strange thing is that I still can create other users from this account (including admins). Any suggestion on what to do?
BSOD Help and Support
admin rights..
ok im getting sick of this. I've got dozens of folders on my PC that i cant delete because apparently i need admin privileges (even tho i am admin). Even if i switch user to the dedicated hidden admin account it still tells me i dont have the rights to delete stuff from MY OWN COMPUTER. It's...
Performance & Maintenance
Admin rights and .exe
My school has taken away are admin rights and we can't download .exe's. I thought maybe there was a way to convert a .exe I searched around but all the program to download but I needed admin rights. Please tell me a way to download the .exe's or convert them to .zip's.
General Discussion
Admin Rights
Hello Just installed Win 7 and using it for the first time, my user account has been crested as an admin but i am trying to edit the hosts file in system32/drivers and it will not allow me to save the edited version stating that it need administrator permission. like i said i am very new to...
General Discussion
How to give Adminstrative Rights to standard user ?
Hi All, For some reason i need to give adminstrative rights to Standard User in Windows 7.How can i do that ? As of now standard user can access all the programs but when he runs IIS it asks for admin password. Any help will be appreciated . Thank You
Network & Sharing

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 23:10.

Twitter Facebook Google+

Windows 7 Forums

Seven Forums Android App Seven Forums IOS App