How do I inflate a bicycle tire with a potato?

Date:June 7, 2007 / year-entry #204
Tags:other
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20070607-00/?p=26523
Comments:    45
Summary: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...

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.)


Comments (45)
  1. BradC says:

    Excellent point. Reminds me of Alex P’s post (linked by my name) called Pounding A Nail: Old Shoe or Glass Bottle?

    "A client has asked me to build and install a custom shelving system. I’m at the point where I need to nail it, but I’m not sure what to use to pound the nails in. Should I use an old shoe or a glass bottle?"

  2. Golden Hammer says:

    rundll32. Problem solved.

    [Um, no. Now you have two problems. -Raymond]
  3. Gnox says:

    >> decided what technology they’re going to use to solve it

    The technology decision is 99% of the time out of question for a number of reasons. If they had put the question differently, the answer would have not satisfied them.

    Q: How do I put my laptop programmatically ?

    A: Use SetSystemPowerState etc etc

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

    A: VBScript does not support that directly. You can however use the xxx.yyy COM Object or write a wrapper yourself which calls SetSystemPowerState using standard VB or C++.

    There’s quite a difference.

    [I realized that my point wasn’t sufficiently clear. The follow-up question is fine, but it should go to a VBScript discussion group. Asking the core development team won’t get you very far since they don’t provide VBScript wrappers. -Raymond]
  4. anonymous says:

    Sorry to tell you, but at least for SetSystemPowerState rundll32 is a valid an excellent solution, since it wraps values into corresponding types.

    rundll32.exe kernel32.dll,SetSystemPowerState 1 1

    or, even better:

    rundll32.exe powrprof.dll,SetSuspendState

    However, wrapping structs and other complex types is not supported.

    [rundll32 does not wrap values into “corresponding” types. I don’t know where people make up this stuff. Rundll32 passes four parameters: HWND, HINSTANCE, LPSTR, and int. You can verify this by writing a test program. -Raymond]
  5. Wang-Lo says:

    How to inflate a bicycle tire with a potato.

    Materials:

    (1) a five-pound sack of potatos, available at any grocery store

    (2) a flexible hose with a valve stem connection, left over from when you broke your previous bicycle pump

    (3) a UPS truck left idling at the curb by its driver, commonly found throughout any modern city

    (4) a ball-point pen — look in your shirt pocket

    Procedure:

    (1) Remove one potato from the sack.  Close the sack.

    (2) Use the pen to drive a hole through the potato.  Long way through is better.

    (3) Force the cut end of the hose through the hole in the potato.  Connect the other end to your valve stem.

    (4) Open the driver’s door of the idling truck and place the sack of potatos on the gas pedal.

    (5) Quickly run around to the back of the truck and jam the potato forcefully into the exhaust pipe.

    Warnings:

    (1) By the time the engine stalls, pressure in the exhaust pipe will reach about 125 psi.  Be careful not to burst your tire.

    (2) Do not stand behind the exhaust pipe.  If the connection fails, bits of flexible hose and hot potato can reach speeds of 1000 fps.

    (3) When the UPS driver finds the sack of potatos, a flat tire will be the least of your worries.

    -Wang-Lo.

  6. Dave says:

    1) Purchase Visual Studio 2005.

    2) Run a wizard to generate TODO-laden code.

    3) Create dialogs as needed.

    4) Fill in the TODOs with your code.

    5) Compile, test, debug, build an installer to deal with dependencies such as a 30MB .NET 2.0 runtime, etc.

    -OR-

    Use VBScript/JScript and WMI (free and on every system since at least Windows 2000) to change the settings. For a lovely interface, use HTAs. Deploy the 800-byte script using advanced techniques such as email, COPY or a USB key.

  7. Let down says:

    Every time I saw this in the pre-blog, my immediate reaction was "Sweet, Raymond’s going to explain how to inflate a bicycle tire with a potato!". You can imagine my disappointment

  8. Jon says:

    Wang-Lo

    I thought your method was going to involve taking pressurized air from one of the tires of the UPS truck.

    Note: In this method bag of potatoes is available for use in discouraging interference from UPS driver.

  9. J says:

    OK Dave, if it’s that easy, show us the script.

  10. Ben Cooke says:

    (Without meaning to pick on Raymond, who quite reasonably noted that he’s not a VB person, but for the benefit of the audience…)

    The example that Raymond provided at the end of this article is actually Visual Basic.NET code using the .NET Platform Invoke feature. The original Visual Basic had a very similar mechanism which would probably look something like this:

    Declare Function SetSystemPowerState Lib "kernel32" Alias "SetSystemPowerState" (ByVal fSuspend As String, ByVal fForce As Boolean) As Boolean

    (I’m not much of a VB person either, but I’m forced by employer to occasionally maintain an ancient VB6 app, so I can roughly remember how to do that.)

    The question given in the article was specifically asking about VBScript, which doesn’t have any mechanism for importing functions from arbitrary DLLs. However, I suspect the question was referring to the use of VBScript in the Windows Script Host, in which case it might well already have an API for doing this, or failing that it can instantiate COM objects so you could (if you’ve got your heart set on Visual Basic) use VB6 or VB.NET to write a COM wrapper library to call from your script.

  11. coditza says:

    Okay, use a c or c++ app where you have to, but that implies you have visual stdion or the express versions. What if, I don’t want to install all of those (let’s say I have all the software I need, licenses and stuff)? Is there anything like the “free” gcc already provided by windows? Why not? It’s so hard to provide a cmd line only compiler for Windows? All I want is an already shipped compiler (and linker) with a minimum library set (heck, with LoadLibrary I am pretty much set). No, you can’t develop commercial applications with it, but for small tools it’s ok.

    [I’m sure the antitrust lawyers would have a field day if Windows came with a copy of Visual C++, even just the command line edition. -Raymond]
  12. Wolf Logan says:

    "Is there anything like the "free" gcc already provided by windows?"

    There’s csc.exe (in C:WindowsMicrosoft.NETFrameworkvXXX), which is a "free" command line C# compiler. Using the same interop mechanism as Raymond points out in his VB.NET sample, you can write a nice, little program to shutdown the computer (or do whatever) using just notepad and csc. You won’t be able to write C++ code, and therefore some of the more esoteric COM techniques won’t be available, but if you need that level of support, you should really grab one of the "real" dev environments.

  13. J says:

    "Okay, use a c or c++ app where you have to, but that implies you have visual stdion or the express versions."

    A simple search for "microsoft command line compiler" will tell you how to obtain cl.exe and set up your build environment.

    I downloaded the platform SDK for Windows XP, clicked "Start | Programs | Microsoft Platform SDK for Windows XP SP2 | Open Build Environment Window | yadda yadda" to open the build environment window.  Then I wrote a program to shut down the PC using SetSystemPowerState (using vi as my editor, but I could have used notepad).  Then I compiled it with "cl test.cpp user32.lib Advapi32.lib".  And it works.  No Visual Studio necessary as far as I can tell.

    Then I deployed it to my Vista laptop by copying the .exe and double clicked it to run it.  Oh yeah, I had to set up a shortcut first to pass a command-line parameter.

  14. David Walker says:

    "All I want is an already shipped compiler"

    No, Coditza, the compiler is not "already shipped" with Windows.

  15. David Walker says:

    Maybe I was wrong… if a compiler actually ships with .NET, as Wolf Logan says.  Interesting.

  16. Wolf Logan says:

    Technically, I suppose it can only be considered "already shipped with Windows" in the case of Vista, which ships .NET on the disk. On the other hand, .NET is available as an optional automatic download via Windows Update, and was included (as a redist package) with at least several commercial apps, so the likelihood of you finding .NET on any given Windows installation is pretty high.

    Every version of .NET, though, has included the csc compiler. And .NET assemblies carry their own metadata, so the equivalent of the Windows header files are also already there. You can do plenty of useful development work "right out of the box" (at least on Vista), but it’s a pretty rough experience compared to Visual Studio.

  17. David Walker says:

    I thought it would have something to do with letting the potato ferment, and produce gases, which would have to build sup sufficient pressure (maybe a lot of pressure), then …

  18. Ulric says:

    Is there anything like the "free" gcc

    already provided by windows?

    not only is the microsoft command-line compiler free, and VC++ Express Edition,

    but ‘gcc’ is also available for Windows as "MinGW"

  19. Archangel says:

    Maybe that says something about the background of the questioner?

    You certainly can set mouse acceleration from a shell script in Unix-like systems via xset. You can also put the machine to sleep from any environment that can write to /sys/power/state in Linux (no doubt that’s different elsewhere, but I can’t remember what it is). Maybe the questioner was used to Unix and thought he could do the same?

    Of course that’s really just an extension to Raymond’s original point – in the environment he’s in, those are potatoes. Doesn’t matter that they might be bicycle pumps elsewhere.

  20. Cooney says:

    [I’m sure the antitrust lawyers would have a field day if Windows came with a copy of Visual C++, even just the command line edition. -Raymond]

    Um, why? Every other sensible OS has shipped with its own dev tools (well, not OS2) for a while now. Windows is the odd man out.

  21. Dean Harding says:

    Every other sensible OS has shipped with its own dev tools (well, not OS2) for a while now.

    They also ship with web browsers, media players and so on and nobody complains. What’s up with that?

  22. Eric says:

    They also ship with web browsers, media players and so on and nobody complains. What’s up with that?

    I’ve always wondered that myself. The average person EXPECTS a system to have this functionality at minimum when buying a new computer anymore. Just because it’s "the bundled" doesn’t mean you have to stay with it. Most people I’ve known learn this pretty quickly, even if they don’t know where to get quality replacements.

  23. Norman Diamond says:

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

    > How do I change the user’s mouse acceleration from a batch file?

    Some of the comments are spot-on, but let’s take a step back and look at why these questions are being asked.  Every Windows system has a command processor for batch files.  Nearly every Windows system has VBScripting.  With these tools it isn’t even necessary to run market surveys to find out if nearly every Windows system has a command line version of MSBuild (with or without anti-trust worries).  Even if someone thinks the batch script command language is ugly, they might want to use it because it’s available.  They might even have learned this reasoning by reading a very famous blog.

    Thursday, June 07, 2007 6:45 PM by Cooney

    Every other sensible OS has shipped with its

    own dev tools (well, not OS2) for a while now.

    Macs didn’t used to do so.  Vista does now.  XP Pro and some versions of Vista can get gcc from Microsoft though they have to do extra downloading to get it.  If I’m not mistaken, both XP Pro and Home can get .Net’s compilers from Microsoft though they have to do extra downloading to get them.  XP Home can’t get Microsoft’s distribution of gcc.

  24. Angstrom says:

    Norman: It’s not gcc; I’m sure there’s someone at Microsoft whose job it is (in some sense) to prevent any GNU/FSF programs from shipping with Windows.  Very likely a lawyer.

    Stu: that’s exactly the sort of shortsighted software development that leads to half the posts here and 90% of the posts at Worse Than Failure.

    Just because it’s a silent, invisible crash now, for you, doesn’t mean it’s always going to be silent and invisible forever, nor that it isn’t already a very noisy one for some users.  I’m sure people with the debug kernel turned on would love a command-line shutdown tool that instead popped up a modal dialog asking if you wanted to debug rundll32, interrupting the shutdown.

  25. DriverDude says:

    Hmmm, "when all you have is a hammer, everything looks like a nail"

    rundll32: if only I had a nickle for every hung or crashing rundll32 process because some commercial software idiot thought it was a golden hammer. And there are so many rundll32 command lines in the registry, that when you see a hung rundll32 in Processes, it’s hard to tell who screwed up…

  26. Stu says:

    Raymond: I understand this is your blog and you have the right to say what you want, but please stop misqouting Jamie Zawinski, you may hate regular expressions or despise people that are forced* to use tools not entirely suited to the job they wish to do, but just quoting Zawinski is as bad as those people who quote Dijkstra whenever somebody mentions any form/dialect of BASIC (as occurs on certial blogs/forums).

    Secondly, a silent and invisible crash (as happens when rundll is used with ‘incompatible’ functions) is not, in any way that a normal user would care about, a crash.

    I understand that you don’t like to see your work misused, but I would consider using rundll more of a clever hack or kludge that works than something overtly bad.

    *Yes, forced, many corporate security policies will ban arbitary .exe’s on user machines, or you may have to implement these in pre-existing scripts where creating a new dependency is not allowed/practical.

    [It’s not a comment on regular expressions (which I myself am a fan of); I just like the joke pattern. And if you’re willing to corrupt the stack and take a 1/256 chance that the suspend will fail, then at least document it so your customers know what they’re up against. And if you are constrained by what you can do, then say so. Otherwise people will just say, “Don’t use a potato. Use a bicycle pump.” -Raymond]
  27. Norman Diamond says:

    Thursday, June 07, 2007 9:08 PM by Angstrom

    It’s not gcc; I’m sure there’s someone at

    Microsoft whose job it is (in some sense) to

    prevent any GNU/FSF programs from shipping

    with Windows.

    It is gcc.  Though I already stated my agreement with you on the other part, it doesn’t ship with Windows, it requires a separate download from Microsoft.  XP Pro can install Windows Services for Unix.  Server 2008, and if I recall correctly some versions of Vista, have a Start menu entry that will automatically open Internet Explorer to a Microsoft page where Subsystem for Posix Applications can be downloaded.  The gcc compiler that is included is gcc.

  28. Anon says:

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

    I worked at a company in the Netherlands for a while, they were developing an MFC application to drive some custom hardware. One of the developers there said he went to a Microsoft conference in the US and one of the Microsoft guys giving a presentation about C++ said "Visual Basic is for lesser mortals. Real men use C++"

  29. foxyshadis says:

    DriverDude, with good ol’ Process Explorer, you can see the command line of the rundll32, at least that can get you closer to matching it up. ;)

    It’s quite understandable to want to do as much from a single language/script as possible, but VBScript has some pretty hard limits – like binary file/registry IO, and APIs. Being able to load .Net libraries eases many of the limitations, however.

  30. Kuwanger says:

    > Every other sensible OS has shipped with its own dev tools (well, not OS2) for a while now.

    They also ship with web browsers, media players and so on and nobody complains. What’s up with that?

    Not to be horribly off-topic, but MS wasn’t prosecuted for shipping with a web browser.  They were prosecuted because they went out of their way to threaten OEMs who wanted to install a competing web browser alongside MS’s offering.  Ie, they were trying to be anti-competitive.  The issue then was whether MS was in a position where this anti-competitiveness was illegal.  The fact that merely offering software, bundled with the OS or otherwise, could be construed as anti-competitive is disturbing, though.

  31. Dewi Morgan says:

    If rundll could be given alternative function syntaxes, then these would not be potatoes.

    Does such a program exist? It would be so astonishingly useful to those of us who mostly program in php or perl.

    That people misuse rundll isn’t surprising. The command has no on-system help via ‘-h’ or ‘/?’ or ‘help’, so people will use it as best they can. If they learn from a trusted source (colleague, "useful tips" website) that it can be used to shut down the machine with an incantation, and on testing they find that it works, why should they suspect that there is an evil pixie that will make it sometimes not work?

    Many of us who use scripting languages exclusively simply would not think to look in MSDN, since almost nothing we normally do is related to that.

    Though speaking of which, anyone know for a list of rundll-callable Windows functions with the correct format? (Yes, I did search msdn).

    As for the potato/tyre thing: simple go to the person with the pump, and say "I will give you this fine potato…"

  32. DC says:

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

    strServer = "."

    Set objWMI = GetObject("winmgmts:\" & strServer & "rootcimv2")

    strWQL = "select * from Win32_ComputerSystem"

    Set objInstances = objWMI.ExecQuery(strWQL,,48)

    For Each objInstance in objInstances

    p_PowerState = 3
    
    p_Time = &quot;20051205044912.546875+060&quot;
    
    ' Uncomment next line to actually execute the method!
    
    ' intResult = objInstance.SetPowerState(p_PowerState, p_Time)
    
    WScript.Echo &quot;Result: &quot; &amp; intResult
    

    Next

  33. arun.philip says:

    Appreciate it that you’ve stopped the nitpickers corner [Considering you were having to think up whacky nitpicks, and preempt them]

    Has it stopped the nitpickers?

  34. AndyC says:

    “Go ahead, write that program, and then call it from your batch file. ”

    But then you have two problems….

    [You don’t have to install a runtime to run a native app (assuming you wrote it with this purpose in mind). Heck, you don’t even need to install it at all – you can run it directly over the network. -Raymond]
  35. Leo Davidson says:

    "Many of us who use scripting languages exclusively"

    My advise is to take a look at some non-scripting languages as well. You’ll find the transition a lot easier than you might think and it will allow you to choose the right tool for the job in different situations. It’ll also be good for your CV and open up more choices about what kind of work you do.

    I don’t mean this in a derogatory way. Something I have noticed over the years is that people can be scared off by the "big" languages. People I’ve known have been stuck using one particular language, say a scripting language or VB, and felt that learning a "proper" (for lack of a better word) language was beyond their abilities, but it’s not.

    I can understand being put off by C++ but these days there’s C# and Java and if you can understand VB or a scripting language then you shouldn’t have any trouble learning either of those. The basic concepts and flow of logic are exactly the same and the syntax differences are more like learning a regional dialect than a completely different language.

    I’d argue that C# is actually easier to understand than Perl, too.

    All it takes is a bit of reading and a bit of time. The basic concepts are the same in almost all languages (ignoring the "functional programming" languages, anyway).

    C++ can be a pain to learn because it’s full of caveats and complexities which take years to get the hang of, or even know they’re there. You have to trip over a lot of things in C++ before you can really consider yourself a good C++ programmer, in my opinion. C# and Java are cleaner and slimmer lanaguages which you can pick up and understand very easily, and they’re also great gateways into C++ if you want to go there one day (but you don’t have to, C# is fine for just about everything on the Windows platform, assuming you are not writing drivers or high-performance games, etc.).

    The overhead to writing a piece of code in C# are not much (if at all) greater than a scripting language, in terms of what you have to understand and the boiler-plate stuff you have to write to, for example, pull in a library, but the benefit is they are better designed and more structured so you will generally write better code (which also feeds back into what you may write in scripting languages) and you’ll gain access to APIs that you might not be able to call from a scripting language (which is Raymond’s point, I guess).

    There’s no reason, other than fear of the unknown, to say that you’ll only use scripting languages. You’re missing out on a very useful set of tools if you think that way. I’ve seen a lot of people who were afraid to take what they thought was a big leap, but when they did they found it was surprisingly easy.

    Of course, scripting languages have a place. I have to confess that I’m not a big fan of them but I still write the odd bit of VBScript glue here and there. The point is to arm yourself with a bigger toolbox so you aren’t constrained into using a hammer when what you really need is a sander.

  36. James Risto says:

    My take-away on this is to not get too particularly fixated on one tool. The command line is extensible via a lot of things … sometimes, you have to use C. A one page C program can save a lot of tears from somewhere else.

  37. Mihai says:

    If you want to do Windows development without installing a compiler (and all the headers), you can always use debug.

    It’s been there since early MS-DOS.

    Ok, it is not a compiler, but it is enough to call the one or two Win32 APIs required.

  38. Chris says:

    Would people actually be willing to USE a bigger, badder rundll32? Something that checks ESP after the call and puts up a big error box in case of mismatch? Would they agree to use a syntax like the below? [argv0 being a placeholder name, of course.]

    argv0 kernel32.dll SetSystemPowerState b=bb true true

    argv0 user32.dll GetSystemMetrics i=u 76 >> sm_cxscreen.txt

    argv0 /CDECL /GETLASTERROR somedll.dll _cfunc v=ii 42 999

    (Or, as is more likely, someone trying to start a screensaver the not-quite-right way…)

    argv0 user32.dll SendMessageA u=puup $fgwnd 0x0112 0xF140 0

    Because, you see, I’ve got some code already written along those lines. If people are interested I suppose I could clean it up for external release.

  39. name required says:

    Wang – I had a slightly longer term version which involved fermenting the potatoes, I’m sure they give off gas under such circumstances*. Of course, there would be certain beneficial side-effects with my version of the "code". Warning: can cause the ocular system to crash.

    * Caveat: I am not a bootlegger†

    † RIP

  40. Craig Ringer says:

    @coditza

    Download the Visual C++ Express Edition. It’s not hard, and provides a rather good tool. The only thing I’ve really been bugged by the lack of so far is a profiler, and that might just be my inability to find it.

    I build cross platform software so I use MinGW (gcc for Windows), the VC++ Express Edition (which also includes a command line cl.exe), and gcc on Linux & Mac OS X quite a lot. Do you know how much I paid for any of those? $0.

    Some years ago I too used to be annoyed by the lack of a quality free compiler on win32. Especially when it came to C++. Thankfully it’s just not an issue anymore.

  41. ExOrPhine says:

    This worked for me pretty well:

    1. Connect the potato and the tire with a usual tube

    2. Deflate the potato and concurrently inflate the tire

    3. If it doesn’t work – reiterate

  42. pc486 says:

    I cannot accept an answer of “write it in <lower-level language X>,” even if it’s just a small executable that makes one or two calls. Let me first say that I don’t use Windows as a platform for anything, work or home (but I do enjoy this and other Microsoft blogs). There may be something I’m missing here with the way Windows does its job. That said, I fully understand a developers feelings of wanting to (maybe forced too) script in something higher level. I write scripts all the time in evil bourne/bash to ugly Perl to any one of my own domain specific languages (translation: Lisp). I can get more done in 10 lines of script than a C++ or C# program can in 500. The act of starting a new project/directory+makefile just to make some syscall or low-level call is a significant developer performance hit as well as a maintenance problem.

    OK, now down to problem solving. Others have pointed out rundll, but Raymond shot that down by showing that it cannot create arbitrary calls. It is possible to create arbitrary calls out of some languages with tools like SWIG (http://www.swig.org/) or Lisp’s Common Foreign Function Interface (http://common-lisp.net/project/cffi/). But what about a SWIG/CFFI like command-line tool that can be passed a symbol and the symbol signature to make the call? In other words, is there a “correct” rundll?

    – Tristan

    [It’s not “write it in <lower-level language>. It’s “At the end of the day, it’s a call in the designated target language. You’ll need to bridge the gap.” Maybe there’s a “p/invoke”-like way of doing it, maybe somebody else bridged it for you. -Raymond]
  43. Phil Wilson says:

    Usin Win32_PointingDevice in a WMI script that sets DoubleSpeedThreshold or QuadSpeedThreshold is all it takes to solve the mouse problem, same principle as DC’s PowerState script. You can do some serious stuff with WMI and VBScript.  

  44. andreister says:

    OK, I’ve come across one post from Raymond (http://blogs.msdn.com/oldnewthing/archive/2004/01/15/58973.aspx) about calling convention and rundll. I’m assuming calling SHExitWindowsEx via rundll would also fail because SHExitWindowsEx is merely a wrapper on ExitWindowsEx.

    Then, if yes, it looks like this Microsoft article (http://support.microsoft.com/?kbid=234216) about shutdown on Win98 is not valid, right? It suggests using “rundll32.exe shell32.dll,SHExitWindowsEx X” to restart Windows 98/Me automatically.

    Or back in time of Win98, ExitWindowsEx had a different signature?

    Thanks,

    Andrew

    [I already discussed this. Most KB articles are not reviewed by the product team; it’s just a bunch of product support people helping each other out. Maybe their advice is good, maybe not. -Raymond]
  45. I agree with Raymond that the product teams (and Raymond in particular) should not have to explain how to make a specific API call from (a possibly very long) list of programming languages. That’s a bit backwards.

    I also agree that rundll32.dll is overused, and often mis-used.

    However, there seems to be a real need to easily make an API call without having to write the 15-lines programs that makes such a call.  Even I, as a developer, encounter this mental barrier that  ‘writing a whole program to…’ takes too much time/attention.

    To deal with this apparent need, I took some time this weekend to write a simple program to execute an arbitrary DLL method call with arbitrary parameters from the command-line.  For example, execute

    RunAnyDLL user32.dll MessageBoxA UINT 0 LPSTR Welcome LPSTR goodbye UINT 1

    A v0.1 version of this tool is available on tool available on http://www.yanivpessach.com/shared/runanydll/ .

    The current version uses .NET (it emits a module using the .NET interop), but I may rewrite it to use straight C/++. Feedback most welcome.

    // Yaniv Pessach

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index