Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Vista Newsgroups > Vista security

Vista - PDH library can not be accessed through Vista 64 bit .

Reply
 
Old 04-16-2007   #1 (permalink)
bhadra


 
 

PDH library can not be accessed through Vista 64 bit .

Hi ,

I was trying to get processor related information through PDH
library . This works well on all platform but in Vista 64 bit , I have
some problem .
Here is my code :
===============
Sample.java
===============
class Sample
{
//Declaring native method
public native int queryCPU ();
static
{
//loading the myLibrary DLL
System.loadLibrary("CPULoad");
}
}
================
SampleApp.java
================
class SampleApp
{
public static void main(String args[])
{
System.out.println("Calling main method of main");
int result = new Sample().queryCPU();

}
}

=============
Compile the two files
===============
javac *.java

==================
Create .h file for CPP Application
==================
javah -jni Sample

This creates a Sample.h file

==================
Create a DLL called CPULoad.dll with this following .c file
==============
#include <jni.h>
#include "sample.h"
#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <tchar.h>
#include <pdh.h>
#include <pdhmsg.h>


JNIEXPORT jint JNICALL
Java_Sample_queryCPU (JNIEnv *env, jobject obj)
{
printf ("Native method implementation!\n");
while (1)
{
PDH_STATUS status;
HQUERY perfQuery = NULL;
HCOUNTER uptimeCounter;
//char uptimeCounterPath[] = "\\\\.\\System\\System Up Time";
//char uptimeCounterPath[] = "\\Memory\\Pages/sec";
char uptimeCounterPath[] = "\\Processor(_Total)\\% Processor
Time";
PDH_FMT_COUNTERVALUE uptimeValue;
//.......................
int seconds = 0;
//
// Create a PDH query
//
if( PdhOpenQuery(NULL, 0, &perfQuery ) != ERROR_SUCCESS )
{
printf ("PdhOpenQuery failed");
return FALSE;
}

if (perfQuery == NULL)
{
printf ("perfQuery failed");
return FALSE;
}
//
// Associate the uptime counter with the query
//
status = PdhAddCounter(perfQuery, uptimeCounterPath,
0, &uptimeCounter );
if( status != ERROR_SUCCESS )
{
printf ("PdhAddCounter failed");
return FALSE;
}


status = PdhCollectQueryData( perfQuery );
if( status != ERROR_SUCCESS )
{
printf ("PdhCollectQueryData123 failed");
return FALSE;
}

Sleep(2000);
status = PdhCollectQueryData( perfQuery );
if( status != ERROR_SUCCESS )
{
printf ("PdhCollectQueryData123 failed");
return FALSE;
}

//
// Get the formatted counter value
//

status = PdhGetFormattedCounterValue( uptimeCounter,
PDH_FMT_LARGE , NULL, &uptimeValue );
if( status != ERROR_SUCCESS )
{
printf ("PdhGetFormattedCounterValue failed");
return FALSE;
}
//
// Close the query
//
PdhCloseQuery( &perfQuery );

seconds = (DWORD) (uptimeValue.largeValue);
printf ("System Up time =%d\n",uptimeValue.longValue);
Sleep(15);

}
return 1;
}

================================
Note that to link this file you need to put pdh.lib in the path . I
build it on Visual Studio 6 SP5 .

Now copy CPUload.dll , Sample.class and SampleApp.class in some
directory say C:\temp.

Run this on XP , 2003 etc etc
java SampleApp
This will produce an oulput like this :
====================================
Calling main method of main
Native method implementation!
System Up time =63
System Up time =22
System Up time =46
System Up time =30
System Up time =33
System Up time =67
System Up time =16
System Up time =28
System Up time =40
System Up time =3
System Up time =69
System Up time =17
=========================================

Now logon to Vista 64 bit box as an user who has administrative
priviledges .

Create a temp directory .
Put the above 3 files under the temp directory .
and run java SampleApp

This will produce the follwoing output :
=============================
Calling main method of main
Native method implementation!
PdhCollectQueryData123 failed
================================

I tried to build with the dll with mt.exe that comes with VC 8
my manifest file looks like this :
=======================
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator"></
requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
==========================

and then I linked it like this :
mt.exe -manifest CPUload.dll.manifest -outputresource:CPUload.dll;2

Still I am getting the same output .

Let me know on how could I troubleshoot this ?

Thanks,
Abhijit


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
nothing can be accessed in vista 64 General Discussion
Can Vista remember the last folder accessed? Vista General
After Vista upgrade, 2nd HD can't be accessed Vista hardware & devices
WMP11 - can no longer find library or add to library Vista music pictures video
Windows Vista installer service cannot be accessed Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46