90%的时间我无法osk.exe从32位进程启动Win7 x64.最初代码只是使用:
Process.Launch("osk.exe");
Run Code Online (Sandbox Code Playgroud)
由于目录虚拟化,这对x64无效.不是我想的问题,我只是禁用虚拟化,启动应用程序,然后再次启用它,我认为这是正确的做事方式.我还添加了一些代码,如果它已经被最小化(这可以正常工作)使键盘恢复 - 代码(在示例WPF应用程序中)现在看起来如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;using System.Diagnostics;
using System.Runtime.InteropServices;
namespace KeyboardTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
private …Run Code Online (Sandbox Code Playgroud) 当我尝试从我的C#应用程序运行BCDEDIT时,我收到以下错误:
'bcdedit'未被识别为内部或外部命令,可操作程序或批处理文件.
当我通过提升命令行运行它时,我得到了预期.
我使用了以下代码:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = @"CMD.EXE";
p.StartInfo.Arguments = @"/C bcdedit";
p.Start();
string output = p.StandardOutput.ReadToEnd();
String error = p.StandardError.ReadToEnd();
p.WaitForExit();
return output;
Run Code Online (Sandbox Code Playgroud)
我也试过用
p.StartInfo.FileName = @"BCDEDIT.EXE";
p.StartInfo.Arguments = @"";
Run Code Online (Sandbox Code Playgroud)
我尝试过以下方法:
我的想法已经用完了,知道为什么我会收到这个错误?
我需要的是命令的输出,如果有另一种方式也可以工作.谢谢
我想知道有什么方法可以像%PROGRAMFILES%, %APPDATA%,....使用 System.Diagnostics.Process.Start一样使用普通的快捷方式窗体窗口?
我想要做的是使用这些快捷方式之一动态创建用于启动我想从 Process.Start 开始的程序的路径。例子:
System.Diagnostics.Process.Start("%PROGRAMFILES%\MyApp\MyApp.exe");
Run Code Online (Sandbox Code Playgroud)
编辑:作为对已接受答案的评论:
由于在评论中提到了一件重要的事情,我也想把它放在这里:如果由于找不到文件而解决方案不起作用,则应打印出 System.Environment.ExpandEnvironmentVariables 命令的结果。它可能会无意中指向 x86 程序文件位置而不是程序文件位置(反之亦然),具体取决于应用程序本身(项目属性)“首选 32 位”或平台目标是否相应设置。如果牢记这一点,该解决方案效果很好。
我在这里看到了一些类似的问题,但找不到我的问题的答案..
这个几乎明白了: 如何从 32 位进程启动 64 位进程
但我错过了关于如何做到这一点的解释。
我正在努力实现以下目标:
P.StartInfo.FileName = "%windir%\\sysnative\\cmd.exe";
Run Code Online (Sandbox Code Playgroud)
但可能做错了什么 - 因为当我这样设置时没有任何反应,但是当这样设置时:
P.StartInfo.FileName = "c:\\windows\\sysnative\\cmd.exe";
Run Code Online (Sandbox Code Playgroud)
我认为是一样的 - 一切正常。我究竟做错了什么?
我怎么能“告诉”解决 %windir% 的过程而不是按原样对待它?!
我会像在第二个示例中那样设置它,但是我从不允许更改的外部文件中获取文件名,并将其写为 %windir%\sysnative\cmd。
我在x64系统上运行32位应用程序.(Windows 7)我正在尝试运行Windows备份,它位于:c:\ System32\sdclt.exe.因为我作为32位进程运行,所以我必须禁用WOW64重定向(使用Wow64DisableWow64FsRedirection).问题是,在禁用wow64重定向后,我得到"无法找到指定的过程"错误.
我的猜测是,不知何故,当禁用重定向时,sdclt.exe无法加载其所有依赖的dll.
注意:1.只有在我没有使用高级特权的情况下才会发生这种情况.2.我将"使用shell执行"设置为true,因为我想让用户使用我的应用程序而没有提升权限.2.编译为64位时不会发生此错误.