Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ShellExecuteEx path question. [modified] (fixed)

ShellExecuteEx path question. [modified] (fixed)

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpperlvisual-studiohelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #1

    Edit : Issue was mostly with the spawned EXE that did not handled parameters properly. Now everything is working ok. Thanks. I'm trying to figure out a couple of issues I have with some path that contains spaces when using ShellExecuteEx : The current directory contains space : C:\Users\me\Documents\Visual Studio 2008\Projects\asdcasd\asdcasd

    TCHAR Buffer\[MAX\_PATH\];
    DWORD dwRet;
    dwRet = GetCurrentDirectory(MAX\_PATH, Buffer);
    
    // wrap the path with quotes
    CString sWorkingPath;
    sWorkingPath.Format( \_T("\\"%s\\""), Buffer );
    
    CString command ( \_T("XMLtoPDF.exe"));
    CString parameters( \_T("")); // /noopen
    
    // wrap the path with quotes.
    CString sExe;
    sExe.Format ( \_T("\\"%s\\\\%s\\""), Buffer, command);
    
    SHELLEXECUTEINFO ShExecInfo = {0};
    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = SEE\_MASK\_NOCLOSEPROCESS;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = \_T("open");
    ShExecInfo.lpFile = sExe;
    ShExecInfo.lpParameters = parameters;	
    ShExecInfo.lpDirectory = sWorkingPath;
    ShExecInfo.nShow = SW\_SHOW;
    ShExecInfo.hInstApp = NULL;	
    ShellExecuteEx(&ShExecInfo);
    WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
    

    The exe spawns a console (it's a perl byte-compiled stand-alone) and tells me the path is not good : C:\Users\me\Documents\Visual does not exists. I've checked the path and they all semms to be double-quoted to handle the spaces. Am i missing something ? Thanks a bunch.

    Watched code never compiles.

    modified on Thursday, July 8, 2010 3:52 PM

    D 1 Reply Last reply
    0
    • M Maximilien

      Edit : Issue was mostly with the spawned EXE that did not handled parameters properly. Now everything is working ok. Thanks. I'm trying to figure out a couple of issues I have with some path that contains spaces when using ShellExecuteEx : The current directory contains space : C:\Users\me\Documents\Visual Studio 2008\Projects\asdcasd\asdcasd

      TCHAR Buffer\[MAX\_PATH\];
      DWORD dwRet;
      dwRet = GetCurrentDirectory(MAX\_PATH, Buffer);
      
      // wrap the path with quotes
      CString sWorkingPath;
      sWorkingPath.Format( \_T("\\"%s\\""), Buffer );
      
      CString command ( \_T("XMLtoPDF.exe"));
      CString parameters( \_T("")); // /noopen
      
      // wrap the path with quotes.
      CString sExe;
      sExe.Format ( \_T("\\"%s\\\\%s\\""), Buffer, command);
      
      SHELLEXECUTEINFO ShExecInfo = {0};
      ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
      ShExecInfo.fMask = SEE\_MASK\_NOCLOSEPROCESS;
      ShExecInfo.hwnd = NULL;
      ShExecInfo.lpVerb = \_T("open");
      ShExecInfo.lpFile = sExe;
      ShExecInfo.lpParameters = parameters;	
      ShExecInfo.lpDirectory = sWorkingPath;
      ShExecInfo.nShow = SW\_SHOW;
      ShExecInfo.hInstApp = NULL;	
      ShellExecuteEx(&ShExecInfo);
      WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
      

      The exe spawns a console (it's a perl byte-compiled stand-alone) and tells me the path is not good : C:\Users\me\Documents\Visual does not exists. I've checked the path and they all semms to be double-quoted to handle the spaces. Am i missing something ? Thanks a bunch.

      Watched code never compiles.

      modified on Thursday, July 8, 2010 3:52 PM

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Suggestions: 1) Use GetShortPathName(). 2) Use UrlEscape(). I'm not sure if either will work, however.

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Man who follows car will be exhausted." - Confucius

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups