mkdirs在Windows 7中不起作用 [英] mkdirs not working in windows 7

查看:130
本文介绍了mkdirs在Windows 7中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个小型的Java应用程序,可将目录从CD复制到HD.我使用Windows Vista制作了该程序,并且可以运行,但是当我在Windows 7中运行它时,它失败了.

I made a small java app that copies a directory from a CD to the HD. I made the program using Windows Vista and it worked, but when i ran it in Windows 7, it fails.

主要问题是需要在Program Files文件夹中创建一个文件夹.

The main problem is that a folder inside the Program Files folder needs to be created.

我使用了DestinationFolder.mkdirs(),但是创建它失败

I used DestinationFolder.mkdirs(), but it fails creating it

这是Java代码:

public void Install_App()
{
    File srcFolder = new File(System.getProperty("user.dir") + "\\WINDOWS");
    File destFolder = new File("C:\\Program Files\\test1\\test2\\");
    if (srcFolder.exists())
    {
        try{
            if(!destFolder.exists())
        {
            destFolder.mkdirs();
        }
            copyFolder(srcFolder,destFolder,1);
        }catch(IOException e){
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, e.toString());
            error=true;
            System.exit(0);
            }
    } else 
    {
        JOptionPane.showMessageDialog(null, "Error. Source Directory doesn't exist.");
        error=true;
    };
} 

...,然后有一个copyfolder函数,该函数可使用inputstream和outputstream复制文件.

... and then there is a copyfolder function that copies the files with inputstream and outputstream.

问题是文件夹从未创建.我的登录用户是管理员.正如我所说的,它可以在Vista中使用.

The problem is that the folder is never created. My login user is an administrator. And as i said, it worked in Vista.

可以帮我吗?

谢谢.

问题是我在Java中创建了这个应用程序,以便在Windows和Mac上运行它. 在Windows中,应使用和autorun.inf自动运行,如下所示:

The thing is that i created this app in java to run it in Windows and Mac. In Windows it should autorun with and autorun.inf like this:

[autorun]
OPEN=java_app.bat

然后这只蝙蝠将运行:

@echo off
start javaw -jar "java_app.jar"
EXIT

那么我该如何修改它以使其以管理员身份自动运行? 此Java应用程序的主要思想是简化安装和安装过程.无论您使用哪个操作系统,都可以使用外部应用程序.如果我必须要求用户以admin身份运行它,那么它将失去(使用简单)的感觉.

so how can i modify it to run it as administrator automatically? The main idea of this java app is simplify the process of install & use an external application no matter which OS are you using. If I have to ask the user to run it as admin it will loose it's sense (of been simple of use).

推荐答案

我猜您正在以常规用户身份运行代码.

I am guessing you are running your code as regular user.

默认情况下,以 UAC 阻止以普通用户身份写入Program Files目录Windows7.这就是您的Java代码无法创建目录的原因.

Writing into Program Files directory as a regular-user is by default blocked by UAC under Windows 7. That's why your Java code fails to create directories.

尝试从特权Shell运行Java代码.您可以通过Start > [type cmd] > [right-click on 'cmd.exe' and select "Run as administrator"]拥有一个.现在,在管理员命令提示符下使用java -jarjava -classpath运行编译后的代码.现在应该可以使用了.

Try running your Java code from a privileged shell. You can have one by Start > [type cmd] > [right-click on 'cmd.exe' and select "Run as administrator"]. Now, run your compiled code with java -jar or java -classpath from the administrator command prompt. It should work now.

自动执行UAC提示:

您需要创建清单文件,如[ 1 ]和[ 2 ],以使Windows/UAC知道您的程序需要提升的特权.

You need to create a manifest file as described in detail at [1] and [2] to let Windows/UAC know that your program would need elevated privileges.

也请检查名为elevate的[ 3 ]实用程序将在处理UAC权限请求时将程序作为子进程生成,所有UAC权限请求都是由父程序(elevate)本身发出的.

Also check this [3] utility called elevate that would spawn your program as child process while handling the UAC permission requests all being made from the parent (elevate) program itself.

[1] [http://msdn.microsoft.com/en-us/library/aa511445.aspx][2] 
[2] [http://msdn.microsoft.com/en-us/library/bb756929.aspx][3]
[3] [http://www.wintellect.com/cs/blogs/jrobbins/archive/2007/03/27/elevate-a-process-at-the-command-line-in-vista.aspx][4]

这篇关于mkdirs在Windows 7中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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