June 7th, 2007

How do I inflate a bicycle tire with a potato?

I see this all the time.

People have a problem and have already decided what technology they’re going to use to solve it, and then they hit a roadblock: The technology they picked is unsuited to the problem!

How do I put my laptop into standby mode from VBScript?

How do I change the user’s mouse acceleration from a batch file? I changed the registry values but it doesn’t take effect immediately.

The functionality you seek is implemented in native code via Win32. At the end of the day, the solution involves calling SetSystemPowerState or SystemParametersInfo(SPI_SETMOUSE), since those are the functions that actually do the work.

There’s no law that forbids writing programs in C or C++, particularly since that’s the target language for the native bits of Win32. Go ahead, write that program, and then call it from your batch file.

Now, it’s possible that you can get somebody else to play middle-man for you. For example, if you wanted to shut down the computer, you can get the shutdown.exe program to help out. And if you had chosen wisely, the technology you already decided upon may wrap the Win32 functionality inside a helper function or class, or it may provide a way of calling into native Win32 code. For example, your Visual Basic program could just call SetSystemPowerState via a platform invoke:

<DllImport("kernel32.dll")>
Public Shared Function SetSystemPowerState(_
      fSuspend As Boolean, _
      fForce As Boolean) As Boolean
SetSystemPowerState(True, False)

(Note: I don’t speak Visual Basic, so I may have gotten the details wrong, but I hope you get the idea.)

Topics
Other

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.