Questo articolo è un articolo speculare di traduzione automatica, clicca qui per saltare all'articolo originale.

Vista: 9441|Risposta: 1

[VB] Pipeline anonima implementa l'eco CMD

[Copiato link]
Pubblicato su 06/12/2014 00:05:15 | | |
Ne ho già scritta unaL'eco CMD è implementato utilizzando pipeline anonimeOra sembra che il codice di quel momento fosse davvero debole, e l'ho riscritto con rabbia.


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

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

SECURITY_ATTRIBUTES SecurityAttributes;
SecurityAttributes.nLength = dimensione(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(VERO)
{
memset(szBuffer, 0, sizeof(szBuffer));
bRet = ReadFile(hRead, szBuffer, sizeof(szBuffer), & dwRead, NULL);
if((FALSO == bRet) || (dwRead = 0))
pausa;

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

CloseHandle(hRead);
}
}[/mw_shl_code]




Precedente:Percepisci la carta bancaria tramite Windows Phone
Prossimo:Estrai rapidamente l'immagine dell'emoticon di QQ eif
Pubblicato su 07/12/2014 17:24:30 |
Leggere e rispondere è una virtù
Disconoscimento:
Tutto il software, i materiali di programmazione o gli articoli pubblicati dalla Code Farmer Network sono destinati esclusivamente all'apprendimento e alla ricerca; I contenuti sopra elencati non devono essere utilizzati per scopi commerciali o illegali, altrimenti gli utenti dovranno sostenere tutte le conseguenze. Le informazioni su questo sito provengono da Internet, e le controversie sul copyright non hanno nulla a che fare con questo sito. Devi eliminare completamente i contenuti sopra elencati dal tuo computer entro 24 ore dal download. Se ti piace il programma, ti preghiamo di supportare software autentico, acquistare la registrazione e ottenere servizi autentici migliori. In caso di violazione, vi preghiamo di contattarci via email.

Mail To:help@itsvse.com