我已经通过堆栈溢出搜索找到了这个问题,但还没有人给出一个有效的解决方案。我正在编写一个简单的程序,它的第一部分是使用一些参数启动sysprep.exe。由于某种原因,sysprep不会在代码运行时启动。它会给出找不到文件的错误。例如,通过使用下面的代码,记事本将不会出现任何问题。如果我尝试打开sysprep,它不会。
Process.Start(@"C:\Windows\System32\notepad.exe"); -- opens with no issue
Process.Start(@"C:\Windows\System32\sysprep\sysprep.exe"); -- does not open任何帮助都将不胜感激。
{
public MainWindow()
{
InitializeComponent();
}
private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
if (radioButtonYes.IsChecked == true)
{
Process.Start(@"C:\Windows\System32\sysprep\sysprep.exe");
}
}发布于 2018-08-16 14:09:22
这实际上是64位Windows上的重定向问题。根据this discussion的说法,System32调用被重定向到SysWOW64文件夹。由于C:\Windows\SysWOW64\Sysprep\sysprep.exe不存在,因此会出现错误。
这就是你想要的:
Process p = Process.Start(@"C:\Windows\sysnative\Sysprep\sysprep.exe");只需使用sysnative即可。
发布于 2018-08-24 03:24:57
我看到另一个答案对你有效,但我想包括一个不同的答案,允许你随时从System32访问文件。如果您从一个公共类开始随时修改内核,那么只要您拥有正确的权限,就应该能够访问所需的任何内容。
public class Wow64Interop
{
[DllImport("Kernel32.Dll", EntryPoint = "Wow64EnableWow64FsRedirection")]
public static extern bool EnableWow64FSRedirection(bool enable);
} 在这之后,我写出调用sysprep的方法如下
private void RunSysprep()
{
try
{
if (Wow64Interop.EnableWow64FSRedirection(true) == true)
{
Wow64Interop.EnableWow64FSRedirection(false);
}
Process Sysprep = new Process();
Sysprep.StartInfo.FileName = "C:\\Windows\\System32\\Sysprep\\sysprep.exe";
Sysprep.StartInfo.Arguments = "/generalize /oobe /shutdown /unattend:\"C:\\Windows\\System32\\Sysprep\\unattend.xml\"";
Sysprep.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
Sysprep.Start();
if (Wow64Interop.EnableWow64FSRedirection(false) == true)
{
Wow64Interop.EnableWow64FSRedirection(true);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}在做这样的事情时,你要确保这个过程是否会重启你的电脑,不使用"WaitForExit()“方法。希望这篇文章能帮助其他寻找这个答案的人。
发布于 2018-08-16 13:39:22
我认为这是权限问题,您可以尝试以管理员身份运行
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName ="cmd.exe";
startInfo.Arguments = @"/c C:\Windows\System32\sysprep\sysprep.exe";
startInfo.Verb = "runas";
process.StartInfo = startInfo;
process.Start();https://stackoverflow.com/questions/51869905
复制相似问题