Java executable jar, Window program file folder and administrator privilages - java

This is for Window 7 and Window 10
We have requirement to generate jar inside c:program file only. Installer can easily install our jar into c:\\ProgramFile\\testapp. After that we have the requirement to download the zip file from third party server inside c:\\ProgramFile\\testappp and here we are getting the access denied.
After lot of research, we come to know, we can run our jar under administrator privileges using super-user-application-0.0.5.jar.
Now the problem is We are getting the "User account control popup" with message "Do you want to allow the following program to make changes to this computer"
We don't want this popup so anyone know how to bypass this popup?
The important code from super-user-application-0.0.5.jar is
Shell32X.SHELLEXECUTEINFO execInfo = new Shell32X.SHELLEXECUTEINFO()
execInfo.lpParameters = args
execInfo.lpDirectory = lpDirectory
execInfo.fMask = Shell32X.SEE_MASK_NOCLOSEPROCESS
execInfo.lpVerb = "runas"
boolean result = Shell32X.INSTANCE.ShellExecuteEx(execInfo)
execInfo.lpVerb = "runas" is actually opening the popup. Is there any way, just bypass the popup and further processing should be similar to the saying OK to the popup.
Any chance to java programatically provide admin rights to the testapp folder created inside c:\ProgramFile\testapp

Related

How To Open Files With .Jar (Java) Application?

Tough question here. How do you open a file in java, in the way that when you double click on the file it automatically opens in a java application.
I'm making a musicplayer (first real big Java project for me) and I have no clue how to acheive this. When you open, lets say, a .mp3 file it will open in whatever default program you have selected for it (such as VLC mediaplayer or Windows Media Player). What I want is to be able to set the .jar file of my application as the default program for .mp3 files, and then to be able to actually launch the files in the application.
When I currently try to open a file with the application I get a windows error saying "This app cannot be executed on your pc". But when I launch the .jar itself without doing it by trying to open a .mp3 file it runs just fine.
Does anyone know how to acheive what I want? Many thanks in advance!
---edit---
I do not mean that you can select a default program for the mp3 file. The problem is that windows throws the error shown above, and that I dont know how to handle the application being launched by opening a file (which does not ope due to the error).
I think the problem is that you have to open a file with a .exe , so you sshould use an exe wrapper (I use jsmooth: download here)
BUT, before you do that, you need to accept that info. So in the main class, the "args" is a list of info about how it's being launched. If you are opening a file, the array's first argument will be the opened file's destination. SO I would accept it like this:
if (args.length > 0) {
File f = new File(args[0]);
start_the_application_with_a_file(f);
} else {
start_the_application_without_a_file();
}
C:\ProgramData\Oracle\Java\javapath\java.exe -jar "C:\Program Files\YourApp.jar" %* within a batch-file (.cmd) might do it.

Signed Applets don't Load

After change in security in new version of Java there is a popup showing information about unsigned content every time site is reloaded. So we decided to sign our applets (and all libraries used). But after signing, all applets ceased to load on site, it’s just blank grey space. After deploying signed jars we got information saying “Application Blocked by Security settings”. When I click ‘OK’ applet shows information "Error. Click for details", when I click it there is no information in applet console.
What can be reason of this?
Steps to resolve in my case:
-create jar per applet
-create jnlp file per applet outside jar file
-still you need jnlp in jar file in JNLP-INF
-set properties in manifest
-then sign every lib and jar with cert

Java: Where to write config without requiring administrative rights

I actually can't believe I'm saying this but since porting my programs to OSX and getting used to permissions, I've realized that what I planned to do on Windows will not work how I want it to. Currently, on windows, my program stores it's setting's in the registry (HKLM) and some user editable resources in a folder next to the program file. For various reasons, I have now decided that the configuration/settings will be stored in a file and the user will be able to in which folder the other resources are kept.
So the question I have now is where to store the configuration file. Obviously it will be updated, but I don't want to program to have to require administrator permissions to run. I would like to offer an option so that all users can use the program (like most programs do), which will of course require Admin, so this leads be onto the second query: where should I store the configuration file (and the folder in which other resources are kept) and how can I detect whether the program has been installed for all users or just one!
Thanks in advance
PS If you didn't guess, the program is written in Java so I would like to know how to programatically get the location you suggest as well please.
Its normal practice in *nix compatible programs to store information in folders starting with name . in the home directory of the users like,
.bash_history
.bashrc
You could use the same on OSX in my opinion and create a directory say,
.myapp
You can store any number of files with any format under that directory.
To get the location of the folder, you can do
String homeDir = System.getProperty("user.home");
File myAppDir = new File(homeDir, ".myapp");
That is roughly the code that can get you your custom config directory for your app.
Please not that dot files / folders are somewhat similar to hidden folders in windows. Your File Manager will not generally show these files / folders by default.
To identify if the program is installed for all the users or not, you could create the configuration at some administrator (root) controlled location like /etc (not sure about Mac) The user configuration can always override the default config. There could be a better way to handle this though.
On both windows and unix, User(usually) has a (home)folder to which it has full permissions. You may create a directory in the home folder and have your user configuration files reside there.

File manipulation won't work in Java Web Start

I built this program that works with files. Since I made it for a friend, I made it into a Java Web Start app, complete with a JNLP file.
When I launch the app through an ANT (netbeans) without the JNLP, it works just fine. But when launched through the JNLP (even through netbeans), the button that is supposed to perform the required actions instead does nothing (it just stays in "clicked" mode until you hover away from it).
I spent hours trying to figure out the problem, but no luck.
Here is the problematic method:
public void copy(String path1, String path2) throws IOException {
File inputWorkbook = new File(inputFile);
Path in = Paths.get(path1);
Path out = Paths.get(path2);
Workbook w;
try {
w = Workbook.getWorkbook(inputWorkbook);
.
.
.
If I don't attempt to do anything with the inputWorkbook file, everything works ok. As soon as I attempt ANY sort of method on it (such as w = Workbook.getWorkbook(inputWorkbook), or even inputWorkbook.exsists();) , the problem occurs. It won't even throw an exception, it just does nothing... Again, the problem only occurs when the program is launched through the JNLP file.
I hope I managed to explain the problem... I'm new to programming.
Thank you!!!
Adam
Webstart applications run in a security sandbox which prevents the to access the file system. You need to digitally sign your har to gain access to the file system, or use the file open api. See http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/faq.html#302 and http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/examples.html#FileOpenService for more information.

JavaFX loading external resources problem

I've coded small JavaFX Applet in Netbeans 6.8 IDE. Everything works fine if the applet runs on my computer. But when I put the applet (and edited JNLP files containing changed paths to server) into server, it doesn't load any data from an server text file. Paths are correct - i look at it many times - they are ok. It also doesn't load images with external urls. What is wrong?
Haven't seen your code so I'm going to make a guess. If your resource is not bundled in your JAR file and you are using file:// to access it, then you will need to sign your applet. On NetBeans, right click on project node -> properties -> application. Select self signed.
If you don't want to sign your applet, then access your resource as REST. Use the HttpRequest.
If it is on the client machine, consider using JNLP APIs like so.
FileOpenService fos = (FileOpenService)ServiceManager
.lookup(“javax.jnlp.FileOpenService”);
//Open dialog pops up
FileContent fc = fos.openFileDialog(null, null);
The best way to diagnose the problem is to open the Java Console and see if there are any exceptions. Run $JAVA_HOME/bin/ControlPanel -> Advanced -> Java Console -> Show Console

Categories