Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Page 1 of 2 1 2 >
Topic Options
#347731 - 04/10/2011 18:56 Anyone got any *old* Windows driver development kits?
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
I've got PWRTEST.EXE from the Windows driver development kit at my disposal. It comes with the "tools" part of the install. This command-line utility will put the machine to sleep (s:3) or hibernate (s:4) and then automatically wake it up again after a set interval. As you might imagine, this is incredibly useful for automated software testing. I use it every day.

However, the version I've got refuses to run on anything older than Windows Vista. It requires OS version 6.x, so it won't run on XP. I've heard that older xp-compatible versions exist in older development kits, but I don't have access to them. Anyone have that? (I don't need the whole dev kit, just PWRTEST.EXE.)

NOTE: For XP, I have been running a tool called "Sleeper" from PassMark, but the latest version of this tool has another bug that I'm having trouble working around right now. I was only running Sleeper to work around the "pwrtest won't run on XP" bug, and now that Sleeper has a bug, I want to see if I can go back to pwrtest.
_________________________
Tony Fabris

Top
#347757 - 05/10/2011 06:58 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
The Windows XP Driver Development Kit is available from MSDN subscriber downloads. It's second from bottom of the Operating Systems / Windows XP section.
_________________________
-- roger

Top
#347760 - 05/10/2011 09:17 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
Originally Posted By: tfabris
I've heard that older xp-compatible versions exist in older development kits, but I don't have access to them. Anyone have that? (I don't need the whole dev kit, just PWRTEST.EXE.)


I've just downloaded and installed the XP DDK. It does not contain PWRTEST.EXE. I can even tell you why: the Power IRPs needed for most of what PWRTEST does don't actually exist pre-Vista. In the past, I've had to write a device driver that poked around in undocumented structures to implement some of what it does.

That said: the go-to-sleep-and-wake-up-again functionality should work fine on XP; it's just that it doesn't appear to be in a canned utility in the DDK.
_________________________
-- roger

Top
#347761 - 05/10/2011 09:31 Re: Anyone got any *old* Windows driver development kits? [Re: Roger]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
Originally Posted By: Roger
That said: the go-to-sleep-and-wake-up-again functionality should work fine on XP


Not tested (or even compiled):

Code:
#define SUSPEND_SLEEP TRUE
#define SUSPEND_HIBERNATE FALSE

const LONGLONG FILETIME_UNITS_PER_MICROSECOND = 10;
const LONGLONG FILETIME_UNITS_PER_MILLISECOND = FILETIME_UNITS_PER_MICROSECOND * 1000;
const LONGLONG FILETIME_UNITS_PER_SECOND = FILETIME_UNITS_PER_MILLISECOND * 1000;

int _tmain(int argc, _TCHAR* argv[])
{
	BOOL fSuspend = SUSPEND_SLEEP;
	BOOL fForce = FALSE;
	DWORD delaySeconds = 90;

	HANDLE hToken;
	::OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken);

	LUID privilegeId;
	LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &privilegeId);

	TOKEN_PRIVILEGES privs;
	privs.PrivilegeCount = 1;
	privs.Privileges[0].Luid = privilegeId;
	privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

	::AdjustTokenPrivileges(hToken, FALSE, &privs, sizeof(TOKEN_PRIVILEGES), NULL, 0);
	HANDLE hTimer = ::CreateWaitableTimer(NULL, FALSE, NULL);

	SYSTEMTIME systemTime;
	GetSystemTime(&systemTime);

	FILETIME fileTime;
	SystemTimeToFileTime(&systemTime, &fileTime);

	LARGE_INTEGER wakeTime;
	wakeTime.LowPart = fileTime.dwLowDateTime;
	wakeTime.HighPart = fileTime.dwHighDateTime;

	wakeTime.QuadPart += delaySeconds * FILETIME_UNITS_PER_SECOND;

	::SetWaitableTimer(hTimer, &wakeTime, 0, NULL, NULL, TRUE);
	::SetSystemPowerState(fSuspend, fForce);

	return 0;
}

_________________________
-- roger

