SQL Server with Mr. Denny

Nov 2 2016   4:00PM GMT

Length limit of the Run and RunOnce registry keys

Denny Cherry Denny Cherry Profile: Denny Cherry

Tags:
Microsoft Windows

Microsoft has had the registry keys for Run and RunOnce in the registry since the registry was introduced in Windows 95 and Windows NT 4.  But in the 20+ years that those keys have been there (and I’ve used them for a variety of things) I’ve never known that there was a limit on the length of the commands that you could put into those keys.

I found this while working on a client project when I needed to kick off some powershell automatically when the server restarted to get it added to the domain, as well as do a few other things.  But for some reason the key just wasn’t running.

I did a LOT of digging around the Internet and I stumbled across this old Stack Overflow post (from 2012) which in the comments talks about how there’s a limit of 256 characters.  I threw the command in Microsoft word and low and behold my command was 350+ characters long.

The next step was to change the PowerShell script that created the command to put it into a batch file and then setup the RunOnce key to run the batch file instead, and it worked on the next try.

So here it is documented for all the world to see, sometime in the mid 1990s, someone at Microsoft set the length of a command at 256 characters, probably to save memory and because “why would anyone need a command longer than 256 characters”.  And today in 2016 it bit me.

Denny

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: