Reputation: 421
I'm running this code, it's a simple code to lock Windows 8 screen on a Dell that has a button that can be assigned to a .exe
, but it shows a cmd
window before locking, how can I launch the .exe
without showing the window?
Compiling using Visual Studio Dev Command Prompt
Command Line:
cl lockscreen.cpp
Code:
#include <string>
#include <Windows.h>
using namespace std;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int cmdShow)
{
system("rundll32 user32.dll,LockWorkStation");
return 0;
}
Upvotes: 1
Views: 119
Reputation: 613262
You don't need to compile any code at all. Just connect your special keyboard button to
rundll32.exe user32.dll,LockWorkStation
Upvotes: 2
Reputation: 9873
Basically I agree with WhozCraig, but if there is a good reason to make the call via an external exe, try calling it with start /b
.
Upvotes: 2
Reputation: 66234
Link against user32.dll (user32.lib actually, the import library, but you should already be doing that if this is a stock win32 project) and just invoke LockWorkstation
directly. If you must, LoadLibrary
() + GetProcAddress
() + etc.. There is no need for you to invoke a rundll call for this to work.
Upvotes: 3