Top
#347783 - 05/10/2011 15:25 Re: Anyone got any *old* Windows driver development kits? [Re: Roger]
siberia37
old hand

Registered: 09/01/2002
Posts: 702
Loc: Tacoma,WA
There is nothing better than low-level Windows API in the morning. Can you write some code to set ACL permissions on a file next? I tried that once and almost cried..

Top
#347819 - 06/10/2011 06:44 Re: Anyone got any *old* Windows driver development kits? [Re: siberia37]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
Originally Posted By: siberia37
There is nothing better than low-level Windows API in the morning. Can you write some code to set ACL permissions on a file next? I tried that once and almost cried..


SetEntriesInAcl is the not-quite-so-low-level way to do it.
_________________________
-- roger

Top
#347821 - 06/10/2011 14:15 Re: Anyone got any *old* Windows driver development kits? [Re: Roger]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
Originally Posted By: Roger
Not tested (or even compiled)


Although, thinking about it, Windows might not wake up unless someone's actually waiting on the timer. Chuck a WaitForSingleObject(hTimer, INFINITE) in there...
_________________________
-- roger

Top
#347823 - 06/10/2011 18:43 Re: Anyone got any *old* Windows driver development kits? [Re: Roger]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
Originally Posted By: Roger
Originally Posted By: Roger
Not tested (or even compiled)


Although, thinking about it, Windows might not wake up unless someone's actually waiting on the timer. Chuck a WaitForSingleObject(hTimer, INFINITE) in there...


Thank you so much, Roger! This is awesome. I'll give this all a try shortly, when I get the chance. In the meantime, I've worked around the bug in the Sleeper.exe program, but I still want to try this one instead.
_________________________
Tony Fabris

Top
#347825 - 06/10/2011 21:10 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
Hm, can't get it to compile without any errors. I'm using Visual Studio 2008 and targeting a Win32 Console app. It's whining about basically every line, so clearly I'm doing something wrong. :-)
_________________________
Tony Fabris

Top
#347839 - 07/10/2011 06:45 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
Originally Posted By: tfabris
Hm, can't get it to compile without any errors. I'm using Visual Studio 2008 and targeting a Win32 Console app. It's whining about basically every line, so clearly I'm doing something wrong. :-)


Yeah, you're missing some header files. Anyway: https://bitbucket.org/rlipscombe/spikes

Tested on Windows Vista (since I don't have an XP machine handy).
_________________________
-- roger

Top
#347862 - 07/10/2011 15:41 Re: Anyone got any *old* Windows driver development kits? [Re: Roger]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
Heh. Awesome. Grabbing now. :-) :-) :-)
_________________________
Tony Fabris

Top
#347863 - 07/10/2011 15:52 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
Compiles great, works great on the Vista system, copying over to the XP system to try it out.
_________________________
Tony Fabris

Top
#347864 - 07/10/2011 16:05 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
XP system goes to sleep on command, but does not automatically wake up again, increasing the 15-second timer to see if that's the reason.
_________________________
Tony Fabris

Top
#347865 - 07/10/2011 16:26 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
Ross Wellington
enthusiast

Registered: 21/02/2006
Posts: 325
Hi,

Some motherboards had a hard time "waking up" as you describe. My older Core2Duo system had that exact problem as you describe. Ended up leaving on all of the time unit I was able to replace it. My other systems never seemed to have that problem.

Ross
_________________________
In SI, a little termination and attention to layout goes a long way. In EMC, without SI, you'll spend 80% of the effort on the last 3dB.

Top
#347869 - 07/10/2011 17:01 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
Increased 15 second timer to 35, XP system wakes up on command as expected, but the laptop's internal/external display configuration is not set correctly on wake-up and I must press the FN+F4 key to get the screen to come back on. Interesting.

Additional interestingness. When I use your Doze program, it does not induce this problem, but using PassMark Sleeper induces that problem. (But the screen is working when Sleeper wakes up.) I wonder what's different about the two?
_________________________
Tony Fabris

