1
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: C:\Users\Kelvz1\AppData\Local\Temp\JNativeHook_6363198016012433909.dll: Access is denied

我有这些错误,我该如何解决。有些用户可以访问这些并且没有问题,但有些用户不能。

4

1 回答 1

3

这是一个奇怪的随机错误,有时会出现在 Windows 7 和 Windows 8 上。有一天一切都很好,然后当 Java 尝试访问临时文件夹中的 DLL 时,突然出现访问被拒绝异常。

我发现删除 TEMP 文件夹并让它自动重新创建它通常可以解决问题。

如果您是将 DLL 放入 TEMP 文件夹的代码的作者,那么我建议您更改代码以将 DLL 放入此路径下的文件夹中,因为我还没有在此处看到此问题:%USERPROFILE%\AppData \当地的\

我在某处读到这可能是由 Microsoft Security Essentials 引起的,但它看起来不像是安装在刚刚遇到此问题的计算机上。

我已经看到许多不同的 DLL 文件都会发生这种情况,例如 jna.dll。

如果您使用 JNA 并且遇到此问题,您可以更改临时目录系统属性,JNA 将在不同目录中创建文件。此代码应该适用于此。

    String osName = System.getProperty("os.name");
    if (osName.toLowerCase().startsWith("windows")) {
        // we change the temp directory because sometimes Windows is stupid and doesn't want to load jna.dll from the temp directory
        File tempDir = new File(System.getenv("USERPROFILE") + "\\AppData\\Local\\MyCompany\\temp");
        System.out.println("Using temp dir: " + tempDir.getPath());
        tempDir.mkdirs();
        System.setProperty("java.io.tmpdir", tempDir.getPath());
    }
于 2014-01-23T14:12:11.287 回答