tags:

views:

141

answers:

3

Hi

when i run my application on my friend's win 7 os, i get .Net security error.

here is a screenshot

alt text

and here is manifest

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  <assemblyIdentity version="1.0.0.0" name="Myapp.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the 
            requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            If you want to utilize File and Registry Virtualization for backward 
            compatibility then delete the requestedExecutionLevel node.
        -->
        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>

How can i fix this in visual basic 2010 ?

thanks

EDIT: i made a temporary fix like this

    Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup

            Dim a As New WindowsPrincipal(WindowsIdentity.GetCurrent())
            If Not a.IsInRole(WindowsBuiltInRole.Administrator) Then
                MsgBox("Please Run the application as administrator")
                e.Cancel = True
            End If

End Sub

EDIT 2: i also realized that my friend's win 7 is kinda broken cuz it does not even load SSL certf. of the web pages. weird :

+1  A: 

Please, take a look here: Demand UAC elevation for an application by adding a manifest using mt.exe

Rubens Farias
i read it but there is no Build events tab in visual basic 2010, i dont know, actually i couldn't understand that text as a vb beginner :) but i added manifest info to my question
Ahmet vardar
You need to right-click your project and select Properties; There you'll see Build events tab; (well, I have one with a console project type)
Rubens Farias
sorry but really there is no that tab on properties in visual basic 2010
Ahmet vardar
just saw that... but what about that UAC button on Application tab?
Rubens Farias
+3  A: 

Do you need to write or read from the common appdata registry?

  • If you only need to read: Change your code such that your RegistryKey only requires read-only permissions.

  • If you need to write: Only administrators can write to HKEY_LOCAL_MACHINE, which is where the common appdata resides. Thus, your application will require administrative permissions, which requires elevation in Windows Vista or 7. At this point, you should again make a decision:

    • If it is really important that this data is shared between users and it's OK that only admins can use your software: Start your application with Right-mouse-button/Run as administrator or add a manifest as suggested by Rubens.

    • If it's OK for the data to be stored per user, use Application.UserAppDataRegistry instead.

Heinzi
A: 

Have you tried adding a security demand on the method for the specified key, I think this causes UAC to kick in if needed. Change the Write attribute to whatever key you're accessing.

    <System.Security.Permissions.RegistryPermission(Security.Permissions.SecurityAction.Demand, Write:="HKLM\Software")> _
Private Shared Sub Bob()

End Sub

Or adding this to your AssemblyInfo.vb:

<Assembly: System.Security.Permissions.RegistryPermission(Security.Permissions.SecurityAction.RequestMinimum, ViewAndModify:="HKLM\Software")>
Chris Haas
should i add this to the function where i am accessing ?
Ahmet vardar
You can add the first attribute to the class or method that you're calling, the second you can add to the AssemblyInfo.vb file (in the solution explorer you'll need to click "Show All Files").
Chris Haas