Solved

Start a thread with different user in Delphi app

Posted on 2008-10-28
2
435 Views
Last Modified: 2010-04-21
I have this app run from the currently logged on user
(standard start double click from desktop)

In this windows app i want to create a thread using a diffent user.
This user obviously has more priviliges than the user starting the app.

This app is a tool to read from AD and perform changes in AD.
The secondary user would be used to do this.

I could off course start the app from the secondary user,
but i don't want to do this.

Any code examples in Delphi ?
0
Comment
Question by:Geert Gruwez
2 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 500 total points
ID: 22821423
use ImpersonateLoggedOnUser

  if LogonUser(user, domain or empty string , pass, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, h) then
  try
    if ImpersonateLoggedOnUser(h) then
    try
      do whatever as user
    finally
      if not RevertToSelf then// either this, or exit the thread
        showmessage(syserrormessage(getlasterror));
    end
    else
      showmessage(syserrormessage(getlasterror));
  finally
    closehandle(h);        
  end;

Open in new window

0
 
LVL 37

Author Closing Comment

by:Geert Gruwez
ID: 31510716
thx ciuly
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 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