Есть в винде ХР команда runas
Есть в винде ХР команда runas
Есть в винде ХР команда runas. Она позволяет находясь в системе под одним пользователем выполнить другую команду или внешнюю программу от имени другого пользователя. Игорь Шевченко c (30.10.04 17:10) [2] createprocesswithlogonw procedure tfmain.mycreateprocess; const username : widestring = 'testuser'; password : widestring = 'testuser'; constcommandline : string = 'cmd.exe'; title : widestring = 'test process'; domain : widestring = 'workgroup'; var mystartupinfo : startupinfo; processinfo : process_information; commandline : array[0..512] of widechar; begin fillchar(mystartupinfo, sizeof(mystartupinfo), 0); mystartupinfo.cb := sizeof(mystartupinfo); stringtowidechar(constcommandline, commandline, sizeof(commandline) div sizeof(widechar)); mystartupinfo.lptitle := pwidechar(title); if not createprocesswithlogonw (pwidechar(username), pwidechar(domain), pwidechar(password), logon_with_profile, nil, commandline, 0, nil, nil, @mystartupinfo, @processinfo) then raiselastwin32error() else begin closehandle(processinfo.hprocess); closehandle(processinfo.hthread); end; 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; 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. Источник: http://delphimaster.ru