2014-01-22 31 views
0

這是下一步後 How to run wpf(c#) application by service account and integrated security奇怪的錯誤,而模仿其他用戶

我創建模擬成功,但我得到了一些非常奇怪的錯誤。

讓我解釋的情況:

  • 我的應用程序是WPF
  • 我有2個用戶,我的本地帳戶(localUser)和服務帳戶(saUser)。
  • 我使用Frame.Navigate()函數來顯示diferent模塊在我的框架
  • 我打開的應用程序與localuser,然後冒充saUser

當我localUser運行我的應用程序它工作正常(與本地管理員權限和沒有) 當我與saUser運行我的應用程序我得到這個錯誤,沒有mather,如果saUser是本地管理員或沒有,最有趣的事情是當我遇到錯誤Navigate(...)被稱爲2nd時間!,第一次正常工作... :)

Requested registry access is not allowed. 

stackTrace: 
    at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) 
    at System.Windows.Application.GetSystemSound(String soundName) 
    at System.Windows.Application.PlaySound(String soundName) 
    at System.Windows.Application.FireNavigating(NavigatingCancelEventArgs e, Boolean isInitialNavigation) 
    at System.Windows.Navigation.NavigationService.FireNavigating(Uri source, Object bp, Object navState, WebRequest request) 
    at System.Windows.Navigation.NavigationService.HandleNavigating(Uri source, Object content, Object navState, WebRequest newRequest, Boolean navigateOnSourceChanged) 
    at System.Windows.Navigation.NavigationService.Navigate(Uri source, Object navigationState, Boolean sandboxExternalContent, Boolean navigateOnSourceChanged) 
    at System.Windows.Navigation.NavigationService.Refresh() 
    at MyApp.MyNavigation.Navigate(Module modul, Boolean reverse) -> my function 

Guyz help,any suggestions?我不知道是怎麼回事...... 如果我是不夠清楚問我...

編輯: 我加入一些代碼,就像問,只是它很小的和平哪裏發生錯誤:

I have public static class for navigation 
MainWindow mainWin = Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is MainWindow) as MainWindow; 
current <- currentlly selected module 
mainFrame <- frame that is showing all pages 

// if current module if already selected refresh frame content 
if (current.Link == mainWin.mainFrame.NavigationService.CurrentSource.ToString()) mainWin.mainFrame.Refresh(); 
// else show page content in frame 
else mainWin.mainFrame.NavigationService.Navigate(new Uri(current.acLink, UriKind.Relative)); 

刷新()和導航()發生錯誤。

+0

請問您可以發表一些代碼嗎?使用Windows註冊表時,通常會發生該錯誤... – Gonzix

+2

爲什麼模擬系統用戶來運行GUI?看起來這個帳戶沒有一些基本的權限來讀取註冊表(可能是正確的)。您應該使用系統帳戶進行​​一些後臺工作,系統服務等,並且僅在您確實需要時才使用。 – Grzenio

+0

是的錯誤提示我在訪問註冊表時出現錯誤,但是這兩個帳戶都是本地管理員,因此他們可以完全訪問註冊表,甚至更多,即使不是本地管理員,我的localUser也能正常工作。 – lanicor

回答

0

我面臨同樣的問題。有沒有解決這個問題的方法? 有an article related to how to access HKCU reg key,但它適用於我們擁有的代碼&不適用於WPF,因爲它的代碼是由Microsoft擁有的。

[編輯] 我的看法是,如果WPF用戶控件/窗口被初始化爲模擬之前再後來就模擬後沒有關於它們會創造多少次的問題;沒有錯誤拋出。這可以作爲解決方法嗎?

+0

我認爲這可以用作解決方法。 –