baldeagle wrote:
I am trying to rebuild a program I origianlly created in VB 6 in Java. I am trying to obtain the tick count contained within Windows. I know there is a a currentSecondMills() method but it is for current time on the system.
The tick count stores how long the pc has been running during a session (i.e. how long since it was last booted). I have heard that it can be used with Java like any other method but I cannot find any information on its use in the Java forum from sun.com.
If anyone can provide any information it would be greatly appreciated.
Sorry this took so long - having a crappy day today.
Anyways, post the section of VB code that you used to obtain the tick count. I'm no windows internals guru, and I don't know diddly about the windows libraries (except that everyone seems to hate them), so that might help point things in the right direction. Java lets you gather quite a bit of system information easily with Properties and Runtime (see the code below), but I don't think there is a way to get at the 'tick count' directly from the Java API.
Possible solutions are calling GetTickCount() using JNI, execute a native command like systeminfo (and get rid of the extra info - easier, but slower), or if windows stores this info in a file, just read it in from there (again, easier and slower). You might be able to read it in directly from the registry - never tried it. Additionally, COBRA might offer something here, but I know diddly-squat about COBRA.
edit: OK - brain is working again. Amazing what a little pizza and beer can do to help you forgot a bad day.

This version gathers system information from three places: first, it gets system properties using the System.getProperties() method in the Java API; second, it gets runtime information using the Runtime instance; finally, it makes executes the systeminfo windows command as a seperate process and acquires additional system info, including the uptime. Since it is a seperate process, it could be threaded and ran concerrently with the other two - might save a few miliseconds.
Yeah, looks like I need to change my host name from amd700 to amd2600 now. Do you get some kind of brownie prize for the longest post ever? I even tried to make the font smaller, but it doesn't work seem to work inside of a code or quote block - sorry about teh length.
Code:
import java.io.*;
import java.util.*;
public class SysInfo {
public static void main(String[] args) {
System.out.println("System Properties");
System.out.println("-----------------");
System.getProperties().list(System.out);
Runtime r = Runtime.getRuntime();
System.out.println();
System.out.println("Runtime Information");
System.out.println("-------------------");
System.out.println("num processors: " + r.availableProcessors());
System.out.println("Total jvm memory: " + r.totalMemory()/1024 + " KB");
System.out.println("Free jvm memory: " + r.freeMemory()/1024 + " KB");
if (r.maxMemory() == Long.MAX_VALUE)
System.out.println("No maximum memory limit set");
else
System.out.println("Max.jvm memory: " + r.maxMemory()/1024 + " KB");
try {
DataInputStream in = new DataInputStream(r.exec("systeminfo").getInputStream());
String s = in.readLine();
StringBuffer sb = new StringBuffer();
while (s != null) {
sb.append(s);
sb.append("\n");
s = in.readLine();
}
System.out.println();
System.out.println("Systeminfo Command");
System.out.println("-------------------");
System.out.println(sb.toString());
}
catch (IOException e) {
e.printStackTrace();
}
System.out.println("finsihed SysInfo");
System.exit(0);
}
}
Output wrote:
System Properties
-----------------
-- listing properties --
java.runtime.name=Java(TM) 2 Runtime Environment, Stand...
sun.boot.library.path=C:\Program Files\Java\j2re1.4.2\bin
java.vm.version=1.4.2-b28
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
user.country=US
sun.os.patch.level=Service Pack 1
java.vm.specification.name=Java Virtual Machine Specification
user.dir=C:\Documents and Settings\Larry\Deskt...
java.runtime.version=1.4.2-b28
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files\Java\j2re1.4.2\lib\e...
os.arch=x86
java.io.tmpdir=C:\DOCUME~1\Larry\LOCALS~1\Temp\
line.separator=
java.vm.specification.vendor=Sun Microsystems Inc.
user.variant=
os.name=Windows XP
sun.java2d.fontpath=
java.library.path=C:\WINDOWS\system32;.;C:\WINDOWS\Syst...
java.specification.name=Java Platform API Specification
java.class.version=48.0
java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFac...
os.version=5.1
user.home=C:\Documents and Settings\Larry
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=Cp1252
java.specification.version=1.4
user.name=Larry
java.class.path=C:\Documents and Settings\Larry\Deskt...
java.vm.specification.version=1.0
sun.arch.data.model=32
java.home=C:\Program Files\Java\j2re1.4.2
java.specification.vendor=Sun Microsystems Inc.
user.language=en
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode
java.version=1.4.2
java.ext.dirs=C:\Program Files\Java\j2re1.4.2\lib\ext
sun.boot.class.path=C:\Program Files\Java\j2re1.4.2\lib\r...
java.vendor=Sun Microsystems Inc.
file.separator=\
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport...
sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.cpu.isalist=pentium i486 i386
Runtime Information
-------------------
num processors: 1
Total jvm memory: 1984 KB
Free jvm memory: 1844 KB
Max.jvm memory: 65088 KB
Systeminfo Command
------------------
Host Name: AMD700
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Uniprocessor Free
Registered Owner: AMD700
Registered Organization: CSUF
Product ID: xxx
Original Install Date: 6/29/2004, 4:01:09 AM
System Up Time: 1 Days, 11 Hours, 28 Minutes, 3 Seconds
System Manufacturer: Ssystem manufacturer
System Model: System product name
System type: X86-based PC
Processor(s): 1 Processor(s) Installed.
[01]: x86 Family 6 Model 8 Stepping 1 AuthenticAMD ~2079 Mhz
BIOS Version: A M I - 11000325
Windows Directory: C:\WINDOWS
System Directory: C:\WINDOWS\System32
Boot Device: \Device\HarddiskVolume1
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (GMT-08:00) Pacific Time (US & Canada); Tijuana
Total Physical Memory: 447 MB
Available Physical Memory: 85 MB
Virtual Memory: Max Size: 1,602 MB
Virtual Memory: Available: 881 MB
Virtual Memory: In Use: 721 MB
Page File Location(s): c:\pagefile.sys
Domain: xxx
Logon Server: xxx
NetWork Card(s): 1 NIC(s) Installed.
[01]: NVIDIA nForce Networking Controller
Connection Name: Local Area Connection 3
DHCP Enabled: Yes
DHCP Server: 192.168.1.1
IP address(es)
[01]: 192.168.1.xxx
Finsihed SysInfo