We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How to execute code with current user privilege on the service application.

Medium Priority
823 Views
Last Modified: 2012-05-07
Hello.
I made a serivce application. ( it is executed with System user account )

When i trying to some jobs on the service application, the code does not work.
Because of service application has limitted privileges.
So, i must made other win32 program which is executed by service application with current logon user system privileges.

I think this way is not efficient. Because i must made another program.

So, I looking for the solution that execute some procedure or function with current logon user privileges at the service application.

For Example)
// Service application body
begin
....
   do_excute_some_code( parameter 1 ); // this procedure will execute with current logon user privileges

end;

Is this possible ???
If you know how to do this, please let me know or give me some example code.

Thanks.
Comment
Watch Question

CERTIFIED EXPERT

Commented:
I am almost certain you will not be able to change the account under which you are running while running.
Is there a reason why you can not just run the entire service from a user's account with all of the approriate priveleges?

As an alternative you could perhaps write two services and run them under different accounts and have service1 send a message to service2 that will then execute some code but it sounds like alot of work.
Geert GOracle dba
CERTIFIED EXPERT
Top Expert 2009

Commented:
you need to change to the user you need with impersonate user and then run that task

  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

Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Geert GOracle dba
CERTIFIED EXPERT
Top Expert 2009

Commented:
lol, mlmcc
accepting a VB solution in a Delphi zone

ahh, there is general programming languages too
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.