Get system uptime in Java

In Windows, you can execute the net stats srv command, and in Unix, you can execute the uptime command. Each output must be parsed to acquire the uptime. This method automatically executes the necessary command by detecting the user’s operating system. Note that neither operation returns uptime in millisecond precision. public static long getSystemUptime() throws … Read more

With Java 7 Update 45, the System Properties no Longer Set from JNLP Tag “Property”

We experienced the same Problem with Java 7 Update 45 (1.7.0_45). The JNLP Spec gave a hint for a work-around: Properties set in the jnlp file will normally be set by Java Web Start after the VM is started but before the application is invoked. Some properties are considered “secure” properties and can be passed … Read more

get unique machine id

Maybe the easiest way is. Get the DeviceId Nuget package And use it like string deviceId = new DeviceIdBuilder() .AddMachineName() .AddMacAddress() .AddProcessorId() .AddMotherboardSerialNumber() .ToString(); You can personalize the info used to generate the ID Github Project

File System TreeView

If you wanted to stick with the strings something like this would work… TreeNode root = new TreeNode(); TreeNode node = root; treeView1.Nodes.Add(root); foreach (string filePath in myList) // myList is your list of paths { node = root; foreach (string pathBits in filePath.Split(“https://stackoverflow.com/”)) { node = AddNode(node, pathBits); } } private TreeNode AddNode(TreeNode node, … Read more

Calculating elapsed time in a C program in milliseconds

Best way to answer is with an example: #include <sys/time.h> #include <stdlib.h> #include <stdio.h> #include <math.h> /* Return 1 if the difference is negative, otherwise 0. */ int timeval_subtract(struct timeval *result, struct timeval *t2, struct timeval *t1) { long int diff = (t2->tv_usec + 1000000 * t2->tv_sec) – (t1->tv_usec + 1000000 * t1->tv_sec); result->tv_sec = … Read more

how to detect operating system language (locale) from java code

The Windows XP systeminfo command displays lots of stuff, but the relevant information is this: System Locale: en-us;English (United States) Input Locale: en-us;English (United States) To get equivalent information in Java, use Locale.getDefault() to get the Locale that Java is using, and use methods on the Locale object such as getCountry(), getLanguage() to get details. … Read more

How do I check if an app is a non-system app in Android?

PackageManager pm = mcontext.getPackageManager(); List<PackageInfo> list = pm.getInstalledPackages(0); for(PackageInfo pi : list) { ApplicationInfo ai = pm.getApplicationInfo(pi.packageName, 0); System.out.println(“>>>>>>packages is<<<<<<<<” + ai.publicSourceDir); if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { System.out.println(“>>>>>>packages is system package”+pi.packageName); } }