Click here to Skip to main content
15,905,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, have build that simple app with VS2010 which adds a registry key in HKCU/SOFTWARE/MICROSOFT/WINDOWS/CURRENT VERSION/RUN and prints a message when it runs.

Here is the code :

#include "stdafx.h"
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <winbase.h>
void regedit();
int main()
    return 0;
void regedit()
LPCTSTR regPathRun = TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
int ro, sizeOfPath;
char buffer[300];
HKEY hKey;
char *appPath;
char finalPath[200];
    ro = 0;
    if(ro == 0)
        /* Get current Directory.*/
        sizeOfPath = GetModuleFileName(NULL,buffer,300);
        //MessageBox(NULL, num1, "sizeOfPath",MB_OK);
        appPath = buffer;
        //MessageBox(NULL, appPath, "appPath",MB_OK);
        //sprintf(num2,"%d", sizeof(appPath));
        //MessageBox(NULL, num2 , "size of appPath",MB_OK);
        _snprintf(finalPath, sizeOfPath+2, "\"%s\"", appPath);
        finalPath[sizeOfPath+2] = '\0';
        //MessageBox(NULL, finalPath , "finalPath",MB_OK);
        //sprintf(num3,"%d", sizeof(finalPath));
        //MessageBox(NULL, num3 , "size of finalPath",MB_OK);
        /* Create registry keys for startup*/
        /* For HKEY CURENT USER*/
        if(RegOpenKeyEx(HKEY_CURRENT_USER,regPathRun,0,KEY_ALL_ACCESS,&hKey) == ERROR_SUCCESS)
            //MessageBox(NULL, "Error opening key", "er",MB_OK);

i compile it as a console application on a WinXP. Next, i ran it on a WIN 7 machine through cmd and it runs properly without trigger the UAC. Although after a restart , while the reg key has been added, i'm getting UAC window popped up. The question is how can i make it not to be triggered when that app is going to run.

I look for it on the net and even here there are posts that talk about the manifest file. So in my projects debug folder there are two manifest files:
which has this content:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level='asInvoker' uiAccess='false' />

I saw that the level that it asks is the most lower level, so i didn't change anything.

Any hint?
Thank you.
Jochen Arndt 22-Jan-15 4:55am    
This might not be the source of your problem but should be observed:


A program run from any of these keys (Run, RunOnce; added) should not write to the key during its execution because this will interfere with the execution of other programs registered under the key.

1 solution

You need to run the process in elevated mode, or turn off UAC. You can of course assign access rights to your specific registry key that allows you access.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900