[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Lock the workstation on a windows machine

Posted on 2004-10-20
8
Medium Priority
?
483 Views
Last Modified: 2007-12-19
hi,

i'm trying to come by some code to help me lock the workstation from the program i'm developing for windows machines (2000 and xp)

i know there is an API, but i think i don't have it, for example i tried this:
#include <windows.h>
#include <stdio.h>
int main()
{
                        if(!LockWorkStation())
                                  printf ("error: could not lock workstation:  %d\n", GetLastError());
                        return 0;
}

according to msdn LockWorkStation() is included on windows.h, but not VC 5, nor GCC (mingw or cygwin) can find it.

another thing i tried is to find something similar to this:

SendMessage(HWND_BROADCAST,WM_SYSCOMMAND,SC_SCREENSAVE,0);

that will lock the workstation by activating the screensaver. everything is fine, only i just want to lock the computer without the screensaver. so maybe there is a parameter other than SC_SCREENSAVE that i can pass onto SendMessage.

the last thing i know of is the rundll trick of locking the Workstation by calling user32.dll or something, but again, there must be a better way

any ideas?

any help will be appreciated.
0
Comment
Question by:urif
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
8 Comments
 

Expert Comment

by:Mic77
ID: 12356328
To make the work, you need a newer SDK which contains the header and lib-files.
You need install VC7 or try this one

http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
0
 

Author Comment

by:urif
ID: 12356381
hmmm, thanks but i dont think that installing a 266mb sdk for one function is a solution. at least not at this point.

thanks so much anyway

any other ideas?
0
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 12358597
>>any other ideas?

Load the entrypoint dynamically:

typedef BOOL (*FPTR_LockWorkStation)(VOID);

HINSTANCE hDll = LoadLibrary( "user32.dll");

FPTR_LockWorkStation pLockWorkStation = (FPTR_LockWorkStation) GetProcAddress (hDll,"LockWorkStation");

_LockWorkStation();

FreeLibrary (hDll);
0
 

Author Comment

by:urif
ID: 12399102
it still returns as undeclared identifier: _LockWorkStation();
0
 

Author Comment

by:urif
ID: 12419532
ok for anyone that searched the solution:

#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <winuser.h>

so you only have to add winuser.h


cheers!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question