Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.04.11;
Скачать: CL | DM;

Вниз

Запуск от имени   Найти похожие ветки 

 
dmytro   (2004-03-23 17:51) [0]

Привет Всем!
Дано: ХР проф, зарегистрено два юзера Admin и User, первый с правами, второй - ограниченный. Нужно, чтобы User запустил прогу от имени Admin, которая пишет в дир. Windows. Я понимаю, что юзать нужно CreateProcessAsUser и LogonUser, но как? Ткните в пример, плз. Все, что нарыл в инете либо сишное, либо не работает :-) Заранее благодарю.


 
Игорь Шевченко ©   (2004-03-23 18:48) [1]

Ищи в форуме WinAPI или в этом - я давал пример CreateProcessWithLogonW


 
dmytro   (2004-03-23 18:51) [2]

Этот пример у меня есть, там uses HSAdvApi который я не могу найти


 
Игорь Шевченко ©   (2004-03-23 19:15) [3]

unit HSAdvApi;

interface
uses
 Windows;

function CreateProcessWithLogonW (const lpUsername : PWideChar;
 const lpDomain : PWideChar; const lpPassword : PWideChar;
 dwLogonFlags : DWORD; const lpApplicationName : PWideChar;
 lpCommandLine : PWideChar; dwCreationFlags : DWORD;
 lpEnvironment : Pointer; const lpCurrentDirectory : PWideChar;
 lpStartupInfo : PStartupInfo;
 lpProcessInfo : PProcessInformation) : Boolean; stdcall;

const
 LOGON_WITH_PROFILE = $00000001;
 LOGON_NETCREDENTIALS_ONLY = $00000002;
 LOGON_ZERO_PASSWORD_BUFFER = $80000000;

implementation
uses
 SysUtils;

{ ADVAPI32.DLL functions }
type
 TCreateProcessWithLogonW =
   function (const lpUsername : PWideChar;
 const lpDomain : PWideChar; const lpPassword : PWideChar;
 dwLogonFlags : DWORD; const lpApplicationName : PWideChar;
 lpCommandLine : PWideChar; dwCreationFlags : DWORD;
 lpEnvironment : Pointer; const lpCurrentDirectory : PWideChar;
 lpStartupInfo : PStartupInfo;
 lpProcessInfo : PProcessInformation) : Boolean; stdcall;

const
 DllName = "advapi32.dll";

var
 DllHandle : THandle;
 _CreateProcessWithLogonW : TCreateProcessWithLogonW;

function InitLib : Boolean;
begin
 if DllHandle = 0 then
   if Win32Platform = VER_PLATFORM_WIN32_NT then begin
     DllHandle := LoadLibrary(DllName);
     if DllHandle <> 0 then begin
       @_CreateProcessWithLogonW := GetProcAddress(DllHandle,
         "CreateProcessWithLogonW");
     end;
   end;
 Result := (DllHandle <> 0);
end;

function NotImplementedBool : Boolean;
begin
 SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
 Result := false;
end;

function CreateProcessWithLogonW (const lpUsername : PWideChar;
 const lpDomain : PWideChar; const lpPassword : PWideChar;
 dwLogonFlags : DWORD; const lpApplicationName : PWideChar;
 lpCommandLine : PWideChar; dwCreationFlags : DWORD;
 lpEnvironment : Pointer; const lpCurrentDirectory : PWideChar;
 lpStartupInfo : PStartupInfo;
 lpProcessInfo : PProcessInformation) : Boolean; stdcall;
begin
 if InitLib and Assigned(_CreateProcessWithLogonW) then
   Result := _CreateProcessWithLogonW(lpUsername, lpDomain, lpPassword,
     dwLogonFlags, lpApplicationName, lpCommandLine, dwCreationFlags,
     lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInfo)
 else
   Result := NotImplementedBool;
end;

initialization
finalization
 if DllHandle <> 0 then
   FreeLibrary(DllHandle);
end.


 
dmytro   (2004-03-23 19:48) [4]

Большое человеческое спасибо!!! А можно еще и тот исходник, где этот юнит используется, я его со злости грохнул :-(


 
dmytro   (2004-03-23 21:16) [5]

Класс! Все работает, спасибо большое. Кстати, а что означает предупреждение Symbol "RaiseLastWin32Error" is deprecated?


 
dmytro   (2004-03-23 21:49) [6]

Все, разобрался сам. Это устаревший вызов, нужно заменить на RaiseLastOSError



Страницы: 1 вся ветка

Текущий архив: 2004.04.11;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.03 c
14-1081863939
miwa
2004-04-13 17:45
2004.04.11
О встречах мастаков вообще...


4-1079444425
BillyJeans
2004-03-16 16:40
2004.04.11
Окно без title bar...


1-1082361797
TransparentGhost
2004-04-19 12:03
2004.04.11
Определение позиции тхт курсора в Memo


1-1082660847
Боян Георгиев
2004-04-22 23:07
2004.04.11
Курсор


1-1080124600
satron
2004-03-24 13:36
2004.04.11
TWebBrowser ....?