cmd的使用問題 |
尚未結案
|
ericlwl
一般會員 ![]() ![]() 發表:3 回覆:5 積分:1 註冊:2003-10-26 發送簡訊給我 |
|
ericlwl
一般會員 ![]() ![]() 發表:3 回覆:5 積分:1 註冊:2003-10-26 發送簡訊給我 |
我自己想到了一個暫時的解法,但是不滿意,不知有沒有人可以分享一下。
以下是我的暫時解法:(很笨的方法)
main() { RunProcess("cmd.exe /c", password); } RunProcess(char *CommandLine, char password[10]) { int i, charnum; STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); si.wShowWindow = SW_HIDE; // Start the child process. if( CreateProcess( NULL,CommandLine,NULL,NULL,FALSE,0,NULL, NULL, &si, &pi) != 0) { if( strlen(password) > 3 ) { WaitForSingleObject( pi.hProcess, 5000 ); for( i = 0; i < strlen(password); i ) { password[i] = toupper(password[i]); charnum = password[i]; keybd_event(charnum, 0, 0, 0); keybd_event(charnum, 0, KEYEVENTF_KEYUP, 0); } keybd_event(13, 0, 0, 0); keybd_event(13, 0, KEYEVENTF_KEYUP, 0); } } // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); } |
liangnet
中階會員 ![]() ![]() ![]() 發表:19 回覆:148 積分:83 註冊:2004-01-03 發送簡訊給我 |
|
ericlwl
一般會員 ![]() ![]() 發表:3 回覆:5 積分:1 註冊:2003-10-26 發送簡訊給我 |
|
m8815010
版主 ![]() ![]() ![]() ![]() ![]() 發表:99 回覆:372 積分:289 註冊:2003-11-13 發送簡訊給我 |
引言: 我自己想到了一個暫時的解法,但是不滿意,不知有沒有人可以分享一下。 以下是我的暫時解法:(很笨的方法)ericlwl你好main() { RunProcess("cmd.exe /c", password); } RunProcess(char *CommandLine, char password[10]) { int i, charnum; STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); si.wShowWindow = SW_HIDE; // Start the child process. if( CreateProcess( NULL,CommandLine,NULL,NULL,FALSE,0,NULL, NULL, &si, &pi) != 0) { if( strlen(password) > 3 ) { WaitForSingleObject( pi.hProcess, 5000 ); for( i = 0; i < strlen(password); i ) { password[i] = toupper(password[i]); charnum = password[i]; keybd_event(charnum, 0, 0, 0); keybd_event(charnum, 0, KEYEVENTF_KEYUP, 0); } keybd_event(13, 0, 0, 0); keybd_event(13, 0, KEYEVENTF_KEYUP, 0); } } // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); } |
ericlwl
一般會員 ![]() ![]() 發表:3 回覆:5 積分:1 註冊:2003-10-26 發送簡訊給我 |
|
m8815010
版主 ![]() ![]() ![]() ![]() ![]() 發表:99 回覆:372 積分:289 註冊:2003-11-13 發送簡訊給我 |
引言: m8815010你好: 先謝謝你讓我多學了一個方法,但因為學藝不精看不太懂列舉視窗的方法,而我在執行程式時會開啟不只一個的cmd視窗,所以.... |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |