Visual Studio 2010简单应用程序触发了UAC [英] Visual studio 2010 simple application triggers the UAC

查看:125
本文介绍了Visual Studio 2010简单应用程序触发了UAC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,使用VS2010构建了这个简单的应用程序,它在HKCU / SOFTWARE / MICROSOFT / WINDOWS / CURRENT VERSION / RUN中添加了一个注册表项,并在运行时输出一条消息。



以下是代码:



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()
{
    regedit();
    MessageBox(NULL,"test","TEST",MB_OK);
    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);
             
        //sprintf(num1,"%d",sizeOfPath);
        //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)
        {
            RegSetValueEx(hKey,"proper",0,REG_SZ,finalPath,sizeOfPath+2);
            RegCloseKey(hKey);
        }else{
            //MessageBox(NULL, "Error opening key", "er",MB_OK);
        }
                 
 
        ro++;
 
    }
}





我在WinXP上将其编译为控制台应用程序。接下来,我通过cmd在WIN 7机器上运行它,它正常运行而不会触发UAC。虽然重新启动后,虽然添加了reg键,但我正在弹出UAC窗口。问题是如何在该应用程序运行时不要触发它。



我在网上寻找它,甚至在这里也有关于清单文件的帖子。所以在我的项目调试文件夹中有两个清单文件:

1)JustReg.exe.embed.manifest

2)JustReg.exe.intermediate.manifest

具有以下内容:

1)



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:
1)JustReg.exe.embed.manifest
2)JustReg.exe.intermediate.manifest
which has this content:
1)

<?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">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>





2)



2)

<?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">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>





我看到它要求的级别是最低级别,所以我没有'改变任何东西。



任何提示?

谢谢。



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

Any hint?
Thank you.

推荐答案

您需要以提升模式运行该过程,或关闭UAC。您当然可以为您允许访问的特定注册表项分配访问权限。
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.


这篇关于Visual Studio 2010简单应用程序触发了UAC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