IOException
,其中写着CreateProcess error=5, Access is denied
。然而,该程序通常不需要管理员权限。有什么想法可以解决这个问题吗? File RDexe = File.createTempFile("rmvd", ".exe");
InputStream exesrc = (InputStream) GraphicUI.class.getResource("RemoveDrive.exe").openStream();
FileOutputStream out = new FileOutputStream(RDexe);
byte[] temp = new byte[1024];
int rc;
while((rc = exesrc.read(temp)) > 0)
out.write(temp, 0, rc);
exesrc.close();
out.close();
RDexe.deleteOnExit();
// run executable
Runtime runtime = Runtime.getRuntime();
System.out.println(RDexe.getPath() + " " + "F:\\" + " -b -s");
Process proc = runtime.exec(RDexe.getPath() + " " + "F:\\" + " -b");
InputStream is = proc.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line; boolean ejected = false;
while((line = reader.readLine()) != null)
if(line.equalsIgnoreCase("failed")) ejected = false;
else if(line.equalsIgnoreCase("success")) ejected = true;
reader.close();
is.close();
更新:如果我启用内置的管理员帐户(net user administrator /active:yes
),从那里运行一切都很好。但是,如果我在标准帐户中右键单击并以管理员身份运行,则仍会出现错误,并且UAC甚至不会请求权限。
编辑:由于赏金即将结束,请参阅我的SuperUser问题,这已经帮助我解决了这个问题... 我很快就会授予赏金并接受答案。