Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从代码隐藏中访问rstrui.exe?_C#_Wpf_Windows_Xaml_System Restore - Fatal编程技术网

C# 如何从代码隐藏中访问rstrui.exe?

C# 如何从代码隐藏中访问rstrui.exe?,c#,wpf,windows,xaml,system-restore,C#,Wpf,Windows,Xaml,System Restore,请告诉我如何从我的c#代码访问系统还原“rstrui.exe” 我尝试调用C:\Windows\System32\rstrui.exe; 但根本无法访问 我需要调用此函数将我的控件重定向到系统还原 谢谢……您可以使用以下属性访问C:\Windows\System32: Environment.SystemDirectory 可以使用以下方法运行可执行文件: Process.Start(Path.Combine(Environment.SystemDirectory, "rstrui.exe"

请告诉我如何从我的c#代码访问系统还原“rstrui.exe”

我尝试调用
C:\Windows\System32\rstrui.exe
; 但根本无法访问

我需要调用此函数将我的控件重定向到系统还原


谢谢……

您可以使用以下属性访问C:\Windows\System32:

Environment.SystemDirectory

可以使用以下方法运行可执行文件:

Process.Start(Path.Combine(Environment.SystemDirectory, "rstrui.exe"));

更新>>>

啊。。。现在我明白你的问题了

当从64位Windows 7和Vista(也可能是Windows 8)上的32位代码访问
System32
文件夹时,Windows“聪明地”将请求路径的该部分更改为
SysWow64
。这就是您可能出现“找不到路径”错误的原因。为了避免这种情况,您可以使用以下方法:

Process.Start(@"C:\Windows\SysNative\rstrui.exe");
更完整的答案可能是:

if (Environment.Is64BitProcess)
{
    Process.Start(Path.Combine(Environment.SystemDirectory, "rstrui.exe"));
}
else Process.Start("C:\\Windows\\sysnative\\rstrui.exe");

我在64位系统上运行这一切,但仍然没有任何功能。 所以我设法解决了这个问题:

IntPtr wow64Value = IntPtr.Zero;
        try
        {
            Wow64Interop.DisableWow64FSRedirection(ref wow64Value);
            ProcessStartInfo psi1 =
        new ProcessStartInfo("cmd.exe");

            psi1.UseShellExecute = false;
            psi1.RedirectStandardOutput = true;
            psi1.RedirectStandardInput = true;
            psi1.CreateNoWindow = true;
            psi1.Verb = "runas";


            Process ps1 = Process.Start(psi1);
            ps1.EnableRaisingEvents = true;
            StreamWriter inputWrite1 = ps1.StandardInput;

            // uses extra cheap logging facility
            inputWrite1.WriteLine("chcp 437");
            inputWrite1.WriteLine("rstrui.exe");
        }
        catch (Exception ex)
        {
            Console.WriteLine("Unabled to disable/enable WOW64 File System Redirection");
            Console.WriteLine(ex.Message);
        }
        finally
        {
            // 3. Let the Wow64FSRedirection with its initially state
            Wow64Interop.Wow64RevertWow64FsRedirection(wow64Value);
        }
要启用它,请执行以下操作:

public class Wow64Interop
    {
        const string Kernel32dll = "Kernel32.Dll";

        [DllImport(Kernel32dll, EntryPoint = "Wow64DisableWow64FsRedirection")]
        public static extern bool DisableWow64FSRedirection(ref IntPtr ptr);

        [DllImport(Kernel32dll, EntryPoint = "Wow64RevertWow64FsRedirection")]
        public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
    }

到目前为止,您尝试了什么确切的代码?您尝试了什么吗?是的,我可以通过这种方式调用系统备份和还原…它要求定义关键字Combine。我在回答中添加了一个新链接,用于
路径。Combine
。感谢您让我尝试此操作,但仍然无法访问rstrui.exe。它仅显示system32文件夹。否这是一个32位的windows 7,但问题是关键字combine没有被识别,像msconfig.exe这样的命令也不能从后面的代码执行。请告诉我WPF的代码。