Results 1 to 6 of 6

Thread: [RESOLVED] Explorer context menu - path argument issue

  1. #1

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Resolved [RESOLVED] Explorer context menu - path argument issue

    Hi guys,

    Just wondering if anyone has run into this problem before... My scenario is that I want to add an option to the explorer context menu that appears whenever a user right clicks on a folder or drive. So I add the following reg key:

    HKEY_CLASSES_ROOT\Folder\shell\MyProgram\command
    "(Default)" value within is set to:
    C:\MyProgram.exe "%1"

    and all works fine for folders, the %1 gets expanded to the relevant folder path that the user clicked on. However, when right clicking on a drive (e.g C drive in My Computer) the fact that the path then has a trailing backslash seems to seems to mess things up as the backslash acts as an escape character and makes the last quote mark get passed in as part of the command line (and the backslash is removed completely).

    For example if the following command is called from a context menu generated by the user right clicking on their C drive:
    "MyProgram.exe" "%1"
    You would expect the final command line to be this:
    MyProgram.exe C:\
    But what actually happens is this:
    MyProgram.exe C:"

    Anyone got a solution? I can add a backslash in manually (e.g "%1\") but then it works fine for drives and not for folders. Anyone know of a solution that will work for both?

    Thanks
    Chris
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Explorer context menu - path argument issue

    in MyProgram just check if your commandlineargs endswith : + if yes add a \

  3. #3

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Explorer context menu - path argument issue

    but I could have other command line args as well and it screws them up because now instead of having two command line args, for example:
    C:\ and /debug
    I end up with one command line arg:
    C:" /debug
    I realise that if I spent enough time I could probably build some logic into my program to handle this correctly but it seems that I really should not have to do that... there must be a way to get the command line args passed in correctly in the first place
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Explorer context menu - path argument issue

    Quote Originally Posted by chris128 View Post
    but I could have other command line args as well and it screws them up because now instead of having two command line args, for example:
    C:\ and /debug
    I end up with one command line arg:
    C:" /debug
    I realise that if I spent enough time I could probably build some logic into my program to handle this correctly but it seems that I really should not have to do that... there must be a way to get the command line args passed in correctly in the first place
    I'm not that familiar with command args but since a path can only have one colon char in it couldn't you just check it and fix it, something like...

    If Not path.Contains(":\") Then path = path.Replace(":", ":\")

  5. #5

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Explorer context menu - path argument issue

    Thanks but that's still kind of trying to work around the problem rather than fix it, plus it doesn't help with the fact that command line arguments after that path will be part of that same command line argument. Command line arguments should all be passed in separately, that's how they are supposed to work, I shouldn't be having to unscramble and make sense of them once they have actually been passed to my program
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #6

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Explorer context menu - path argument issue

    Found a simple solution instead of adding my context menu reg keys to the following location:
    HKEY_CLASSES_ROOT\Folder\Shell
    I add them to here instead:
    HKEY_CLASSES_ROOT\Directory\Shell

    All seems to work perfectly then for drives and folders

    This also means that my context menu item doesn't appear when right clicking on special 'folders' like the recycle bin, which is better for my particular application.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


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