Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 09, 2016, 07:14:28 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Commandline execution VC++ using ShellExec  (Read 1269 times)

renjithcr

  • Participant
  • Joined in 2015
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Commandline execution VC++ using ShellExec
« on: November 05, 2015, 10:49:09 AM »
 Hi i am trying to save a screenshot file to the following path C:\Users\Rn\Desktop\ScreenshotCaptor. But i cant change the screenshot directory.
 
 i used the following link to find the commandline options : http://www.donationc...ptor/help/index.html

 please find my code below. any help is appreciated.

 ////////////////////////////// VC++ code  //////////////////////////////

  CString sApp = _T("C:\\Program Files (x86)\\ScreenshotCaptor\\ScreenshotCaptor.exe");

  CString sParameters = _T("-show -capture screen -format png -dir \"C:\\Users\\Rn\\Desktop\\ScreenshotCaptor\" ");

  CString sWorkDir = _T("C:\\Users\\Rn\\Desktop\\ScreenshotCaptor");

  int nRet = (int)ShellExecute(NULL, NULL, sApp, sParameters, sWorkDir, SW_SHOWNORMAL);

/////////////////////////////////////////////////////////////////////////////

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,431
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Commandline execution VC++ using ShellExec
« Reply #1 on: November 05, 2015, 10:58:21 AM »
For what you are trying to do (commandline screenshot grabbing), may I recommend Screenshot Captor's little brother: MiniCap
It is made to do exactly what you are doing and is built with same codebase as SC.

renjithcr

  • Participant
  • Joined in 2015
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: Commandline execution VC++ using ShellExec
« Reply #2 on: November 10, 2015, 04:35:32 AM »
Thanks Mouser... it works with ShellExecute()

is there any way to wait until the screen capture is completed? I mean using ShellExecuteEx and WaitForSingleObject functions?

my following code is not working

    SHELLEXECUTEINFO ShExecInfo = { 0 };
    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = NULL;
    ShExecInfo.lpFile = GetMiniCapAppPath().AllocSysString();
    ShExecInfo.lpParameters = sParameters.AllocSysString();
    ShExecInfo.lpDirectory = NULL;
    ShExecInfo.nShow = SW_SHOWNORMAL;
    ShExecInfo.hInstApp = NULL;
    ShellExecuteEx(&ShExecInfo);
    WaitForSingleObject(ShExecInfo.hProcess, INFINITE);

« Last Edit: November 10, 2015, 07:44:00 AM by renjithcr »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,431
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Commandline execution VC++ using ShellExec
« Reply #3 on: November 10, 2015, 08:45:49 AM »
When you say your code isn't working -- specifically what is happening?

renjithcr

  • Participant
  • Joined in 2015
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: Commandline execution VC++ using ShellExec
« Reply #4 on: November 10, 2015, 09:17:46 AM »


With ShellExecute() i can make a screenshot.

CString sParameters = _T("-save \"") + sImagePath + _T("\" -captureappbyname \"") + sUniNgeExeName + _T("\" -exit");
iRet = (int)ShellExecute(NULL, NULL, GetMiniCapAppPath(), sParameters, NULL, SW_SHOWNORMAL);


but with ShellExecuteEx() and then WaitForSingleObject() as described in my previous post i want to wait until the MiniCap executable exits (using -exit in sParameters). but i see the executable on Task manager. and the function call WaitForSingleObject() waits.



mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,431
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Commandline execution VC++ using ShellExec
« Reply #5 on: November 10, 2015, 09:19:27 AM »
so you are saying that minicap never exits on its own?

try calling the commandline on your own in a dos commandline box to make sure it exits when called manually.

it seems to me that your commandline args may be slightly wrong, instead of adding at the end: + _T("\" -exit");
try: + _T(" -exit");

renjithcr

  • Participant
  • Joined in 2015
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: Commandline execution VC++ using ShellExec
« Reply #6 on: November 10, 2015, 09:19:54 AM »
Yes. those were the closing symbols _T(\") for -captureappbyname "filename.exe"
« Last Edit: November 10, 2015, 09:35:14 AM by renjithcr »

renjithcr

  • Participant
  • Joined in 2015
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: Commandline execution VC++ using ShellExec
« Reply #7 on: November 10, 2015, 10:15:52 AM »
it works with both the versions... Thanks mouser...