flasht
asked on
Run as other user...
How do i run my application as other user? I mean so the application would load itself as other user on its profile like runas /profil ... but so my application would do it itself?
Try this
function CreateProcessWithLogon(use r, password, cmdLine: string) : DWord;
const
LOGON_WITH_PROFILE=1;
var
lsi: TStartupInfo;
lpi: TProcessInformation;
begin
ZeroMemory(@lsi, sizeOf(lsi));
lsi.cb := sizeOf(lsi);
ZeroMemory(@lpi, sizeOf(lpi));
CreateProcessWithLogonW(PW ideChar(wi deString(u ser)),nil, PWideChar( wideString (password) ),
LOGON_WITH_PROFILE, nil,PWideChar(wideString(c mdLine)),C REATE_DEFA ULT_ERROR_ MODE or NORMAL_PRIORITY_CLASS,
nil, nil, lsi, lpi);
Result := GetLastError
end;
function CreateProcessWithLogon(use
const
LOGON_WITH_PROFILE=1;
var
lsi: TStartupInfo;
lpi: TProcessInformation;
begin
ZeroMemory(@lsi, sizeOf(lsi));
lsi.cb := sizeOf(lsi);
ZeroMemory(@lpi, sizeOf(lpi));
CreateProcessWithLogonW(PW
LOGON_WITH_PROFILE, nil,PWideChar(wideString(c
nil, nil, lsi, lpi);
Result := GetLastError
end;
ASKER
@TheRealLoki: I need exatly the same thing as making shortcut and in advanced options setting up "run with other privilages" (translated from polish - so it may be something else)
@pcsentinel: The problem is i would like my application to run itself as other user, not other process...
@pcsentinel: The problem is i would like my application to run itself as other user, not other process...
ASKER
Bah... its seems that both examples aren't answer to my question...
Ok... the problem is more complicated than i thought anyway...
First of all i want my application to run as other user by double-clicking on executable of my application. For example im on Administrator account, double click on my application executable and its being run as OtherUser ... so everything would be from other user - IE settings, Cache Directory, Cookies Directory etc etc... But... my application has MadExcept in itself and on exception it restarts itself... So after restart it appears that it was run by this OtherUser that cant set any privilages because its normal user (not administrator). Hope you understand what the problem is... any suggestions on how to do that?
New Point Value: 200 pts
Ok... the problem is more complicated than i thought anyway...
First of all i want my application to run as other user by double-clicking on executable of my application. For example im on Administrator account, double click on my application executable and its being run as OtherUser ... so everything would be from other user - IE settings, Cache Directory, Cookies Directory etc etc... But... my application has MadExcept in itself and on exception it restarts itself... So after restart it appears that it was run by this OtherUser that cant set any privilages because its normal user (not administrator). Hope you understand what the problem is... any suggestions on how to do that?
New Point Value: 200 pts
Sorry, i don't know how to do that. THere is source for making "SUser.exe" a commandline to start your app, or you could always tell your app to start itself again
e.g. your app starts, it knows it does not have anough access rights, so it doesthhe createprocess with the correct rights, running the same exe again, then the 1st instance closes.
the 2nd instance runs, sees it has enough access rights, and continues
e.g. your app starts, it knows it does not have anough access rights, so it doesthhe createprocess with the correct rights, running the same exe again, then the 1st instance closes.
the 2nd instance runs, sees it has enough access rights, and continues
Simplest answer is to have 2 apps, one which is a launcher for the other the launcher calls CreateProcessWithLogon
ASKER
pcsentinel: your code aint working...
[Error] Unit1.pas(35): Undeclared identifier: 'CreateProcessWithLogonW'
[Error] Unit1.pas(35): Undeclared identifier: 'CreateProcessWithLogonW'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
take a look at this question
https://www.experts-exchange.com/questions/21027137/Impersonate-User-problems.html
I think your user needs some privileges set up
I can't quite recall if you need
"Act as part of the operating system" - SeTcbPrivilege
"Increase quotas" - SeIncreaseQuota
"Replace a process level token" - SeAssignPrimaryToken
or any of them in fact, been so long since I had to do this sort of thing :-)