JNativeHook_6363198016012433909.dll: Access is denied - java

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: C:\Users\Kelvz1\AppData\Local\Temp\JNativeHook_6363198016012433909.dll: Access is denied
I have these error how can I fix it.
Some of the users can access these and no problem, but some user cant.

This is a strange random error that sometimes manifests on Windows 7 and Windows 8. Everything is fine one day and then suddenly you get an access denied exception when Java tries to access a DLL in the temp folder.
I've found deleting the TEMP folder and letting it re-create it automatically usually solves the problem.
If you are the author of the code that put the DLL in the TEMP folder then I would recommend you change the code to put the DLL in a folder under this path instead as I have yet to see this problem there: %USERPROFILE%\AppData\Local\
I read somewhere this can be caused by Microsoft Security Essentials but it doesn't look like this is installed on the computer that just experienced this problem.
I've seen this happen with many different DLL files, like jna.dll.
If you're using JNA and it has this problem you can change the temp directory system property and JNA will create the file in a different directory. This code should work for this.
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());
}

Related

How to pass variable file path to SQL*Loader on Linux

I'm creating .csv file and placing it in one location.
String location = "/APPL_TOP2/IMDD/apps/apps_st/appl/xxfin/12.0.0/bin/xe.csv";
Using exact path working fine on Windows but I need it to work on Linux client too.
String location = "$XXFIN_TOP\\12.0.0\\bin\\xe.csv";
If I'm using relevant path on Linux it is not working, showing Error
SQL*Loader-500: Unable to open file(/APPL_TOP2/IMDD/apps/apps_st/appl/xxfin/12.0.0/bin/xe.csv)
SQL*Loader-553: file not found
SQL*Loader-509: System error: No such file or directory
" Client is asking any option to pass relevant path client machine is Linux"
Paths in Linux have slashes which go the other way. So it should be this:
$XXFIN_TOP/12.0.0/bin/xe.csv

Why an extra "/.\" in linux path?

Windows Scenario :-
I have a small piece of code which gets me the location of a specific folder in the directory. The code is as given below:
browserPath = this.EnginePath + "\\Chrome_Selenium\\" + "chromedriver.exe";
This gets me the exact path : D:\Engine\Test
I am trying to use the same logic to get the path in linux machine.
The path where the Engine and Chrome Driver is stored in my linux machine (VM) is
/root/Engine/Chrome_Selenium
Now the linux part :-
I am using the following piece of code to get that
browserPath = this.EnginePath + "/Chrome_Selenium/" + "chromedriver";
The path this piece of code fetches is
/root/Engine/.\Chrome_Selenium\chromedriver
Can you please help me understand why the "/.\" is appearing in the path?
I am guessing the reason why ./ is added is because in linux in order to execute a script in the present working directory you need to address it this way: ./script instead of script. Somehow it is attached even in cases where it is not needed (execution in other folder)
As for the main part as Alfe mentioned it does not make any different at the first place.

Access denied when trying to execute a .exe in %AppData%

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();
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.
EDIT: 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.
This may not be the problem in your situation, but some anti-virus programs will prevent executables or scripts inside temporary folders from being run. Instead of creating a temporary file, try putting it in the user directory:
File rdExe = new File(System.getProperty("user.home") + "/.yourProgramName/rmvd.exe");
rdExe.getParentFile().mkdirs();
just a heads up on another way to run files, have you thought of using the java Desktop object? : http://docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html
i've found it useful when needing to run programs through my java program. something like this could work for you:
Desktop.getDesktop().open(new File("enter path and name of the file"));
hope you find it useful
I am not JAVA user but isn't it 32 vs. 64 bit issue ?
On 64 bit Windows error code 5 usually means that executable is not 64 bit compatible. Sometimes this is the case even when executable need to access only some (older win) system directory which does not exist anymore. To prove this try to use your executable in command line. if you can manage to get it work there than it is different issue. If not find executable for your OS.
Another possibility is that the file has to be physically present on some drive.
You wrote that you has it as temporary. Not shore what it means for JAVA. If it only copy it to some file and delete after use than its OK but if it is only in memory somewhere than that could be problem if executable need access to itself. To prove this just copy the file to some known location and then run it from there (in JAVA). if it works than you will need to do something about it (copy and delete executable from JAVA before and after execution to physical disk medium or whatever)
Another possibility is that error code 5 comes from JAVA environment an not from OS
In that case I have not a clue what it means (not JAVA user)
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.
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.
What version of Windows are you running? Microsoft significantly tightened the restrictions around executing programs in Windows 7. My guess is that it the OS won't allow you to fork something that wasn't authenticated at the time your program was launched. I'd try running it on Windows 2000 or XP and see if you have the same issues.

Loading external dll with bridj is not possible due to hebrew username

I tried to load native library (lib.dll) to Java application via BridJ on Windows 7, where username is written in Hebrew.
What is important is that the Java application downloads lib.dll and save it properly in place:
C:\Users\דני\AppData\Local\Temp\lib.dll
I have reference to that file -> File lib, and pass lib.getCanonicalPath() to BridJ.
In the end I get the following exception:
Caused by: java.io.FileNotFoundException: Library 'LIB' was not found in path
...
...
...
(failed to load C:\Users\???\AppData\Local\Temp\lib.dll)
at org.bridj.BridJ.getNativeLibrary(BridJ.java:619)
at org.bridj.BridJ.getNativeLibrary(BridJ.java:619)
at org.bridj.BridJ.getNativeLibrary(BridJ.java:599)
at org.bridj.BridJ.getNativeLibrary(BridJ.java:315)
at org.bridj.CRuntime.getNativeLibrary(CRuntime.java:341)
at org.bridj.CRuntime.register(CRuntime.java:299)
... 21 more
So it seems that, getCanonicalPath() converts דני to.
How can I solve that ?
This bug looks similar to the following issue, which was fixed yesterday :
https://github.com/ochafik/nativelibs4java/issues/276
You might want to try again with the latest 0.7-SNAPSHOT.

Deployment in tomcat

i am getting a problem
i have deployed a war file, when i run localy through tomcat it works fine but when i run on another system by giveing my system ip and then project folder e.g
http:\192.168.0.145\DllTest it loads the applet but when i click on a button to load the functionality it is throwing an exception
Exception in thread "AWT-EventQueue-3" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: http:\192.168.0.145:8080\DllTest\lib\jinvoke.dll
while it is working fine localy but not in another system. Please tell me what is the problem.
Is it a rights issue or something else.
You cannot load a DLL on an external host. It has to be an absolute disk file system -as the exception message already hints. Your best bet is to download it manually, create a temp file and load it instead.
File dllFile = File.createTempFile("jinvoke", ".dll");
InputStream input = new URL(getCodeBase(), "lib/jinvoke.dll").openStream();
OuptutStream output = new FileOutputStream(dllFile);
// Write input to output and close streams the usual Java IO way.
// Then load it using absolute disk file system path.
System.loadLibrary(dllFile.getAbsolutePath());
dllFile.deleteOnExit();

Categories