-1

I am developing a very simple C# Windows Application (it only displays a message box saying "UACtest") that I want it to run at startup without prompting UAC.

For that I created a registry key for it under HKCU, and in the machine that I compiled it (Windows 8 64-bit using Visual Studio 2013) it runs at startup without promping UAC, as expected.

However, if I export the executable to a Windows 7 machine and do exactly the same thing, a UAC prompt is shown at startup.

Please note that the manifest of the executable has "asInvoker" on the "requestedExecutionLevel", the whole manifest is this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
   <security>
     <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
      <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
     </requestedPrivileges>
   </security>
 </trustInfo>
</assembly

Also when I directly double click the executable, it never prompts UAC neither on Windows 7 32-bit or in the Windows 8 64-bit, the UAC prompting problem is only at startup.

I also tried to compile the executable on the Windows 7 32-bit machine (to maybe bypass some compatibility issues) and a strange thing happened, in that machine now UAC is not prompted at startup as expected, however, when I make the test on another machine (Windows 7 64-bit under Virtual Box) it prompted UAC at startup.

This has now really puzzled me, can someone please tell me a way to compile it so that it never prompts UAC at startup on all versions of Windows?

The project properties I used on Visual Studio 2013 are the default ones, except: *Target framework: 2.0 *Platform target: x86

And the UAC settings on all machines where the default one: "Notify me only when applications try to make changes on my computer (default)"

JaneGoodall
  • 1,478
  • 2
  • 15
  • 22
samsam
  • 39
  • 1
  • 8

2 Answers2

0

Moving the executable has caused the destination system to mark the file as coming from a different system, and as a result the destination system will block execution at startup (in case the executable maliciously added itself to the startup).
Removing the block should fix the issue, it can however be avoided altogether if the executable is added to the system by an installer.
How to set up an installer is however a different question.

Jonas
  • 491
  • 6
  • 22
  • Removing what block? So for example if I want my program to be downloaded from my website, when executed is possible to add itself to HKCU and not trigger UAC everytime a customer restarts his machine? – samsam Apr 10 '14 at 00:57
  • Adding to the registry should be handled by an installer to avoid leaving behind unused keys when the user wishes to remove the program. About the block; if you view the properties of the executable on the destination system it should show it at the bottom of the window. – Jonas Apr 10 '14 at 01:04
  • Do you mean by right-clicking the executable and selecting "properties"? Or in Visual Basic's project properties? – samsam Apr 10 '14 at 01:11
  • I will try making an installer and post here if it triggers UAC. However, I am sure there most be a way to adding it to HKCU without an installer and not trigger UAC at startup, because for example I used this program called "Don'tSleep" as a test: http://www.tomsguide.com/us/download/Dont-Sleep,0301-28162.html and if I add it to HKCU, it never prompts UAC at startup neither on Windows 8 64-bt or Windows 7 32-bit, it's very strange... – samsam Apr 10 '14 at 01:27
  • The executable properties, not the project properties. It is very much possible to edit the registry using .Net, however it remains a different question and I will not recommend doing it. Adding a startup key is something that should be handled at installation time. – Jonas Apr 10 '14 at 08:44
0

The problem was the Zone Identifier, which was set to 3, as for all files downloaded from internet. If anyone else have this problem, just delete the Zone Identifier, for example with this tool:

http://jameskovacs.com/2005/04/11/zonestripper-updated/

And now the program should run at startup without prompting UAC.

samsam
  • 39
  • 1
  • 8