Top
#347873 - 07/10/2011 19:28 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
Okay, it turns out that it's any key on the keyboard, or any mouse move, to get the monitor to turn back on, after Doze has suspended, waited, and then resumed the system. The system resumes with the monitor black, Doze finishes its run, monitor still black. Then I press a key (including Shift) or I move the mouse and then the screen lights up.

This explains why it didn't induce that other problem... The other problem was also solved by keystrokes or mouse moves.

Anyway, I tried...
- Ghosting mouse moves to get the monitor to turn on. No dice.
- SendMessage(HWND_BROADCAST, WM_SYSCOMMAND , SC_MONITORPOWER , MONITOR_ON ); No dice.
_________________________
Tony Fabris

Top
#347884 - 08/10/2011 05:06 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
Originally Posted By: tfabris
to get the monitor to turn back on


Try SetThreadExecutionState(ES_DISPLAY_REQUIRED).
_________________________
-- roger

Top
#347956 - 10/10/2011 17:01 Re: Anyone got any *old* Windows driver development kits? [Re: Roger]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
Alas, that also did not do the trick. I added the following line in int _tmain right after DWORD delaySeconds = 30; :

SetThreadExecutionState(ES_DISPLAY_REQUIRED);

Same result: Screen is off after resume from suspend. Must move mouse or press key to see screen.
_________________________
Tony Fabris

Top
#347966 - 11/10/2011 06:43 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
Originally Posted By: tfabris
right after DWORD delaySeconds = 30;


If you think about what that line's actually saying -- "I need the display" -- you'll see that it's probably better (though I'm not saying it'll definitely work; it's been a while since I delved into the vagaries of Windows power management) to put it right after the WaitForSingleObject(..., INFINITE) completes -- i.e. once the computer's woken up again.
_________________________
-- roger

Top
#347977 - 11/10/2011 19:05 Re: Anyone got any *old* Windows driver development kits? [Re: Roger]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
That seems to have done the trick! smile

I didn't think I needed to put that line at the end of the program run because I thought it was a perpetual thing: The app setting a flag saying that this particular application has a feature that needs the display all the time. I hadn't realized it would be like a trigger.

Anyway, it's working now and I think I'll be using this instead of PassMark Sleeper once I parameterize it (timer value and sleep/hibernate choice).

Thanks!
_________________________
Tony Fabris

Top
#348009 - 12/10/2011 17:33 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
Hmph. Having trouble parameterizing it because I can't for the life of me figure out how to properly reference and manipulate the _TCHAR* argv[]. Every time I try to do something with it, such as convert the string to an integer (so I can use a parameter for the number of timer seconds) it says "cannot convert parameter 1 from '_TCHAR **' to 'const wchar_t *'".

If I change the main() function so that it's not using the _T macros at all, then the rest of the program breaks.

I'd love to know the "right" way to handle that situation. Everything I've seen on the internet looks like a kludge to me. I just want to take the values in the arguments and turn them into integer or DWORD numbers so I can use them in the main code as case statements in a switch, or as the Seconds variable.
_________________________
Tony Fabris

Top
#348011 - 12/10/2011 17:46 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
As long as you're still using asterisks in your code, you're going to be manipulating the original data structure, which is probably bad juju.

Chances are that if you want to manipulate the data, you want to pull it out into its own variable, probably using strcpy() or equivalent.

That said, atoi(), for example, doesn't require manipulating the original data.
_________________________
Bitt Faulk

Top
#348013 - 12/10/2011 18:02 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
peter
carpal tunnel

Registered: 13/07/2000
Posts: 4180
Loc: Cambridge, England
Originally Posted By: tfabris
Every time I try to do something with it, such as convert the string to an integer (so I can use a parameter for the number of timer seconds) it says "cannot convert parameter 1 from '_TCHAR **' to 'const wchar_t *'".

Is that the exact error? Because those two types are indeed very different: one is a pointer to a character, one is a pointer to a pointer. If you posted some code, we'd have a better chance of seeing why that confusion has arisen: at a guess, you're doing something like calling _tcstoul(argv,NULL,10) instead of _tcstoul(argv[1],NULL,10). Argv, don't forget, isn't a string: it's an array of strings.

Peter

Top
#348014 - 12/10/2011 18:21 Re: Anyone got any *old* Windows driver development kits? [Re: peter]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
I mean:

