This article is a mirror article of machine translation, please click here to jump to the original article.

View: 9441|Reply: 1

[VB] Anonymous pipeline implements CMD echo

[Copy link]
Posted on 12/6/2014 12:05:15 AM | | |
I have written one beforeCMD echo is implemented using anonymous pipelinesNow it seems that the code at that time was really weak, and I rewrote it angrily.


[mw_shl_code=c,true]void ExecuteCommand(WCHAR * pszCommand, WCHAR *pszResult, DWORD dwCount)
{
BOOL bRet = FALSE;
USES_CONVERSION;

WCHAR szCmdPath[MAX_PATH] = {0};
GetSystemDirectory(szCmdPath, sizeof(szCmdPath));
PathAppend(szCmdPath, L"cmd.exe");

SECURITY_ATTRIBUTES SecurityAttributes;
SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
SecurityAttributes.lpSecurityDescrip{filter}tor = NULL;
SecurityAttributes.bInheritHandle = TRUE;

HANDLE hRead = NULL;
HANDLE hWrite = NULL;

if(CreatePipe(&hRead, &hWrite, &SecurityAttributes, 0))
{
STARTUPINFO StartupInfo = {0};
StartupInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
StartupInfo.hStdOutput = hWrite;
StartupInfo.hStdError = hWrite;
StartupInfo.wShowWindow = SW_HIDE;

PROCESS_INFORMATION ProcessInformation = {0};

WCHAR szCurrentPath[MAX_PATH] = {0};
GetCurrentDirectory(sizeof(szCurrentPath), szCurrentPath);

if(CreateProcess(szCmdPath, pszCommand, NULL, NULL, TRUE, 0, NULL, szCurrentPath, &StartupInfo, &ProcessInformation))
{
CloseHandle(hWrite);

char szBuffer[4096] = {0};
DWORD dwRead = 0;
if(pszResult)
{
pszResult[0] = 0;
while(TRUE)
{
memset(szBuffer, 0, sizeof(szBuffer));
bRet = ReadFile(hRead, szBuffer, sizeof(szBuffer), &dwRead, NULL);
if((FALSE == bRet) || (dwRead = 0))
break;

wcscat_s(pszResult, dwCount, A2W(szBuffer));
}
}
}

CloseHandle(hRead);
}
}[/mw_shl_code]




Previous:Sense the bank card through Windows Phone
Next:Quickly extract the picture of QQ emoticon eif
Posted on 12/7/2014 5:24:30 PM |
Reading and posting back is a virtue
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com