Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.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
为什么可以';";chgport.exe“;是否由Java中的Runtime.getRuntime().exec()找到?_Java_Windows - Fatal编程技术网

为什么可以';";chgport.exe“;是否由Java中的Runtime.getRuntime().exec()找到?

为什么可以';";chgport.exe“;是否由Java中的Runtime.getRuntime().exec()找到?,java,windows,Java,Windows,在Java中,我尝试运行: processp=Runtime.getRuntime().exec(“C:\\Windows\\System32\\chgport.exe”) 以及 processp=Runtime.getRuntime().exec(“chgport.exe”) 但得到以下例外情况: java.io.IOException:无法运行程序“C:\Windows\System32\chgport.exe”:CreateProcess error=2,系统找不到指定的文件 我正在使用N

在Java中,我尝试运行:
processp=Runtime.getRuntime().exec(“C:\\Windows\\System32\\chgport.exe”)
以及
processp=Runtime.getRuntime().exec(“chgport.exe”)

但得到以下例外情况:

java.io.IOException:无法运行程序“C:\Windows\System32\chgport.exe”:CreateProcess error=2,系统找不到指定的文件


我正在使用NetBeans IDE,它正在使用管理员凭据运行。

我尝试了您的代码,它工作正常,请这样尝试:

String[] command = {"chgport"};
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(new File("C:/Windows/System32/"));
pb.redirectErrorStream(true);
Process p = pb.start();
我在Eclipse中尝试了这两种方法,都很好 您是否可能没有以管理员权限运行IDE?
能否尝试关闭IDE并右键单击“以管理员身份运行”

    try {
        Process p = Runtime.getRuntime().exec("C:\\Windows\\System32\\mspaint.exe");
        p.waitFor();

        String[] command = {"mspaint"};
        ProcessBuilder pb = new ProcessBuilder(command);
        pb.directory(new File("C:/Windows/System32/"));
        pb.redirectErrorStream(true);
        Process p2 = pb.start();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

您可以使用
CMD/C
运行它,它“执行字符串指定的命令,然后终止”


根据,exec不需要绝对/相对路径,而是command@dnsiv我也尝试过不使用路径,但得到了相同的错误。您尝试过类似的方法吗<代码>字符串[]cmdArray=新字符串[]{“C:\Windows\System32\chgport.exe”};exec(cmdArray)@dnsiv是。使用“mspaint.exe”效果很好。更改为“chgport.exe”,但找不到“chgport.exe”。我的IDE以管理员身份运行,“chgport.exe”可由用户执行。“chgport.exe”文件有一些“东西”(似乎不是权限)。“mspaint.exe”是一个很好的例子,可以帮助我解决这个问题,但我还没有。我的IDE以管理员的身份运行,“chgport”可以由用户执行,所以我不知道。这很奇怪。
Process p = Runtime.getRuntime().exec("CMD /C chgport.exe");