Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to give a process or thread administrator attributes Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
09-Jan-04
Category
System
Language
Delphi 3.x
Views
167
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Lou Adler 

I am trying to write a launcher program that can launch applications with 
administrator rights, kind of like the option in Windows 2000 to have an 
application "Run As" administrator. I think the way to do this is to use 
createprocess() function with something set in lpProcessAttributes or 
lpThreadAttributes that gives the process or thread administrator attributes. 
Unfortunatily, I'm not sure what to do beyond this. If anyone can give me answers 
as to what I can do next, I would be grateful.

Answer:
1   
2   function CreateProcessWithLogonW(lpUsername, lpDomain, lpPassword: PWideChar;
3     dwLogonFlags: dword; lpApplicationName: PWideChar; lpCommandLine: PWideChar;
4     dwCreationFlags: DWORD; lpEnvironment: Pointer; lpCurrentDirectory: PWideChar;
5     const lpStartupInfo: TStartupInfo; var lpProcessInformation: TProcessInformation):
6     BOOL; stdcall; external 'advapi32.dll';
7   
8   function RunAsUser(const Filename, Domain, Username, Password: string): Boolean;
9   var
10    StartupInfo: TStartupInfo;
11    ProcessInfo: TProcessInformation;
12    wFilename, wDomain, wUsername, wPassword: PWideChar;
13  begin
14    FillChar(StartupInfo, SizeOf(StartupInfo), #0);
15    StartupInfo.cb := SizeOf(StartupInfo);
16    StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
17    StartupInfo.wShowWindow := SW_SHOWNORMAL;
18    GetMem(wFilename, Length(Filename) * SizeOf(WideChar) + SizeOf(WideChar));
19    GetMem(wDomain, Length(Domain) * SizeOf(WideChar) + SizeOf(WideChar));
20    GetMem(wUsername, length(Username) * SizeOf(WideChar) + SizeOf(WideChar));
21    GetMem(wPassword, length(Password) * SizeOf(WideChar) + SizeOf(WideChar));
22    StringToWideChar(Filename, wFilename, Length(Filename) * SizeOf(WideChar)
23      + SizeOf(WideChar));
24    StringToWideChar(Domain, wDomain, Length(Domain) * SizeOf(WideChar)
25      + SizeOf(WideChar));
26    StringToWideChar(Username, wUsername, Length(Username) * SizeOf(WideChar)
27      + SizeOf(WideChar));
28    StringToWideChar(Password, wPassword, Length(Password) * SizeOf(WideChar)
29      + SizeOf(WideChar));
30    Result := CreateProcessWithLogonW(wUsername, wDomain, wPassword, 0, wFilename,
31      nil, 0, nil, nil, StartupInfo, ProcessInfo);
32    if Result then
33    begin
34      WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
35      CloseHandle(ProcessInfo.hProcess);
36      CloseHandle(ProcessInfo.hThread);
37    end
38    else
39      RaiseLastOSError;
40    FreeMem(wFilename);
41    FreeMem(wDomain);
42    FreeMem(wUsername);
43    FreeMem(wPassword);
44  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC