Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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#程序启动Sysprep.exe_C#_Batch File_Windows 8_64 Bit_Sysprep - Fatal编程技术网

从C#程序启动Sysprep.exe

从C#程序启动Sysprep.exe,c#,batch-file,windows-8,64-bit,sysprep,C#,Batch File,Windows 8,64 Bit,Sysprep,如何从c#程序启动带有特定参数的sysprep.exe public void cmdPrint(string[] strcommmand) { Process cmd = new Process(); cmd.StartInfo.FileName = "cmd.exe"; cmd.StartInfo.RedirectStandardInput = true; cmd.StartInfo.RedirectStandard

如何从c#程序启动带有特定参数的sysprep.exe

 public void cmdPrint(string[] strcommmand)
    {
        Process cmd = new Process();

        cmd.StartInfo.FileName = "cmd.exe";
        cmd.StartInfo.RedirectStandardInput = true;
        cmd.StartInfo.RedirectStandardOutput = true;
        cmd.StartInfo.CreateNoWindow = true;
        cmd.StartInfo.UseShellExecute = false;
        cmd.Start();
        cmd.StandardInput.WriteLine("cd c:\\");

        foreach (string str in strcommmand)
        {
            cmd.StandardInput.WriteLine(str);

        }
        cmd.StandardInput.Flush();
        cmd.StandardInput.Close();
        writeLine(cmd.StandardOutput.ReadToEnd());

    }
我从Windows窗体应用程序中调用它

string[]cmd={“cd C:\\Windows\\System32\\Sysprep”,“Sysprep.exe/audit/reboot”}
consoleBox1.cmdPrint(cmd)

但它似乎没有启动sysprep.exe。我将这两个命令粘贴到.bat中,并用

System.Diagnostics.Process.Start(Application.StartupPath+“\\awesome.bat”)

但它也不起作用(打开一个黑色窗口,然后立即关闭)

从explorer运行bat文件是可行的,所以我想我的c#应用程序中缺少了一些权限

在我的app.manifest中

是否可以启动sysprep?我的应用程序在Windows 7、8、8.1和10上正常桌面和审核模式下运行

编辑:

我在没有关闭命令的情况下尝试了代码,但是程序没有响应

var procInfo = new 
ProcessStartInfo("C:\\Windows\\System32\\Sysprep\\sysprep.exe");
                procInfo.Arguments = "/audit /reboot";
                var proc = new Process();
                proc.StartInfo = procInfo;
                proc.Start(); //Actually executes the process
                proc.WaitForExit();
给出错误:

系统找不到该文件 指定的/nSystem.ComponentModel.Win32Exception(0x80004005):异常 系统找不到在处指定的文件 System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo 在System.Diagnostics.Process.Start()处启动 Windows\u SSD\u优化器\u方法\u 1.Method1.btn\u所有\u单击(对象发送器, 事件参数e):第182行/n/n系统找不到 指定的文件/nSystem.ComponentModel.Win32Exception(0x80004005): 系统找不到在处指定的文件 System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo 在System.Diagnostics.Process.Start()处启动 Windows\u SSD\u优化器\u方法\u 1.Method1.btn\u所有\u单击(对象发送器, 事件参数e)输入:第182行/n/n


找到了适用于早于8的Windows版本的解决方案:

您需要将程序编译为x64二进制文件。如果将其编译为x86二进制文件,系统将重定向到
SysWOW64
,而不是
System32

如果需要与x64和x86兼容,还可以禁用文件夹重定向:

 // Disables folder redirection
 [DllImport("kernel32.dll", SetLastError = true)]
 static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);

 // Enables folder redirection
 [DllImport("kernel32.dll", SetLastError = true)]
 static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);

在Windows8x64中,您应该

当32位应用程序希望访问服务器上的System32文件夹时 64位操作系统,Windows 8将默认任何指向idea上syswow64的路径 一个32位的程序实际上是在寻找32位的文件

请尝试以下路径:

@“c:\windows\sysnative\sysprep\sysprep.exe”


为什么不直接启动sysprep.exe呢?无需运行cmd.exe,但如何传递参数/audit/reboot?cmd.StartInfo.arguments我尝试用process启动sysprep.exe,但不起作用:/您的程序是否在64位系统上以32位运行,如果是这样,您在错误的
系统
文件夹中查找。如果用户没有管理员权限,则highestAvailable可能无法以管理员身份运行。requireAdministrator强制获得管理员权限。尝试过,但仍显示找不到文件。尝试通过VS运行它,
System.dll中发生类型为“System.ComponentModel.Win32Exception”的未处理异常
其他信息:系统找不到指定的文件
我的UAC已在Windows中设置为最低值。我在此处遇到了相同的异常,认为这可以解决问题。我将进一步研究它。它是有效的:DD这在x86系统上有效吗?或者我应该检测操作系统然后继续吗?也许你必须,是的。在Win7上,该路径不起作用。
var procInfo = new ProcessStartInfo(@"c:\windows\sysnative\sysprep\sysprep.exe");
procInfo.Arguments = "/audit /reboot";
var proc = new Process();
proc.StartInfo = procInfo;
proc.Start(); //Actually executes the process
proc.WaitForExit();