Цитата:
Сообщение от IliaIT
очень похоже, что где то кавычки не прописаны при задании пути в команде использования. и пробелы от не воспринял в пути.
|
тоже так думал, все присваивал переменным для проверки и кавычки и правильность на высшем уровне
Цитата:
Сообщение от Stilet
А теперь покажи сам код, партизанин )
|
извините кода нет, уже столько вариантов перепробовал что даже не вспомню первоначальный код
пробовал через
LogonUser -> ImpersonateLoggedOnUser -> CopyFile
ошибки те же
пробовал через
WNetAddConnection2 -> CopyFile ошибки те же
единственный вариант работающий ( без получения данных о выполнении )
Код:
const
LOGON_WITH_PROFILE = $00000001;
function CreateProcessWithLogonW(
lpUsername,
lpDomain,
lpPassword:PWideChar;
dwLogonFlags:dword;
lpApplicationName: PWideChar;
lpCommandLine: PWideChar;
dwCreationFlags: DWORD;
lpEnvironment: Pointer;
lpCurrentDirectory: PWideChar;
lpStartupInfo: PStartupInfo;
lpProcessInformation: PProcessInformation
): BOOL; stdcall; external 'advapi32.dll';
function CreateProcessAsLogon(const User, Domain, PW, Application, CmdLine: WideString): string;
var
si : TStartupInfo;
pif : TProcessInformation;
begin
ZeroMemory(@si, sizeof(si));
si.cb := sizeof(si);
si.dwFlags := STARTF_USESHOWWINDOW;
si.wShowWindow := 1;
SetLastError(0);
CreateProcessWithLogonW(PWideChar(User), PWideChar(Domain), PWideChar(PW),
LOGON_WITH_PROFILE, nil, PWideChar('"'+Application+'" '+CmdLine),
CREATE_DEFAULT_ERROR_MODE, nil, nil, @si, @pif);
Result := SysErrorMessage(GetLastError);
end;
procedure TMainForm.Click(Sender: TObject);
var
s,s1:string;
l,p,d:string;
fl:TStringList;
begin
fl:=TStringList.Create;
s1:=StringGrid1.Cells[3,StringGrid1.Row];
s1[pos(':',s1)]:='$';
fl.Add('net use Q: \\'+StringGrid1.Cells[0,StringGrid1.Row]+'\'+s1[1]+'$ password /USER:domain\user');
fl.Add('xcopy "'+GetCurrentDir+'\info.bat" "\\'+StringGrid1.Cells[0,StringGrid1.Row]+'\'+s1+'Its3\"');
fl.Add('xcopy "'+GetCurrentDir+'\Unit1.pas" "\\'+StringGrid1.Cells[0,StringGrid1.Row]+'\'+s1+'Its3\"');
fl.Add('net use Q: /DELETE');
fl.SaveToFile(GetCurrentDir+'\run.cmd');
s:=CreateProcessAsLogon('user','domain','passworde',GetCurrentDir+'\run.cmd','');
Memo1.Text:=s;
есть такой код для получения данных
Код:
function GetDosOutput(CommandLine: string; Work: string = 'C:\'): string;
var
SA: TSecurityAttributes;
SI: TStartupInfo;
PI: TProcessInformation;
StdOutPipeRead, StdOutPipeWrite: THandle;
WasOK: Boolean;
Buffer: array[0..255] of AnsiChar;
BytesRead: Cardinal;
WorkDir: string;
Handle: Boolean;
begin
Result := '';
with SA do begin
nLength := SizeOf(SA);
bInheritHandle := True;
lpSecurityDescriptor := nil;
end;
CreatePipe(StdOutPipeRead, StdOutPipeWrite, @SA, 0);
try
with SI do
begin
FillChar(SI, SizeOf(SI), 0);
cb := SizeOf(SI);
dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
wShowWindow := SW_HIDE;
hStdInput := GetStdHandle(STD_INPUT_HANDLE); // don't redirect stdin
hStdOutput := StdOutPipeWrite;
hStdError := StdOutPipeWrite;
end;
WorkDir := Work;
Handle := CreateProcess(nil, PChar('cmd.exe /C ' + CommandLine),
nil, nil, True, 0, nil,
PChar(WorkDir), SI, PI);
CloseHandle(StdOutPipeWrite);
if Handle then begin
try
repeat
WasOK := ReadFile(StdOutPipeRead, Buffer, 255, BytesRead, nil);
if BytesRead > 0 then
begin
Buffer[BytesRead] := #0;
Result := Result + Buffer;
end;
until not WasOK or (BytesRead = 0);
WaitForSingleObject(PI.hProcess, INFINITE);
finally
CloseHandle(PI.hThread);
CloseHandle(PI.hProcess);
end;
end else
Result:=SysErrorMessage(GetLastError);
finally
CloseHandle(StdOutPipeRead);
end;
end;
но у меня не получается совместить
CreateProcessWithLogonW и
GetDosOutput, а точнее прописываю в
CreateProcessWithLogonW
Код:
si.hStdOutput := StdOutPipeWrite;
si.hStdError := StdOutPipeWrite;
...
repeat
WasOK := ReadFile(StdOutPipeRead, Buffer, 255, BytesRead, nil);
if BytesRead > 0 then
begin
Buffer[BytesRead] := #0;
Result := Result + Buffer;
end;
until not WasOK or (BytesRead = 0);
WaitForSingleObject(PI.hProcess, INFINITE);
возвращает пустую строку