Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Система";
Текущий архив: 2004.04.11;
Скачать: [xml.tar.bz2];

Вниз

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

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

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


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

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


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

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


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

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


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

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


 
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.


 
Игорь Шевченко ©   (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 19:48) [4]

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


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

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


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

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


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

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


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

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



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

Форум: "Система";
Текущий архив: 2004.04.11;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.49 MB
Время: 0.035 c
7-1079610137
Delph1
2004-03-18 14:42
2004.05.09
Как получить каталог рабочего стола в Delphi?


3-1081758841
Alex2004
2004-04-12 12:34
2004.05.09
Как уменьшить размер кэша


11-1068798502
Ал
2003-11-14 11:28
2004.05.09
Bitmap.LoadFromStream для bmp, сделанных в разных программах


8-1076286432
Maratus
2004-02-09 03:27
2004.05.09
Прорисовка двигающегося выделения как в графических пакетах


11-1067197291
puky
2003-10-26 22:41
2004.05.09
www.Rentacoder.com и Kol





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский