-
February 7th, 2013, 11:29 PM
#1
How to use 2 command in sytem() function ?
I want to run Unhidden.exe in drive N: and send char to that program. I use function like this
Code:
system("N:/Unhidden.exe");
it can open Unhidden.exe but it run in visual studio 2010\Projects\ . I try to use command N: and Unhidden.exe in cmd it can run in drive N: . So I try to use function like this
system("N:");
system("Unhidden.exe");
but it not found Unhidden.exe . How to use 2 command in sytem() function ?
-
February 8th, 2013, 02:09 AM
#2
Re: How to use 2 command in sytem() function ?
Use CreateProcess API instead of system.
Victor Nijegorodov
-
February 8th, 2013, 04:20 AM
#3
Re: How to use 2 command in sytem() function ?
How to use CreateProcess . I read example and try to use the function like this
Code:
DWORD WINAPI hidden_file(LPVOID lp)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
LPTSTR szCmdline1 = _tcsdup(TEXT("N:/Unhidden.exe"));
CreateProcess(NULL, szCmdline1,
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi );
return 0;
}
but when I send key Y with this code it run in visual studio 2010\Projects\
Code:
ir[0].EventType = KEY_EVENT;
ir[0].Event.KeyEvent.bKeyDown = TRUE;
ir[0].Event.KeyEvent.dwControlKeyState = 0;
ir[0].Event.KeyEvent.uChar.UnicodeChar = 'y';
ir[0].Event.KeyEvent.wRepeatCount = 1;
ir[0].Event.KeyEvent.wVirtualKeyCode = 'Y';
ir[0].Event.KeyEvent.wVirtualScanCode = MapVirtualKey('Y', MAPVK_VK_TO_VSC);
And if I use this code it not show anything in command window.
Code:
LPTSTR szCmdline1 = _tcsdup(TEXT("N:"));
CreateProcess(NULL, szCmdline1,
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi );
LPTSTR szCmdline2 = _tcsdup(TEXT("Unhidden.exe"));
CreateProcess(NULL, szCmdline2,
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi );
return 0;
}
-
February 8th, 2013, 04:41 AM
#4
Re: How to use 2 command in sytem() function ?
Originally Posted by mmc01
How to use CreateProcess . I read example and try to use the function like this
Code:
DWORD WINAPI hidden_file(LPVOID lp)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
LPTSTR szCmdline1 = _tcsdup(TEXT("N:/Unhidden.exe"));
CreateProcess(NULL, szCmdline1,
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi );
return 0;
}
Why do you use _tcsdup?
You don't need to duplicate this string.
But if you do want to call _tcsdup then you must somewhere call to avoid memory leaks!
Second: you don't check the return value of CreateProcess. Thus you don't know whether it failed or succeeded. And if it failed then all your other attempts to work with the Unhidden.exe do not make any sense!
Originally Posted by mmc01
but when I send key Y with this code it run in visual studio 2010\Projects\
Code:
ir[0].EventType = KEY_EVENT;
ir[0].Event.KeyEvent.bKeyDown = TRUE;
ir[0].Event.KeyEvent.dwControlKeyState = 0;
ir[0].Event.KeyEvent.uChar.UnicodeChar = 'y';
ir[0].Event.KeyEvent.wRepeatCount = 1;
ir[0].Event.KeyEvent.wVirtualKeyCode = 'Y';
ir[0].Event.KeyEvent.wVirtualScanCode = MapVirtualKey('Y', MAPVK_VK_TO_VSC);
[/CODE]
Where do you send key Y to? You didn't write anything about sending keys...
And what is ir[...]?
Originally Posted by mmc01
And if I use this code it not show anything in command window.
Code:
LPTSTR szCmdline1 = _tcsdup(TEXT("N:"));
CreateProcess(NULL, szCmdline1,
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi );
LPTSTR szCmdline2 = _tcsdup(TEXT("Unhidden.exe"));
CreateProcess(NULL, szCmdline2,
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi );
return 0;
}
Because it is not a "code". It is just a nonsense!
Victor Nijegorodov
-
February 8th, 2013, 09:16 AM
#5
Re: How to use 2 command in sytem() function ?
Originally Posted by mmc01
How to use 2 command in sytem() function ?
Write a batch file?
Best regards,
Igor
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|