I'm busy creating a program that will read parts of the registry to find out what USB devices have been connected to a windows system etc... I've managed to create a piece of software what will display the values, however each person's registry will hold different information.
I've tried looking everywhere to find help/guidence with code to be able to scan a registry folder and display the subfolders within it. I know there is plenty of code for reading ordinary file locations however none will work with attempting to read the registry.
The folder location I am trying to read is:
"\"HKLM\SYSTEM\CurrentControlSet\Enum\USBSTOR\
I've managed to create a program which will read the values from the above location however I have to manualy specify each subfolder into the code.
I hope i've explained what i need, sorry if it's confusing
Thanks in advance
I've used jRegistryKey.dll jRegistryKey.jar
Here you go
ftp://ftp.heanet.ie/mirrors/sourceforge/j/project/jr/jregistrykey/manual/original/jreg_key.pdf
e.g. code:
import ca.beq.util.win32.registry.RegistryKey;
import ca.beq.util.win32.registry.RegistryValue;
import ca.beq.util.win32.registry.RootKey;
enumeration from example ---
RegistryKey r = new RegistryKey(RootKey.HKEY_CURRENT_USER, "Software");
if(r.hasSubkeys()) {
Iterator i = r.subkeys();
while(i.hasNext()) {
RegistryKey x = (RegistryKey)i.next();
System.out.println(x.toString());
} // while
} // if
RegistryKey r = new RegistryKey(RootKey.HKEY_LOCAL_MACHINE, "Software\\app\\update\\Date");
if (r.hasValue("LastSuccessfulUpdate")) {
RegistryValue v = r.getValue("LastSuccessfulUpdate");
updateDate = v.getStringValue();
Date now = new Date(Long.parseLong(updateDate.trim() + "000"));
................
}
Related
I'd like to read and change zoom level of named destinations in a pdf file using iText 7. Ive come up with the following code:
Map<String, PdfObject> names =
document.getCatalog().getNameTree(PdfName.Dests).getNames();
for (Map.Entry<String, PdfObject> dest : names.entrySet()) {
if (dest.getValue().isArray()) {
PdfArray arr = (PdfArray) dest.getValue();
PdfName asName = arr.getAsName(1); // /Fit
arr.set(1, FitR);
//System.out.println();
arr.setModified();
}
}
However, this code fails to work against my example file and has other flaws as well.
Most importantly, it tries to deal with one type of zoom (/Fit), but other types (/XYZ and so on) should also be handled with. Second, I don't know how to get the page number of named destination as key pair named of destination and its zoom value doesn't seem to have this information. Please see a screenshot of debug session below:
Note, at SO there is already a question dealing with exactly the same topic. The thing is the answer to that question give too little information to deal with this problem.
I want to add a numberpad to JavaFX's virtual keyboard.
I've tried several other solutions (including using a keyboard from GitHub or trying JavaFX's numeric virtual keyboard), but this would be the easiest and most practical.
I found the text file (com.sun.scene.control.skin.TextBoard.txt) that is read by com.sun.scene.control.skin.FXVKSkin.class to create the normal keyboard. I added the numpad, and it works fine. However, I want to do this without actually editing the JRE.
This is the relevant part of FXVKSkin.java that loads the keyboard.
private List<List<Key>> loadBoard(String type) {
List<List<Key>> tmpBoard = boardMap.get(type);
if (tmpBoard != null) {
return tmpBoard;
}
String boardFileName = type.substring(0,1).toUpperCase() + type.substring(1).toLowerCase() + "Board.txt";
try {
tmpBoard = new ArrayList<List<Key>>(5);
List<Key> keys = new ArrayList<Key>(20);
InputStream boardFile = FXVKSkin.class.getResourceAsStream(boardFileName);
BufferedReader reader = new BufferedReader(new InputStreamReader(boardFile));
Alternatively, would I be able to just keep TextBoard.txt in my project's classpath and somehow point to that copy instead of the one within the JRE when FXVKSkin.java says "FXVKSkin.class.getResourceAsStream("TextBoard.txt")?
I found a solution!
I took jre/lib/ext/jfxrt.jar, which is the jar file in which com.sun.scene.control.skin.TextBoard.txt resides, and copied it into my project's working directory. I deleted everything within the copy except for the path com/sun/javafx/scene/control/skin/TextBoard.txt, and added "-Xbootclasspath/a:jfxrt.jar" as a boot option. I am still on Java 8, so this might not work for later versions, but it's working for me.
I want to write a Gradle plugin which can inspect an eclipse workspace directory and iterate over the open projects within the workspace and determine the location of each.
Something like
Workspace workspace = EclipseUtils.parseWorkspace("c:/myEclipseWorkspace");
Collection<Project> projects = workspace.getProjects();
for (Project project : projects) {
System.out.println(String.format("name=%s, location=%s, open=%s",
project.getName(), project.getLocation(), project.isOpen()));
}
I've looked at my workspace and can see some .location files under c:\myEclipseWorkspace\.metadata\.plugins\org.eclipse.core.resources\.projects\
But these files are a custom binary format
Is there an eclipse API that I can invoke to parse these? Or some other solution to iterate the open projects in a workspace.
Please note that I want to do this externally to eclipse and NOT within an eclipse plugin.
Reading the Private Description to Obtain Location
Since you are writing in Java, then reuse the Eclipse code from your external location.
i.e. Pull out some of the key code from org.eclipse.core.resources.ResourcesPlugin. Start with the impl of org.eclipse.core.resources.ResourcesPlugin.getWorkspace() and then work your way to org.eclipse.core.resources.IWorkspaceRoot.getProjects()
The above code reads the project description here: org.eclipse.core.internal.resources.LocalMetaArea.readPrivateDescription(IProject, ProjectDescription) and that is called from org.eclipse.core.internal.localstore.FileSystemResourceManager.read(IProject, boolean) which has some logic about default locations.
This is the joy of EPL, as long as your new program/feature is EPL you can reuse Eclipse's core code to do new and wonderful things.
Reading Workspace State to Obtain Open/Close State
When reading workspace state, you are moving into the ElementTree data structures. Reading this without using the ElementTree classes is probably unrealistic. Using the ElementTree classes without full OSGi is probably unrealistic. I provide the following notes to help you on your way.
Working backwards:
ICoreConstants.M_OPEN is the flag value indicating project is open or closed (set for open, clear for closed)
M_OPEN is tested when Project.isOpen() is called
The flags at runtime are in ResourceInfo.flags
The flags are loaded by ResourceInfo.readFrom() called from SaveManager.readElement()
The DataInput input passed to readElement is from the Element Tree stored in the workspace meta directory in .metadata/.plugins/org.eclipse.core.resources/.root/<id>.tree. The specific version (id) of the file to use is recorded in the safe table .metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources
The safe table is part of the SaveManager's internal state stored in a MasterTable
I've managed to parse the file using this as a reference
protected Location parseLocation(File locationFile) throws IOException {
String name = locationFile.getParentFile().getName();
DataInputStream in = new DataInputStream(new FileInputStream(locationFile));
try {
in.skip(ILocalStoreConstants.BEGIN_CHUNK.length);
String path = in.readUTF();
int numRefs = in.readInt();
String[] refNames = new String[numRefs];
for (int i = 0; i < numRefs; ++ i) {
refNames[i] = in.readUTF();
}
in.skipBytes(ILocalStoreConstants.END_CHUNK.length);
return new Location(name, path, refNames);
} finally {
in.close();
}
}
Unfortunately this doesn't seem to be able to detect if a project is closed or not. Any pointers on getting the closed flag would be much appreciated
I want output in the following format, which we get in as400 when WRKSPLF is executed
I am using the following code for retrieving the information from as400
try
{
AS400 as400System = new AS400();
String strSpooledFileName;
SpooledFileList splfList = new SpooledFileList(as400System);
splfList.openAsynchronously();
splfList.waitForListToComplete();
Enumeration enume= splfList.getObjects();
ArrayList<SpoolVO> list = new ArrayList<SpoolVO>();
while( enume.hasMoreElements() )
{
SpoolVO splVO = new SpoolVO();
SpooledFile splf = (SpooledFile)enume.nextElement();
if (splf != null)
{
// output this spooled file's name
splVO.setFileName(splf.getStringAttribute(SpooledFile.ATTR_SPOOLFILE));
splVO.setUserName(splf.getStringAttribute(SpooledFile.ATTR_JOBUSER));
splVO.setUserData(splf.getStringAttribute(SpooledFile.ATTR_USERDATA));
splVO.setDevice(splf.getStringAttribute(SpooledFile.ATTR_OUTPUT_QUEUE));
splVO.setTotalPages(splf.getIntegerAttribute(SpooledFile.ATTR_PAGES));
splVO.setCurrentPage(splf.getIntegerAttribute(SpooledFile.ATTR_CURPAGE));
splVO.setCopy(splf.getIntegerAttribute(SpooledFile.ATTR_COPIES));
list.add(splVO);
}
}
splfList.close();
Now by using the above code I am able to get all the fields except the Options(Opt). I want Options field in java which enables me to do all the operations like send, change, hold, etc. as specified in screenshot.
Is this possible doing with java??
Thanks in advance.
Guessing that you are using JT400 you would use SpooledFileList and SpooledFile to get the details you want. Edit your question to explain the specific details you want to retrieve. Post the code you tried.
Edit:
The Options field is not an attribute of a spooled file; you can't retrieve it from anywhere. It is a field on the display panel that lets the user request an action to be performed by the WRKSPLF command. You will need to provide that functionality within your Java program. For example, if your end user types a 3, you would issue the HLDSPLF command. If she types a 6, you would issue the RLSSPLF command.
I've actually got an Windows/Java Question. I've got a plugged-in device which I want to access via Java. Normally you can access an e.g. USB-Stick via the Drive letter... but this tablet is displayed by Windows as a "Portable Device"... which means, that the Path is something like "Computer\Archos 5S" and there is no Drive letter.
I want to access a file on this device via Java, but I am not able to figure out the correct path to it. There is a similar question out there, but without a productive answer. Or is there another way to access this device via Java?
Actually I've not solved this problem... I am still not able to access such a device via java.
At the moment I am trying to access a windows ShellFolder in Java.
A Shellfolder like: "Shell:::{35786D3C-B075-49b9-88DD-029876E11C01}"
Is this possible with Java?
Recently I uncovered the sun.awt class "ShellFolder"... is this the wanted feature?
thanks for your help
Ripei
The solution to above problem using JMTP library on https://code.google.com/p/jmtp/
Here is my code
package jmtp;
import be.derycke.pieter.com.COMException;
import be.derycke.pieter.com.Guid;
import java.io.*;
import java.math.BigInteger;
import jmtp.PortableDevice;
import jmtp.*;
public class Jmtp {
public static void main(String[] args) {
PortableDeviceManager manager = new PortableDeviceManager();
PortableDevice device = manager.getDevices()[0];
// Connect to my mp3-player
device.open();
System.out.println(device.getModel());
System.out.println("---------------");
// Iterate over deviceObjects
for (PortableDeviceObject object : device.getRootObjects()) {
// If the object is a storage object
if (object instanceof PortableDeviceStorageObject) {
PortableDeviceStorageObject storage = (PortableDeviceStorageObject) object;
for (PortableDeviceObject o2 : storage.getChildObjects()) {
//
// BigInteger bigInteger1 = new BigInteger("123456789");
// File file = new File("c:/JavaAppletSigningGuide.pdf");
// try {
// storage.addAudioObject(file, "jj", "jj", bigInteger1);
// } catch (Exception e) {
// //System.out.println("Exception e = " + e);
// }
//
System.out.println(o2.getOriginalFileName());
}
}
}
manager.getDevices()[0].close();
}
}
Do not forget add jmtp.dll files (that comes up with jmtp download) as a native library. For more info, see my answer on Including Native Library in Netbeans.
Like *nix systems, all devices (including drives) have paths that are part of a common root, this is normally hidden from users because they use the drive letters which are aliases to these fundamental paths, but you can also use full device paths by prefixing the path with "\\.\"
For instance, on my machine D: translates as "\Device\HarddiskVolume1" and can be accessed by passing "\\.\HarddiskVolume1" to CreateFile.
So the path to your device is probably "\\.\Archos 5s".
you can always download and install the Windows mobile developer Powertoys (http://www.microsoft.com/download/en/details.aspx?id=10601) and copy from and to the device using the command line utility cecopy, which you can run from any programming language. There are other options there too, but it's most targeted at .Net