我的C# WPF应用程序可以在我的PC上运行,但不能在其他PC上运行?

piok6c0g  于 2022-11-18  发布在  C#
关注(0)|答案(2)|浏览(285)

我最近使用ClickOnce发布了我的C#应用程序。当我在使用windows 10的PC上运行我的应用程序时,它运行正常,但当我尝试使用安装了windows 10的另一台PC时,它无法打开。我尝试使用兼容性疑难解答,它为我推荐了win 8的设置,并在应用其推荐的设置后,我的应用程序在我的另一台电脑上运行正常。请告诉我为什么会发生这个问题?我知道当我们使用故障排除程序时它会解决,但我会分发这个应用程序,它会使用户很难手动打开它。我的源代码可在这里获得:https://github.com/Yuvaan17/KrakenZ_Tweaker
我已经检查了事件查看器,下面是调试详细信息-
下面是第一条错误消息:

at System.ThrowHelper.ThrowSecurityException(System.ExceptionResource)
   at Microsoft.Win32.RegistryKey.OpenSubKey(System.String, Boolean)
   at KrakenZ_Tweaker.UserControls.UserControl2.Disable_Xbox_Services_Checked(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs)
   at System.Windows.Controls.Primitives.ToggleButton.OnChecked(System.Windows.RoutedEventArgs)
   at System.Windows.Controls.Primitives.ToggleButton.OnIsCheckedChanged(System.Windows.DependencyObject, System.Windows.DependencyPropertyChangedEventArgs)
   at System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs)
   at System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs)
   at System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs)
   at System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex, System.Windows.DependencyProperty, System.Windows.PropertyMetadata, System.Windows.EffectiveValueEntry, System.Windows.EffectiveValueEntry ByRef, Boolean, Boolean, System.Windows.OperationType)
   at System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty, System.Object, System.Windows.PropertyMetadata, Boolean, Boolean, System.Windows.OperationType, Boolean)
   at System.Windows.Controls.Primitives.ToggleButton.set_IsChecked(System.Nullable`1<Boolean>)
   at KrakenZ_Tweaker.UserControls.UserControl2..ctor()
   at KrakenZ_Tweaker.MainWindow..ctor()

Exception Info: System.Reflection.TargetInvocationException
   at System.RuntimeTypeHandle.CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)
   at System.RuntimeType.CreateInstanceSlow(Boolean, Boolean, Boolean, System.Threading.StackCrawlMark ByRef)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean, Boolean, Boolean, System.Threading.StackCrawlMark ByRef)
   at System.Activator.CreateInstance(System.Type, Boolean)
   at System.RuntimeType.CreateInstanceImpl(System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, System.Object[], System.Threading.StackCrawlMark ByRef)
   at System.Activator.CreateInstance(System.Type, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, System.Object[])
   at System.Activator.CreateInstance(System.Type, System.Object[])
   at System.Xaml.Schema.SafeReflectionInvoker.CreateInstanceCritical(System.Type, System.Object[])
   at System.Xaml.Schema.SafeReflectionInvoker.CreateInstance(System.Type, System.Object[])
   at System.Xaml.Schema.XamlTypeInvoker.CreateInstance(System.Object[])
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(System.Xaml.XamlType, System.Object[])
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(System.Xaml.XamlType, System.Object[])
   at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(MS.Internal.Xaml.Context.ObjectWriterContext)
   at System.Xaml.XamlObjectWriter.WriteStartMember(System.Xaml.XamlMember)
   at System.Xaml.XamlWriter.WriteNode(System.Xaml.XamlReader)
   at System.Windows.Markup.WpfXamlLoader.TransformNodes(System.Xaml.XamlReader, System.Xaml.XamlObjectWriter, Boolean, Boolean, Boolean, System.Xaml.IXamlLineInfo, System.Xaml.IXamlLineInfoConsumer, MS.Internal.Xaml.Context.XamlContextStack`1<System.Windows.Markup.WpfXamlFrame>, System.Windows.Markup.IStyleConnector)
   at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)
   at System.Windows.Application.LoadComponent(System.Uri, Boolean)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1_0(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at KrakenZ_Tweaker.App.Main()

下面是第二条错误消息:

Faulting application name: KrakenZ Tweaker.exe, version: 1.0.0.0, time stamp: 0xb3f073bc
Faulting module name: KERNELBASE.dll, version: 10.0.19041.1288, time stamp: 0x3e55bd0b
Exception code: 0xe0434352
Fault offset: 0x0012b5b2
Faulting process id: 0x130
Faulting application start time: 0x01d8e3095e6e54e8
Faulting application path: C:\Users\nevat\AppData\Local\Apps\2.0\YW14JZH9.DZ8\WQ9TP99E.PRA\krak..tion_f4f8753dddbedea6_0001.0000_7a77a162166539c7\KrakenZ Tweaker.exe
Faulting module path: C:\Windows\System32\KERNELBASE.dll
Report Id: 9912415b-acac-4a3d-bedb-24d07417ebb2
Faulting package full name: 
Faulting package-relative application ID:

下面是第三个:

Fault bucket 2059872029189490063, type 5
Event Name: CLR20r3
Response: Not available
Cab Id: 0

Problem signature:
P1: KrakenZ Tweaker.exe
P2: 1.0.0.0
P3: de4d2f9f
P4: mscorlib
P5: 4.8.4515.0
P6: 624cf315
P7: 340
P8: 10
P9: N3CTRYE2KN3C34SGL4ZQYRBFTE4M13NB
P10: 

Attached files:
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WERCBE7.tmp.dmp
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WERCDFB.tmp.WERInternalMetadata.xml
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WERCE3A.tmp.xml

These files may be available here:
\\?\C:\ProgramData\Microsoft\Windows\WER\ReportArchive\AppCrash_KrakenZ Tweaker._829d1d36f9ea56e8517d64b3be67bf83e37261_780215cd_c5b1fb2f-51d2-4d41-b1b7-3ff3c56dfd8c

Analysis symbol: 
Rechecking for solution: 0
Report Id: 80bb5e81-84c9-4e03-b56a-a8e65a2a558c
Report Status: 268435456
Hashed bucket: c5259aa8925522deac9622b2669a458f
Cab Guid: 0
zpqajqem

zpqajqem1#

如果查看RegistryKey.OpenSubKey函数重载的the documentation,您会发现通过提供true作为参数,您试图以写权限打开它。您还将看到,如果您没有权限写入该键,它将抛出您所看到的SecurityException
由于您的代码只是阅读密钥,而不是尝试写入密钥,因此请尝试提供false作为参数。或者尝试查看其他重载。
此外,using statement还可以使您不必在注册表项对象上显式调用Dispose

**EDIT:**您说即使在此之后它也不工作。我假设您无法在任何客户机上调试。是这样吗?

如果是这样的话,你需要某种类型的日志来注销异常的文本。简单的事实是,你需要能够看到异常说了什么。如果你的应用程序中还没有某种类型的日志记录器,添加它。恐怕这只是调试101。除此之外,我没有任何帮助。
我重写了UserControl2类的第76到95行

  • 我放了一个using语句。这将为您调用Dispose
  • 我去掉了不必要的finally子句和dict2.Remove调用。
  • 我添加了一行来记录消息文本(带有注解“Something Like This”)

这是密码

foreach (var key in keys1)
{
    using var rkey = Registry.LocalMachine.OpenSubKey(key, false)
    {
        try
        {
            // If the GetValue call throws, nothing is added to "dict2"

            dict2.Add(key, Convert.ToUInt32(rkey.GetValue("Start", RegistryValueKind.DWord)));
        }
        catch (Exception ex)
        {
            Log.WriteLine(ex.Message()); // SOMETHING LIKE THIS
            dict2.Add(key, 0);
        }
    }
}
c2e8gylq

c2e8gylq2#

问题是我把CheckBox.IsChecked == true;放在InitializeComponent();的下面,我也为Checkbox设置了Checked和Unchecked的事件触发器,因此我得到了错误。为了解决这个问题,我为Checkbox设置了Click事件处理程序,而不是Checked和Unchecked。下面是我在'Click事件处理程序'中添加的内容:

private void Disable_Xbox_Services_Click(object sender, RoutedEventArgs e)
        {
            string[] keys = {
       @"SYSTEM\CurrentControlSet\Services\XblGameSave",
       @"SYSTEM\CurrentControlSet\Services\XboxNetApiSvc",
       @"SYSTEM\CurrentControlSet\Services\XboxGipSvc",
       @"SYSTEM\CurrentControlSet\Services\XblAuthManager",

                            };

            if (Disable_Xbox_Services.IsChecked==true)
            {
               

                foreach (string key in keys)
                {

                    try
                    {
                        RegistryKey newKey = Registry.LocalMachine.OpenSubKey(key, true);
                        newKey.SetValue("Start", 4, RegistryValueKind.DWord);
                    }
                    catch (Exception)
                    {
                    }

                }
            }
            else
            {
                foreach (string key in keys)
                {

                    try
                    {
                        RegistryKey newKey = Registry.LocalMachine.OpenSubKey(key, true);
                        newKey.SetValue("Start", 3, RegistryValueKind.DWord);
                    }
                    catch (Exception)
                    {
                    }
}

    }

相关问题