CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2013
    Posts
    15

    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 ?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: How to use 2 command in sytem() function ?

    Use CreateProcess API instead of system.
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2013
    Posts
    15

    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;
    }

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: How to use 2 command in sytem() function ?

    Quote Originally Posted by mmc01 View Post
    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
    Code:
    free(szCmdline1);
    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!

    Quote Originally Posted by mmc01 View Post
    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[...]?


    Quote Originally Posted by mmc01 View Post
    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

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How to use 2 command in sytem() function ?

    Quote Originally Posted by mmc01 View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured