//================================================================ |
function RunDosCommand(Command: string ): string ; |
// SD : TSecurityDescriptor; |
Dest: array [ 0..1023 ] of char ; |
CmdLine: array [ 0..512 ] of char ; |
Avail,
ExitCode,wrResult: DWORD; |
osVer . dwOSVersionInfoSize
:= Sizeof(TOSVERSIONINFO); |
if osVer . dwPlatformId
= VER_PLATFORM_WIN32_NT then |
// InitializeSecurityDescriptor(@SD,SECURITY_DESCRIPTOR_REVISION); |
// SetSecurityDescriptorDacl(@SD,True,nil,False); |
SA . nLength
:= SizeOf(SA); |
SA . lpSecurityDescriptor
:= nil ; //@SD; |
SA . bInheritHandle
:= True ; |
CreatePipe(hReadPipe,
hWritePipe,@SA, 0 ); |
CreatePipe(hReadPipe,
hWritePipe, nil , 1024 ); |
FillChar(SI, SizeOf(SI), 0 ); |
SI . cb
:= SizeOf(TStartUpInfo); |
SI . wShowWindow
:= SW_HIDE; |
SI . dwFlags
:= STARTF_USESHOWWINDOW; |
SI . dwFlags
:= SI . dwFlags or STARTF_USESTDHANDLES; |
SI . hStdOutput
:= hWritePipe; |
SI . hStdError
:= hWritePipe; |
StrPCopy(CmdLine,
Command); |
if CreateProcess( nil , CmdLine, nil , nil , True , NORMAL_PRIORITY_CLASS, nil , nil , SI,PI) then |
wrResult
:= WaitForSingleObject(PI . hProcess, 500 ); |
// if PeekNamedPipe(hReadPipe,nil,0,nil,@Avail,nil)then |
if PeekNamedPipe(hReadPipe,
@Dest[ 0 ], 1024 , @Avail, nil , nil ) then |
TmpList
:= TStringList . Create; |
FillChar(Dest, SizeOf(Dest), 0 ); |
ReadFile(hReadPipe,
Dest[ 0 ], Avail,BytesRead, nil ); |
TmpStr := Copy(Dest, 0 ,
BytesRead - 1 ); |
if wrResult <>WAIT_TIMEOUT then ExitCode
:= 1 ; |
GetExitCodeProcess(PI . hProcess,
ExitCode); |
CloseHandle(PI . hProcess); |
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理