Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 588501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:19:30+00:00 2026-05-13T15:19:30+00:00

Our clients have a string stored in their registry which is an executable command.

  • 0

Our clients have a string stored in their registry which is an executable command. The string may or may not have quotes around the target path, and may or may not have parameters. For example:

“C:\path\file.exe” param1=value1 param2=value2
C:\path\file.exe param1=value1 param2=value2
“C:\path\file.exe”
C:\path\file.exe
“C:\path\file with spaces.exe” param1=value1 param2=value2
“C:\path\file with spaces.exe”

I need to get the directory of the target path, i.e. C:\path.

  • I tried Path.GetDirectoryName, but that fails with “Illegal characters in path.”
  • I also tried creating a ProcessStartInfo object, but that doesn’t seem to have the smarts to parse the string.
  • I fiddled with Uri, but didn’t have any luck there either.

I have a solution using a regular expression (which I will post below as an answer), but this seems like a “there-must-be-a-built-in-.Net-helper-class-for-this” problem.

Is there a class I’m missing, or just not using the classes above correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:19:30+00:00Added an answer on May 13, 2026 at 3:19 pm

    Here’s a regular expression that is working. But, like I said in my question, is there a better way? Or are there cases where this will fail?

    Regex pattern = new Regex(@"^(?<quot>"")?(?<path>(?(quot)[^""]|\S)*)", RegexOptions.ExplicitCapture);
    var match = pattern.Match(value);
    return Path.GetDirectoryName(match.Groups["path"].Value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a lot of pre-existing BMPs (and our clients have pre-existing bmps as
Due to our clients authentication and network topology we have a number of Windows
we have a public asmx service that is accessed by our clients through SOAP
We have a data grid to display member records for our clients. We recently
I have clients that use our web site (asp.net) that they have to be
I have a need to match cold leads against a database of our clients.
i have an web service and one of the parameter our clients needs to
We design and host websites for our clients/sales force. We have our own domain:
I have an MVC3 view that's design to run reports for our clients. In
Our client is using Microsoft CRM 2011 outlook client and they have a unique

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.