winapiexec
winapiexec is a small tool that allows you to run WinAPI functions through command line parameters.
The syntax is:
winapiexec.exe library.dll@FunctionName 123 unicode_text "a space"
If you don’t specify a library or use “k”, kernel32.dll is used.
If you specify “u” as a library, user32.dll is used.
Numbers are detected automatically, you also can use hex numbers (like 0xFE) and use the minus sign (e.g. -5).
Strings are unicode by default.
You can use special prefixes to specify parameter types:
$s:ascii – an ascii string
$u:unicode – a unicode string (it’s unicode by default, but you can use it to force numbers as strings)
$b:1024 – a zero-bytes buffer with the size you specify, in bytes
$$:1 – a reference to another parameter, you can also use $$:0 for the program’s name (argv[0])
$a:1,$u:2,str – an array of parameters, divided by commas. you can use all the perfixes here
$$:3@2 – a reference to an item in an array of parameters
While referencing to another parameter, note that they are processed by the order of execution, which means there’s no point to reference to a parameter right to the referencing one.
Also note that after a function is run, it’s first parameter (like library.dll@FunctionName) is replaced with the return value.
You can execute multiple WinAPI functions, one after the other, using a comma:
winapiexec.exe library.dll@FunctionName1 123 , library.dll@FunctionName2 456
You can also execute functions nested, using brackets:
winapiexec.exe library.dll@FunctionName1 ( library.dll@FunctionName2 456 )
While the return value of the internal function is passed as a parameter to the external function.
Download:
winapiexec.rar (2.98 KB)
Here are some examples of what you can do:
Display temp path:
winapiexec.exe GetTempPathW 260 $b:520 , u@MessageBoxW 0 $$:3 $$:0 0x40
Greetings:
winapiexec.exe advapi32.dll@GetUserNameW $b:65534 $a:32767 , u@wsprintfW $b:2050 "Hello %s from %s" $$:2 $$:0 , u@MessageBoxW 0 $$:6 ... 0
Hide the taskbar for half a second, then show it:
winapiexec.exe u@ShowWindow ( u@FindWindowW Shell_TrayWnd 0 ) 0 , Sleep 500 , u@ShowWindow $$:3 5
Run calculator for a second, then terminate it:
winapiexec.exe CreateProcessW 0 calc 0 0 0 0x20 0 0 $a:0x44,,,,,,,,,,,,,,,, $b:16 , Sleep 1000 , TerminateProcess $$:11@0 0
Show a messagebox and then create a new instance of the process:
winapiexec.exe u@MessageBoxW 0 Hello! :) 0 , CreateProcessW $$:0 ( GetCommandLineW ) 0 0 0 0x20 0 0 $a:0x44,,,,,,,,,,,,,,,, $b:16
Eject your cdrom ![]()
winapiexec.exe winmm.dll@mciSendStringW "open cdaudio" 0 0 0 , winmm.dll@mciSendStringW "set cdaudio door open" 0 0 0 , winmm.dll@mciSendStringW "close cdaudio" 0 0 0
…and some more useful stuff
Turn off and on monitor:
winapiexec.exe u@SendMessageW 0xFFFF 0x112 0xF170 2
winapiexec.exe u@SendMessageW 0xFFFF 0x112 0xF170 -1
Display the Start menu:
winapiexec.exe u@SendMessageW ( u@FindWindowW Shell_TrayWnd 0 ) 0x111 305 0
Run task manager:
winapiexec.exe u@SendMessageW ( u@FindWindowW Shell_TrayWnd 0 ) 0x111 420 0
More tricks like that:
http://www.codeproject.com/KB/miscctrl/Taskbar_Manipulation.aspx
What would be the command to show the Quick launch?
I don’t think there is a winapi function for that.
In Windows XP you could probably emulate it from the right click menu of the taskbar, but in seven there’s no such menu entry.
There is a ShowTrayBand function introduced in Vista (http://msdn.microsoft.com/en-us/library/windows/desktop/bb774485(v=vs.85).aspx) but I dunno how to use it and winapiexec to show the Quick Launch.
http://blogs.msdn.com/b/oldnewthing/archive/2009/02/02/9388941.aspx
I have the clock hidden in the system tray (windows 7) so I just want to know if there is a way to open the clock window (ex: http://windows7themes.net/pics/windows-7-taskbar-clock.jpg) via command line?
Thanks in advance and keep up the good work
winapiexec.exe u@PostMessageW ( u@FindWindowExW ( u@FindWindowExW ( u@FindWindowW Shell_TrayWnd 0 ) 0 TrayNotifyWnd 0 ) 0 TrayClockWClass 0 ) 0x466 1 0Tested on Windows 7, not sure if it’ll work on other versions.
sorry, maybe I have not used correctly, but this code did not work here… nothing is displayed.
WordPress screwed up the code a little bit, now when I put it in code tags, it should work.
Thank you RaMMicHaeL!!
Now I can hide the clock and use a custom rainmeter skin with a quick link to the calendar and config
Does winapiexec allow sending an e-mail with custom message text and attachments via the default e-mail client?
A while ago I tried to find a way to modify the default text Windows forces upon the user (“Your message is ready to be sent with the following file or link attachments:”) but I think I gave up.
I think I was trying to take advantage of Windows’ simple image resizing interface. There may be other ways to achieve this (AutoHotkey), though.
I took the UNIX/POSIX language BC, a while back, and upgraded it practically into a C interpreter, called C-BC. I can take some of that code and language design, remake it into a command shell and adapt it into your program’s source code, if you wish.
C-BC has the “include” directive, so it has the ability to load modules containing pre-defined routines as well.
The proposed extension would be invoked by just calling “winapiexec.exe” with no command-line arguments. Alternatively, it might be invoked with an argument like $@ to start the shell in mid-command. Or, the modified program might be given a different name, such as wsh.exe, mssh.exe or winsh.exe.
The main question on my mind is how much of C-BC’s facilities to keep intact. I’d probably take out or replace its data types (extended precision numbers, strings, arrays and pointers) with a simpler system of types (bytes, words, strings, arrays). On the other hand, the temptation is strong to go into the opposite direction and throw in the whole type system of a modern language: polymorphism, abstract types, classes and all.
The other question, of course, is what unforeseen consequences there will be in combining a command-line windows API processor with a programming language interpreter.
If you’re interested, send an e-mail note.
Hi Mark,
1995, huh? I was 4 back then
If I wish? I won’t mind.
Polymorphism and classes in a command shell? o_O
Do I get it right, that by command shell you mean something like cmd.exe? I’m not very familiar with UNIX/POSIX OSes, but from what I understand, you want to extend the syntax to include C-BC functions, to allow e.g. to create a while loop from command line?
A couple of examples of what would it look like or what would it be able to do will help me get the idea better.
Regards.
Please a command to enable/disable windows shadows in Windows 7 x64 on the fly. Thanks.
Enable:
winapiexec.exe u@SystemParametersInfoA 0x1025 0 1 3Disable:
winapiexec.exe u@SystemParametersInfoA 0x1025 0 0 3Excellent. Thank you very much.
Antoher one please, a command to change theme in Windows 7 x64. Thanks.
http://www.sevenforums.com/themes-styles/93397-there-silent-command-line-operation-change-theme.html
Does anyone know how to decommit private bytes for a specific process using this program?
Avast Anti-Virus blocked my download before it started stating winapiexec is a suspicious Win32:MDE-B [Susp] item. Could you contact Avast to have it allowed?
Done.
Before and after.
Thanks! That was quick!
А можно этой чудо-программкой запустить команду “Minimize all”, ну и соответственно обратно?
“Minimize all”:
winapiexec.exe u@SendMessageW ( u@FindWindowW Shell_TrayWnd 0 ) 0x111 419 0Обратно оно не работает. Для этого можно использовать “Show desktop”:
winapiexec.exe u@SendMessageW ( u@FindWindowW Shell_TrayWnd 0 ) 0x111 407 0Спасибо. До этого у меня вот такая веселая конструкция была:
chp.exe —> cmdow.exe —> ярлык с командой
=)