?
Solved

Run as other user...

Posted on 2006-05-23
9
Medium Priority
?
498 Views
Last Modified: 2010-04-05
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?
0
Comment
Question by:flasht
  • 3
  • 3
  • 2
8 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16747485
You need to use "ImpersonateUser"
take a look at this question
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21027137.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  :-)

0
 
LVL 11

Expert Comment

by:pcsentinel
ID: 16750451
Try this

function CreateProcessWithLogon(user,  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(PWideChar(wideString(user)),nil,PWideChar(wideString(password)),
            LOGON_WITH_PROFILE, nil,PWideChar(wideString(cmdLine)),CREATE_DEFAULT_ERROR_MODE or NORMAL_PRIORITY_CLASS,
            nil, nil, lsi, lpi);
      Result := GetLastError
end;
0
 
LVL 3

Author Comment

by:flasht
ID: 16754236
@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...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Author Comment

by:flasht
ID: 16754299
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
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16756154
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
0
 
LVL 11

Expert Comment

by:pcsentinel
ID: 16758771
Simplest answer is to have 2 apps, one which is a launcher for the other the launcher calls CreateProcessWithLogon
0
 
LVL 3

Author Comment

by:flasht
ID: 17027521
pcsentinel: your code aint working...

[Error] Unit1.pas(35): Undeclared identifier: 'CreateProcessWithLogonW'
0
 
LVL 11

Accepted Solution

by:
pcsentinel earned 600 total points
ID: 17029425

declare it as


function CreateProcessWithLogonW(lpUserName,lpDomain,lpPassword: LPCWSTR;
  dwLogonFlags:dword; lpApplicationName : LPCWSTR; lpCommandLine: LPWSTR; dwCreateionFlags:dword;
  lpEnvironment:Pointer; lpCurrentDirectory: LPCWSTR; const lpstartupinfo:tstartupinfo;
  var lpProcessInfo:TProcessInformation): BOOL; stdcall; external 'advapi32.dll';
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

839 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