locked
ATL Project in VS2010 RC - how should I run VS2010.

    Question

  • In order to build an ATL project (EXE) successfully I'm finding I have to start VS2010 RC with 'Run as administrator'.  This is needed to perform the post build '/RegServer' step.  If I run normally I get the error -2147024891 which is 'Access is denied. ' (0x80070005).

    I'm running in Windows 7 using the Visual Studio 2010 Release Candidate and a simple project which I had previously created using Visual Studio 2005 under Windows XP (SP3) with no problems.

    Should I expect to have to run Visual Studio 2010 using 'Run as administrator' with Windows 7 and would this be different if I installed VS2010 on Windows XP?

    Tuesday, February 16, 2010 9:13 AM

Answers

  • Yes, I am able to repro your problem. It looks like instead of /RegServerRedirect, we should use /RegServerPerUser instead. We will look into fix this for RTM. For the time being, you can disable register output, and add the following to Post Build Event:

     "$(TargetPath)" /RegServerPerUser

    This should help you work around the registration issue in non-admin mode for exe application.

    Thank you for using the beta product!

    Li Shao, MSFT

     


    Li Shao
    • Marked as answer by Dunx Monday, February 22, 2010 9:18 AM
    Friday, February 19, 2010 7:24 PM

All replies

  • Starting from Windows Vista, including Vista, Win2008 Server, Windows7, build process cannot write to HKEY_CLASSES_ROOT (HKCR) hives unless the process is started as administrator. To be able to register in non-administrator mode, VS2008 and VS2010 offer the feature of "registrer per user". The registration information is written to HKEY_CURRENT_USER (HKCU).

    You can set Linker -> General -> Per User ReDirections to "true" if Linker -> General -> Register Output is set to "true if you use the built registration step of the project system.

    If you have your own custom registration step, you can use the per user registration command: regsvr32 /s /n /i:user "xxxx.dll".

    If VS2010 is installed on Windows XP, you don't need to have the elevated privilege or per user registration to register your application since the security requirement is OS specific.


    Li Shao, MSFT
    Li Shao
    Tuesday, February 16, 2010 7:09 PM
  • Starting from Windows Vista, including Vista, Win2008 Server, Windows7, build process cannot write to HKEY_CLASSES_ROOT (HKCR) hives unless the process is started as administrator. To be able to register in non-administrator mode, VS2008 and VS2010 offer the feature of "registrer per user". The registration information is written to HKEY_CURRENT_USER (HKCU).

    You can set Linker -> General -> Per User ReDirections to "true" if Linker -> General -> Register Output is set to "true if you use the built registration step of the project system.

    If you have your own custom registration step, you can use the per user registration command: regsvr32 /s /n /i:user "xxxx.dll".

    If VS2010 is installed on Windows XP, you don't need to have the elevated privilege or per user registration to register your application since the security requirement is OS specific.


    Li Shao, MSFT
    Li Shao


    This does not work for an EXE project.

    For the moment I have changed the Build Events, Post-Build event in the EXE project from trying to register the exe to a message saying that the project has not been registered along with how to register it i.e.

    Command Line:
    echo "$(TargetPath)" HAS NOT BEEN REGISTERED
    echo %(Message)
    echo "$(TargetFileName)" /RegServer

    Description:
    How to register (run as administrator)


    However, the suggestion does work for an ATL COM DLL project which will tell you some of the same anyway: "error MSB8011: Failed to register output. Please try enabling Per-user Redirection or register the component from a command prompt with elevated permissions."

    Wednesday, February 17, 2010 9:43 AM
  • Thanks for the additional information.

    Yes, it looks like there is problem with registration for ATL Exe application in non-admin mode that are created in VS2010. The problem is actually caused by an extra Post Build Event for registering the exe. You should remove the command: "$(TargetPath)" /RegServer from the post build event or set "Use in Build" to false. That should take care of the registration in admin problem.

    The registration for the exe application is already built into the build process. The registration command that the build is using for registration in non-admin mode is: "$(TargetPath)" /RegServerRedirect.

    Li Shao, MSFT
    Li Shao
    Wednesday, February 17, 2010 6:44 PM
  • Thanks for the additional information.

    Yes, it looks like there is problem with registration for ATL Exe application in non-admin mode that are created in VS2010. The problem is actually caused by an extra Post Build Event for registering the exe. You should remove the command: "$(TargetPath)" /RegServer from the post build event or set "Use in Build" to false. That should take care of the registration in admin problem.

    The registration for the exe application is already built into the build process. The registration command that the build is using for registration in non-admin mode is: "$(TargetPath)" /RegServerRedirect.

    Li Shao, MSFT
    Li Shao
    Sorry, I think i'm missing something important about this suggestion.  I've set 'Use in Build' to false so that the Post-Build event does not happen, however as far as I can tell the ATL COM Exe is then never registered.  I don't understand anything about the final paragraph ('The registration for the exe ... /RegServerRedirect') - where is '$(TargetPath)" /RegServerRedirect' in the build process? what is /RegServerRedirect meant to do exactly?

    Thursday, February 18, 2010 1:39 PM
  • I should have mentioned that you need to set Linker -> General -> Register Output to "true" and Linker -> General -> Register Per User to "true". "Register Output" is not enabled by default for exe applications. To be able to register as non-admin on Vista and above OS, register per user needs to be set to "true". This is what you will see in the log once these settings are enabled:

    1>Target "RegisterOutput" in file "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets" from project "c:\Users\lishao\documents\visual studio 2010\Projects\atlexe\atlexe\atlexe.vcxproj" (target "BuildLink" depends on it):
    1>Task "Exec" skipped, due to false condition; ('$(ConfigurationType)'=='DynamicLibrary' and '%(Link.RegisterOutput)'=='true' and '%(Link.PerUserRedirection)'!='true') was evaluated as ('Application'=='DynamicLibrary' and 'true'=='true' and 'true'!='true').
    1>Task "Exec" skipped, due to false condition; ('$(ConfigurationType)'=='DynamicLibrary' and '%(Link.RegisterOutput)'=='true' and '%(Link.PerUserRedirection)'=='true') was evaluated as ('Application'=='DynamicLibrary' and 'true'=='true' and 'true'=='true').
    1>Task "Exec" skipped, due to false condition; ('$(ConfigurationType)'=='Application' and '%(Link.RegisterOutput)'=='true' and '%(Link.PerUserRedirection)'!='true') was evaluated as ('Application'=='Application' and 'true'=='true' and 'true'!='true').
    1>Using "Exec" task from assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
    1>Task "Exec"
    1>  "c:\foo\Debug\atlexe.exe" /RegServerRedirect
    1>Done executing task "Exec".

    Li Shao, MSFT


    Li Shao
    Thursday, February 18, 2010 6:03 PM
  • I've done everything suggested and now it appears to hang on the /RegServerRedirect stage.  If I use Task Manager to kill my COM EXE process I get warning MSB3073 about the /RegServerRedirect stage returning 1.  I waited several minutes before using Task Manager to kill the process. 

    I've also tried a very simple ATL project, the only change I make from just using default settings is changing to an EXE.  I add an ATL Simple Object and then one method, all of this done using the wizard.  This also fails in the same way i.e. appears to hang when it tries to do /RegServerRedirect.  Is there something else I have to do before /RegServerRedirect will work?
    Friday, February 19, 2010 3:22 PM
  • Yes, I am able to repro your problem. It looks like instead of /RegServerRedirect, we should use /RegServerPerUser instead. We will look into fix this for RTM. For the time being, you can disable register output, and add the following to Post Build Event:

     "$(TargetPath)" /RegServerPerUser

    This should help you work around the registration issue in non-admin mode for exe application.

    Thank you for using the beta product!

    Li Shao, MSFT

     


    Li Shao
    • Marked as answer by Dunx Monday, February 22, 2010 9:18 AM
    Friday, February 19, 2010 7:24 PM
  • I can confirm that changing the Build Events, Post-Build Event to "$(TargetPath)" /RegServerPerUser works for my ATL COM Exe project.  In Linker, General I had both Register Output and Per-user Redirection set to 'No'.

    Monday, February 22, 2010 9:17 AM
  • Just so let you know this issue is not fixed in the final release. So you have to use this workaround for VS2010.

    Li Shao, MSFT


    Li Shao
    Tuesday, June 15, 2010 10:15 PM