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... :o

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?

August 17th, 2011, 04:45 PM

S_M_A

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...

August 17th, 2011, 07:50 PM

Eri523

Re: Length limit on Run registry entries

Quote:

Originally Posted by S_M_A

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.

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... :rolleyes:) 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... :D

September 9th, 2011, 02:18 AM

okayo0

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?