How to recover from PATH being truncated to 1024 characters by SETX

12

3

I received an error on Windows 8 after trying to use SETX to add JAVA.exe to the Windows PATH variable:

WARNING: The data being saved is truncated to 1024 characters.

After a reboot, I notice that the PATH is indeed much shorter than before. I've since read that SETX can't handle more than 1024 characters. That would have been good to know in the article which recommended using it.

I am wondering if my system will be unstable now that (presumably) some of the directories no longer appear in the PATH variable. The end of the string is clearly cut off mid-directory (at Pr):

(...) ;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Pr

Is there any way to roll back or anywhere that the previous value of PATH was captured. Man, I can't believe this kind of stuff can still happen in Windows after 29 years.

Doug

Posted 2014-09-17T00:15:27.420

Reputation: 275

Different from this question because that user is just interested in finding out another way to edit the PATH variable. I am wondering if my system is in a damaged state and how I can recover. http://superuser.com/questions/387619/overcoming-the-1024-character-limit-with-setx

– Doug – 2014-09-17T00:16:58.833

1you system won't be unstable, but find out from another windows 8 user or a webpage, what the path should be in a fresh windows 8 installation, and use that. And grow it if necessary. Always back up your PATH before using setx. Maybe there's a system restore you can do in windows 8 that can roll the path back? it's worth a try EDIT ADDED- next time when using setx, first do echo %PATH%>afile <-- and try setx on some other variable not PATH. Then when you're sure you have the setx line right, after trying it on TESTPATH,then do setx on PATH. – barlop – 2014-09-17T00:20:56.400

Good suggestions, thanks. Default path: http://superuser.com/questions/657769/what-is-the-default-path-setting-for-windows-8

– Doug – 2014-09-17T00:22:35.660

1If you haven't restarted a second time yet, you can look arty ghee CurrentControlSet backups. – Bob – 2014-09-17T00:30:24.667

see what I added in my edit re using setx. Also, (if I recall), there is no need to reboot. Just open a new command prompt and you see the new path. And also, since setx sets things in the registry.. you can always use the reg query command to view what it did. e.g. set reglocation=HKLM....<ENTER> reg query "%reglocation%" – barlop – 2014-09-17T00:31:07.163

@Bob backups? what kind of backup would disappear after a restart? after running setx, the registry is changed e.g. HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment or HKCU\Environment or whatever You may be right re backup (Though he did restart) but what is the reg key/location for what you are calling the backup? – barlop – 2014-09-17T00:33:42.110

@barlop The "Last Known Good Configuration", under HKLM\System\ControlSet002\... I'm not sure if that's overwritten on the first or second restart. Come to think of it, maybe the first, in which case it's already too late. – Bob – 2014-09-17T00:46:59.427

3@Bob well if one hasn't restarted, and still has the same cmd window open, then after a setx, the path variable still isn't set in the current cmd window, and you can just echo %path% Anyhow, maybe system restore restores the path? – barlop – 2014-09-17T01:39:41.150

@barlop That's a good point! System Restore should work here. – Bob – 2014-09-17T02:09:03.073

Doug what are you waiting for re system restore, have you tried it yet? do erport back – barlop – 2014-09-17T02:34:21.110

@barlop My system does seem stable, so I'm not going to go through with a system restore even though I think it's a good idea. If I have problems, then I will do a restore and report back, but until then I'm not going to chance it. Sys Restores have burned me in the past. – Doug – 2014-09-17T04:07:28.603

Restores are far more stable since Vista, so... if you had trouble with XP, it's probably fine now. – Bob – 2014-09-17T05:42:13.097

Note that when using commands like "setx PATH "%PATH%;<yourvar>" /M" you are effectively expanding the system + user PATH which will double your path and soon cause truncation after 1024 chars as noted here http://stackoverflow.com/questions/19287379/how-do-i-add-to-the-windows-path-variable-using-setx-having-weird-problems#26947177

– mkoertgen – 2016-02-12T14:41:24.420

1

about stability: basically, to get Windows itself working well, you just need %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\. Everything else is 3rd party software. nVidia will re-add its entries on driver update, and it works well even without. Path-related problems are rare and usually apparent, so you can just deal with them case-by-case. About expanding path: use pathman.exe from resource kit. But bear in mind limits http://superuser.com/a/387625

– LogicDaemon – 2016-10-07T15:19:50.277

Answers

3

PATH is saved in the Registry at

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

If you have system restore points, you can find the relevant key and restore it.

Sir Adelaide

Posted 2014-09-17T00:15:27.420

Reputation: 4 758

2There will typically be several "ControlSetXXX" registry keys, of which the CurrentControlSet key mentioned is one. No need for any restore points to just have a look at them. – kreemoweet – 2017-02-13T16:52:34.893

0

Don't have enough reputation to comment here, but @kreemoweet's comment - unfortunately, Windows 10 (and I believe 8/8.1 as well) disabled the "last known good config" option and the associated backups that it used to be able to restore (the ControlSet### that you speak of). This behavior can be re-enabled via a reg fix, but unless the user manually did this, its very likely that they will only find one control set (which will in fact be the CurrentControlSet) when looking in the registry). So a system restore might be in order here.

In case anyone else comes across this, the way to re-enable the ControlSet### backups in the registry is to add a reg value:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Configuration Manager

Name: BackupCount
Type: DWORD
Value: 1 = store one backup in registry (one "last known good config")
    2 = store two backups in registry (two "last known good configs")

The above enables the ControlSet### backups. Then, if you also want to enable the "last known good config" option on the (legacy) boot menu (which would also need to be re-enabled in Win8/8.1 I believe, for this option to actually show up), you need to add:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Configuration Manager\LastKnownGood

Name: Enabled
Type: DWORD
Value: 1 = enabled
    0 = disabled

dwillis77

Posted 2014-09-17T00:15:27.420

Reputation: 1