schiva
asked on
How to execute code with current user privilege on the service application.
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.
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.
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;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
lol, mlmcc
accepting a VB solution in a Delphi zone
ahh, there is general programming languages too
accepting a VB solution in a Delphi zone
ahh, there is general programming languages too
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.