2009-12-15 39 views
1

當我在朋友的Windows 7計算機上運行我的應用程序時,出現.NET安全錯誤。.NET Framework安全問題

下面是截圖

alt text http://img707.imageshack.us/img707/1340/94161244.png

,這裏是明顯的

<?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"> 
    <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> 

我怎樣才能在Visual Basic 2010解決這一問題?

感謝

編輯:我做了一個臨時的解決辦法是這樣

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 

編輯2:我也意識到,我的朋友的勝7是有點壞了,它甚至不加載SSL certf。的網頁。怪異

+0

請向我們展示詳細信息(也許它包含stracktrace?)。如果它包含堆棧跟蹤,請向我們顯示該位置的代碼。 – Heinzi

+0

我只是使用「RegistryKey」和「Application.CommonAppDataRegistry」它給出了錯誤,因爲註冊表訪問請求我猜 –

回答

1
+0

我讀過它,但沒有建立事件選項卡在Visual Basic 2010中,我不知道,其實我無法理解文本作爲vb初學者:)但我添加了清單信息到我的問題 –

+0

您需要右鍵單擊您的項目並選擇屬性;你會看到Build events標籤; (好吧,我有一個控制檯項目類型) –

+0

對不起,但真的沒有那個選項卡上的視覺基本2010 –

3

你需要從通用應用程序數據讀取註冊表

  • 如果你只需要閱讀:改變你的代碼,這樣你RegistryKey只需要只讀權限。

  • 如果您需要請寫:只有管理員可以寫入HKEY_LOCAL_MACHINE,這是常用應用程序駐留的地方。因此,你的應用程序需要管理權限,這就需要海拔在Windows Vista或7。在這一點上,你應該再做出決定:

    • 如果是非常重要的,這個數據用戶之間共享只有管​​理員才能使用您的軟件:確定您的應用程序是Right-mouse-button/Run as administrator或者按照Rubens的建議添加清單。

    • 如果可以存儲數據(每個用戶),請改爲使用Application.UserAppDataRegistry

0

您是否嘗試過增加對指定關鍵字的方法的安全性的需求,我認爲這會導致UAC如果需要一命嗚呼將Write屬性更改爲您正在訪問的任何鍵。或者將其添加到您的AssemblyInfo中。VB:

<Assembly: System.Security.Permissions.RegistryPermission(Security.Permissions.SecurityAction.RequestMinimum, ViewAndModify:="HKLM\Software")> 
+0

我應該添加到我正在訪問的功能? –

+0

您可以將第一個屬性添加到您調用的類或方法中,第二個屬性可以添加到AssemblyInfo.vb文件中(在解決方案資源管理器中,您需要單擊「顯示所有文件」)。 –

0

請更改,

此行

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

進入

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

在你的清單文件。