尝试在%AppData%中执行.exe时访问被拒绝 [英] Access denied when trying to execute a .exe in %AppData%

查看:230
本文介绍了尝试在%AppData%中执行.exe时访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用我的在此处找到的RemoveDrive.exe Java应用程序.我将其保存在JAR中,并使用以下代码将其提取到一个临时文件中,但是当我尝试运行它时,我得到一个IOException,其内容为CreateProcess error=5, Access is denied.该程序通常不需要管理员权限.关于可能导致此问题的原因有什么想法吗?

I'm trying to use RemoveDrive.exe, found here, in my Java application. I have it in my JAR, and I'm extracting it to a temporary file using the following code, however when I try to run it I get an IOException which says CreateProcess error=5, Access is denied. The program doesn't normally need admin priviledges though. Any ideas on what could be causing the issue?

            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();

更新:如果我启用了内置的Administrator帐户(net user administrator /active:yes),那么从那里开始一切正常.但是,如果我右键单击并以管理员身份在我的标准帐户中运行,我仍然会收到错误消息,并且UAC甚至都不会征求许可.

UPDATE: If I enable the built-in Administrator account (net user administrator /active:yes), everything works fine from there. However if I right click and run as administrator in my standard account, I still get the error and UAC doesn't even ask for permission.

编辑:好像赏金快要结束了,请参阅

Seeing as though the bounty is nearly finished, please see my SuperUser question which has helped me solve this problem... I'll be awarding the bounty and accepting an answer soon.

推荐答案

似乎只在这里涉及到这个问题,我会说这个问题与Windows中的权限有关,与Java无关.

Seeing as though it has only been touched on here, I will say that the issue was related to permissions in Windows, and is not anything to do with Java.

正如我在原始问题中链接到的超级用户"问题中所述,我发现我的普通帐户由于某些未知原因不具有该文件夹的所有权-因此无法执行任何操作;这不仅仅是我用Java创建的临时文件.

As stated in the SuperUser question I've linked to in my original question, I found that my usual account did not have ownership of that folder for some unknown reason - so nothing could be executed; it wasn't just the temporary file I had created in Java.

即使我是管理员,也要获得该文件夹的所有权,我必须启用内置管理员帐户并授予自己所有权.自从我这样做以来,一切都按预期进行.

Even though I am an administrator, in order to take ownership of the folder I had to enable the Built-In administrator account and grant myself ownership. Since I did that, it has all worked as expected.

感谢大家的努力,我将把悬赏奖励给最详尽的答案,并让我走上正确的道路.

Thanks to all for their efforts, I will award the bounty to the answer that was most detailed and put me on the right tracks.

这篇关于尝试在%AppData%中执行.exe时访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