CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Post Length limit on Run registry entries

    I have written an app that writes one or more entries to the HKCU\Software\Microsoft\Windows\CurrentVersion\Run registry key, created based on information enterd by the user. While testing it, I yesterday hit a limit of these registry entries (more accidentally than not).

    After some more specific tests I narrowed it down to these registry entries being limited to a maximum length of MAX_PATH (260) including the null terminator. Note that, unlike what one might probably think, that limit doesn't pertain to the path to the executable I'm going to start, but instead to the registry entry in total, i.e. including any command line args I pass to the app to be started by the registry entry. If the limit is exceeded, no error of any kind gets thrown (not even an entry in the Windows event log); the entry is plainly ignored. (To clarify, it's no problem to write the entry to the registry and read it back, it just doesn't get executed.)

    Since this app is only aimed at advanced users anyway, I don't think it's a problem to impose a constraint on the data they enter to base the registry entry on, based on the length of the resulting registry entry, and that's how I currently handle it. However, without requiring the user to know how exactly the registry entries are constructed (which IMO is non-trivial even to an advanced user), the error message is somehow vague: It tells the number of excess characters in the resulting registry entry and instructs the user to "shorten some of the values entered to achieve an appropriate registry entry"... Not great, but it's the best I could figure at the time...

    However, while I think I can deploy my app the way it currently is, my primary reason for this post is that I didn't find any relevant information on that, let alone authoritative documentation by MS (tried MSDN seach, CG forum search and Google), and I only have XP Pro SP3 to test that here. So, does anyone have more information about that, in particular on whether this restriction has been relieved in Vista or Win7?
    Last edited by Eri523; August 17th, 2011 at 05:24 PM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Length limit on Run registry entries

    I didn't know that MAX_PATH was including the parameters, I've always thought of it as just the exe path. Anyway, the closest I get in searching for this is what's stated for CreateProcess http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx. As you describe it it seems like the run string is passed as lpCommandLine and lpApplicationName is set to NULL.

    Regarding if the restriction has been lifted in Vista or Win7. The MSVC 2005 help (offline MSDN) says that lpCommandLine can be 32k for all targets but Win2000 so it seems that MS has gone the other way...
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #3
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Length limit on Run registry entries

    Quote Originally Posted by S_M_A View Post
    I didn't know that MAX_PATH was including the parameters, I've always thought of it as just the exe path.
    Yes, that's how IMO probably most of all people would interpret it, including myself.

    Anyway, the closest I get in searching for this is what's stated for CreateProcess http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx. As you describe it it seems like the run string is passed as lpCommandLine and lpApplicationName is set to NULL.

    Regarding if the restriction has been lifted in Vista or Win7. The MSVC 2005 help (offline MSDN) says that lpCommandLine can be 32k for all targets but Win2000 so it seems that MS has gone the other way...
    Thanks for that information. Though it's not directly related to the topic, it took me some steps further. With a Win32 console test app I quickly hacked together (well, actually not that quickly... ) I tested passing the entire command, i.e. executable name plus command line arguments, to CreateProcess() via the lpCommandLine parameter (IMO a reasonable assumption of yours that the registry-interpreting code does it just that way). And under my XP that API function actually did accept more than MAX_PATH characters. I didn't test all the way up to 32k but it worked perfectly fine with up to 290.

    So that restriction obviously isn't imposed by the CreateProcess() API; looks like it rather is some remnant from the days of Win95 in the code interpreting the registry entries, which only can be regarded unnecessarily overcautious nowadays.

    BTW, I don't know how many times I actually read (parts of) that CreateProcess() MSDN article, but I never noticed that funky algorithm described in the section about the lpApplicationName parameter used to probe ambigous executable name/command args combinations...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  4. #4
    Join Date
    Sep 2011
    Posts
    3

    Re: Length limit on Run registry entries

    are you actually on a domain and using roaming profiles?

    have you tried running regclean or some such utility to wipe out cruft?

    registryfast

  5. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Length limit on Run registry entries

    Quote Originally Posted by okayo0 View Post
    are you actually on a domain and using roaming profiles?

    have you tried running regclean or some such utility to wipe out cruft?
    No to both. Why?
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

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