Вниз
Скачать: 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 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.026 c
1-1080124608
Dysan
2004-03-24 13:36
2004.04.11
StrToDate( 29/02/2004 );


1-1079952889
martyanov
2004-03-22 13:54
2004.04.11
Проблемы с временем


14-1081916840
Vlad Oshin
2004-04-14 08:27
2004.04.11
Зачем убрали IP из коментов в постах? :)


3-1078931138
Goida
2004-03-10 18:05
2004.04.11
Выборка в выборке


6-1075643670
stimm
2004-02-01 16:54
2004.04.11
Пишу программу Анти-Интернет для братишки :)




   Наверх