The code you supplied has a main statement that looks like this:

int _tmain(int argc, _TCHAR* argv[])
{
...
}

Now I want to add stuff to the code to do something with argv[2]. For example, convert it to an integer so I can use it in a switch statement. So in my code I go like this:

if (argc <2)
{
_tprintf(_T("Wrong number of arguments.\n\n"));
return 0;
}

int nTempSuspendType;
nTempSuspendType = atoi(argv[2]);
switch (nTempSuspendType)
...

And that's when I start getting all the type errors, right around the atoi statement. I have been scouring the internet for ways to handle the type conversion, I've found about a dozen different ways, tried them all, and they all either produce the same errors, or they cause the program to crash into the debugger when I run it.

If I change the main statement to this:
int main(int argc, char* argv[])
{
...
}

Then everything I do makes the program crash into the debugger.
_________________________
Tony Fabris

Top
#348015 - 12/10/2011 19:13 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
Found something on the internet that says he TCHAR equivalient for atoi() is _ttoi(). But when I try to use that, it breaks into the debugger at the line where I use it.

int nTempSuspendType;
nTempSuspendType = _ttoi(argv[2]);
_________________________
Tony Fabris

Top
#348017 - 12/10/2011 20:07 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
peter
carpal tunnel

Registered: 13/07/2000
Posts: 4180
Loc: Cambridge, England
Tony, you aren't a screenwriter on "Lost". You can give us all the information in one post and it won't count as a spoiler: code and corresponding error message, or crash and corresponding command-line.

Your snippet with _ttoi looks correct, as long as the program has been invoked with at least two parameters. How did you invoke it in that case (i.e. what was the command-line)? Why did it enter the debugger -- is argv[2] NULL? One way to tell is by _tprintf'ing it before you call _ttoi: _tprintf(argv[2] ? argv[2] : _T("NULL")). What does argc equal?

Remember that if argc is 2, only argv[0] and argv[1] are valid strings (but argv[2] is guaranteed to be NULL, only argv[3] and beyond are undefined). If you expect argv[2] to be non-NULL, you should be testing that argc is at least 3.

Peter

Top
#348018 - 12/10/2011 20:27 Re: Anyone got any *old* Windows driver development kits? [Re: peter]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
Originally Posted By: peter
Your snippet with _ttoi looks correct, as long as the program has been invoked with at least two parameters.


I'm so stupid. I'm going to go bury my head in the sand.

It's a zero based index problem. And (correct me if I'm wrong) the fact that the argc parameter is a count which is different from the index into the argv array.

argc is the count. Which is, in my case "2". Because the first parameter is the EXE name and the second parameter is my parameter I typed in. My "if" statement works and prevents the program from continuing if you didn't put in at least one parameter.

So, with argc happily at a count of "2", and validated as such, I go on to read the second parameter of the array. Since I just validated the count at "2", I should be able to read argv[2] right? There's just no way it could try to read past the end of THAT ZERO-BASED-INDEXED ARRAY could it?

Gah. :-)

It's working now. I'm so stupid.
_________________________
Tony Fabris

Top
#348027 - 13/10/2011 04:21 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
Originally Posted By: tfabris
There's just no way it could try to read past the end of THAT ZERO-BASED-INDEXED ARRAY could it?


Hey, look everyone: a BASIC programmer. wink
_________________________
-- roger

Top
#348029 - 13/10/2011 10:17 Re: Anyone got any *old* Windows driver development kits? [Re: Roger]
andy
carpal tunnel

Registered: 10/06/1999
Posts: 5916
Loc: Wivenhoe, Essex, UK
He'll be trying to use redim preserve next wink
_________________________
Remind me to change my signature to something more interesting someday

Top
#348030 - 13/10/2011 10:39 Re: Anyone got any *old* Windows driver development kits? [Re: tfabris]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
Originally Posted By: tfabris
It's working now. I'm so stupid.


Too stupid to send me a pull request? I'd like to merge your changes. Or at least a patch file... wink
_________________________
-- roger

Top
Page 1 of 2 1 2 >