Are there special permissions in Windows 7 to prevent file creation? - java

I created a program that takes in an excel file and pastes in an image of a graphical timeline based on the events in the document. But when trying this on a PC with windows 7 coming from XP and Vista I was unsuccessful in even creating the image. Is there a permission in Windows 7 that disallows a java program called by an excel macro to create files?
Formally it's a 1004 unable to get insert property of image file, but this only occurs because the file is not created in the first place.

An application is not allowed to write under Program Files unless it's run elevated (and you don't want it to run elevated.) Write to a per-user location instead, either AppData if the user should never need to see the files, or under the user's Documents if they might (eg an export that they are supposed to upload or mail.)

Related

How to close a .txt file as it opens

Need a program written in Java to close a .txt file as it opens (so that the user can, hopefully, not see it). How would I go about closing a .txt file as soon as it opens?
The alternatives to this way is to open the file on the secondary monitor or replace the text in the file instantly so the user cannot see this.
As I understand your question you want to intercept all requests, by any program running in a computer, to open any text file, and prevent that file from being accessed.
This is categorically beyond the capabilities of anything you can do in Java, or any "user-space" environment. Anything of this type would have to be done as part of the operating system, operating in privileged mode, and working with the filesystem drivers.
This could probably be done but would be operating-system specific and likely need to be written in C++ or assembler. Also it would require specific user action to be installed and would require superuser or administrator privileges.
This is not something within reach of a developer without significant OS kernel experience.
Sounds like you are trying to write ransomware?

How can I drag virtual files from java swing to windows desktop?

Is it possible to drag a "virtual" file from Java swing application and drop it onto windows desktop?
By "virtual" I mean "not local" file that needs to be downloaded/prepared which could potentially take a long time. I have a client-server application that shows a view of remote files. When user drops that file on desktop, I would like to receive a notification of the destination folder which I would use to start the download process with the Java application.
Please offer any help or guidance as I've been looking for a solution for a while now.
I'm working on something similar myself, and I have some unfortunate news for you: Windows cannot handle promised files, nor does it inform your java application as to where the files are dropped. Simply put, there is no way to handle remote drag-and-drop via the DnD api only.
You need to create empty files in some temp directory somewhere, and hand windows those files when the mouse leaves the swing window. You also need to set up a WatchService on the local filesystem to receive notification of file creation. After DropEnd, you check for empty files of the correct name but not in your temp directory, and effect the transfer at that point (move the remote files into the empty files that were dropped).

Associate file format with my program (Java)

I am making Scouting Software (in Java) for my FRC robotics team. Scouting is like collecting data on other teams' robots during competition. It is absolutely critical that my program makes that process as simple and easy as possible. My program can save its data in two ways, one of which is by writing a .scout file to the user's hard drive. All this is working well, but as a finishing touch i would like to implement a way to associate .scout files with my program so that .scout files are opened with my program. It's like .docx for Microsoft Word. It associates .doc/.docx/...etc to itself such that when the user clicks on a file with those extensions, Word opens itself up and then opens the file the user clicked on. I want something like this for my application. Keep in mind, it is written in Java and meant to work on different operating systems (Windows, OSX, Ubuntu Linux, etc).
Does the program have a GUI? If so, launch it with Java Web Start.
JWS can associate a file-type with an application on Windows, OS X & *nix. Here is a demo. of the JNLP API file service that associates the .zzz file type with the demo. app.

How can I determine the way to access certain third-party programs and resources from my Java app?

I'm trying to open a PDF file after I generate a report. I mean, the user logs in (it's a Swing-based app) and clicks to generate a report. Then, a PDF file is generated. I would like to launch the PDF reader at that moment. I could do something like exec("evince "+path_to_pdf_file). It's just for Ubuntu, Windows would be more difficult. I'm thinking I need to explore the registry.
How can I achieve this?
What you need is the method java.awt.Desktop#open
Launches the associated application to open the file.
If the specified file is a directory, the file manager of the current platform is launched to open it.

Best place to save program config file on Windows and OS X using Java?

I have a SWT Java app that runs on Windows XP / Vista / 7 and Mac OS X. I'm currently saving a config file to:
System.getProperty("user.home") + filename
With the changes in security in Windows Vista and Windows 7 this doesn't seem to be the best place to save it anymore.
This file saves information such as registration key info and it is annoying for my users if the file can't be saved or is deleted.
Is there a better path I should use?
Also, what's the preferred path for per user application data on Mac OS X?
macos path for application data to be kept is "~/Library/Application Support" as per Apple documentation
What changes in security? I understand they prohibited writing in Program Files, I didn't know they forbid to write in user home.
It would be a serious compatibility break, I have a number of applications writing there, either directly a file, or in a folder ("hidden" at the Unix mode, ie. prefixed with a dot).
Now, it seems to be more "friendly" to write in Application Data folder as do a number of other applications (but rarely cross-platform applications which seem to use the previous solution...) but the exact location seems hard to find in Java, and would need a platform detection to do something else on other platforms.
An alternative seems to be to use the Preferences API, ie. java.util.prefs.Preferences.
Sun itself, with its java control panel, had the very same problem (bug 6487334): their control panel, running at different integrity level, could not both read/write to their deployment directories.
They moved it to c:\users\<username>\appdata\local, but had to not rely on System.getProperty("user.home") because to this day, it uses a registry KEY that can be set to incorrect value if windows is "tweaked": bug 6519127
So the question How to get local application data folder in Java?, using HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\* is the right place to start looking for read/write access for your settings.
You can read it with, for instance, SWT Win32 Extension project.
The interest to keep your data within the user's homedir is that they will be part of the user's profile which can be a roaming profile, saved at logoff and restored at logon (used quite often on corporation's workstations)

Categories

Resources