求救:关于net send,net view或者ipconfig之类命令的

limu810812 2003-08-29 11:13:07
如何调用例如net send,net view或者ipconfig……之类的命令,并且把结果用控件显示?
...全文
50 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
limu810812 2003-08-30
  • 打赏
  • 举报
回复
谢谢各位了!
不好意思分数少了点,以后再提问的时候会注意的。
今天晚上来结帖
jingrunx 2003-08-30
  • 打赏
  • 举报
回复
RedirectOutput(NULL, edtCommandLine->Text.c_str(),
OutputMemo->Lines, ErrorMemo->Lines,
cbxShowWindow->Checked ? SW_SHOW : SW_HIDE);


不过你给的分太少了
jingrunx 2003-08-30
  • 打赏
  • 举报
回复
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include <algorithm>
using namespace std;
#include "RedirectThread.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
__fastcall TRedirectThread::TRedirectThread(bool CreateSuspended, HANDLE hHandle, TStrings* Strings)
: TThread(CreateSuspended), hRedirect(hHandle), OutputWindow(Strings)
{
FreeOnTerminate = true;
}
//---------------------------------------------------------------------------
void __fastcall TRedirectThread::Execute()
{
char lpszBuf[256];
char *firstp, *lastp, *curp;
DWORD nNumOfBytes, nReadBytes, nLineBytes;

__try {
try {
firstp = lpszBuf;
nNumOfBytes = sizeof(lpszBuf);
while(!Terminated && ::ReadFile(hRedirect, lpszBuf, nNumOfBytes, &nReadBytes, NULL)) {
strBuffer.append(lpszBuf, nReadBytes);

int spos = 0, epos;
while(true) {
epos = strBuffer.find(lpszEnterFlag, spos);
if(epos == -1) break;
strLine.assign(strBuffer, spos, epos-spos);
Synchronize(Update);
spos = epos + strlen(lpszEnterFlag);
}
strBuffer.assign(strBuffer, spos, strBuffer.size()-spos);
}
} catch(EOSError& E) {
}
} __finally {
::CloseHandle(hRedirect);
}
}
//---------------------------------------------------------------------------
void __fastcall TRedirectThread::Update(void)
{
OutputWindow->Add(strLine.c_str());
}
//---------------------------------------------------------------------------
void __stdcall RedirectOutput(
LPTSTR pApplicationName, LPTSTR lpCommandLine,
TStrings* StdOutputStrings, TStrings* StdErrorStrings, WORD swShow)
{
HANDLE hStdOutput, hStdError;

GetCreatedProcessOutHandle(pApplicationName, lpCommandLine, swShow,
&hStdOutput, &hStdError);
if(StdOutputStrings) {
new TRedirectThread(false, hStdOutput, StdOutputStrings);
}
if(StdErrorStrings) {
new TRedirectThread(false, hStdError, StdErrorStrings);
}
}
//---------------------------------------------------------------------------
HANDLE __stdcall GetCreatedProcessOutHandle(
LPTSTR pApplicationName, LPTSTR lpCommandLine, WORD swShow,
PHANDLE hStdOutput, PHANDLE hStdError)
{
HANDLE hStdOutputRead, hStdOutputWrite;
HANDLE hStdErrorRead, hStdErrorWrite;
SECURITY_ATTRIBUTES sa;

sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;

Win32Check(::CreatePipe(&hStdOutputRead, &hStdOutputWrite, &sa, 0));
Win32Check(::CreatePipe(&hStdErrorRead, &hStdErrorWrite, &sa, 0));

STARTUPINFO si;
PROCESS_INFORMATION pi;

si.cb = sizeof(si);
::GetStartupInfo(&si);
si.dwFlags |= STARTF_USESHOWWINDOW;
si.wShowWindow = swShow;
si.dwFlags |= STARTF_USESTDHANDLES;
si.hStdOutput = hStdOutputWrite;
si.hStdError = hStdErrorWrite;

Win32Check(::CreateProcess(pApplicationName, lpCommandLine,
NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi));

Win32Check(::CloseHandle(hStdOutputWrite));
Win32Check(::CloseHandle(hStdErrorWrite));

if(hStdOutput) *hStdOutput = hStdOutputRead;
if(hStdError) *hStdError = hStdErrorRead;

return hStdOutputRead;
}
//---------------------------------------------------------------------------
jingrunx 2003-08-30
  • 打赏
  • 举报
回复
//---------------------------------------------------------------------------

#ifndef RedirectThreadH
#define RedirectThreadH
//---------------------------------------------------------------------------
#include <string>
using namespace std;
#include <Classes.hpp>
//---------------------------------------------------------------------------
void __stdcall RedirectOutput(
LPTSTR pApplicationName, LPTSTR lpCommandLine,
TStrings* StdOutputStrings, TStrings* StdErrorStrings,
WORD swShowWindow = SW_HIDE);

HANDLE __stdcall GetCreatedProcessOutHandle(
LPTSTR pApplicationName, LPTSTR lpCommandLine,
WORD swShowWindow,
PHANDLE hStdOutput, PHANDLE hStdError);
//---------------------------------------------------------------------------
class TRedirectThread : public TThread
{
static const char* lpszEnterFlag;
private:
HANDLE hRedirect;
string strBuffer, strLine;
TStrings* OutputWindow;
protected:
void __fastcall Execute();
void __fastcall Update(void);
public:
__fastcall TRedirectThread(bool CreateSuspended, HANDLE hHandle, TStrings* Strings);
};
const char* TRedirectThread::lpszEnterFlag = "\r\n";
//---------------------------------------------------------------------------
#endif
sprewellkobe 2003-08-29
  • 打赏
  • 举报
回复
PIPE
limu810812 2003-08-29
  • 打赏
  • 举报
回复
能不能具体点,举个例证 谢谢!
nuaacims 2003-08-29
  • 打赏
  • 举报
回复
用ShellExecute方式调用这些命令,然后用管道pipe把结果输出到一个memo之类的文本控件中
FallenAngel 2003-08-29
  • 打赏
  • 举报
回复
你自己搜一下吧
关键字可以是
Pipe 管道

13,824

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