Welcome to MSFN

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.


tomasz86

How to get around the 2047 characters CMD string limitation

36 posts in this topic

http://support.microsoft.com/kb/830473

In Windows NT 4.0 and 2000 the maximum length of the string is only 2047 characters while in XP and 2003 it's 8191. In order to get around this you should just replace CMD.EXE in your system with the one from XP. I thought that there may be some other system files would have to be replaced too but no, replacing CMD.EXE is enough.

CMD.EXE 5.1.2600.5512

from XP SP3 seems to work OK in Windows 2000 (no unofficial updates required).

0

Share this post


Link to post
Share on other sites

In Windows NT 4.0 and 2000 the maximum length of the string is only 2047 characters ....

Just in case:

http://dictionary.reference.com/browse/only

Of course having a line in batch longer than 2047 characters is very common, as an example, you cannot have this command:

DIR /B C:\a senselessly long directory name containing\another pretty much unusefully and stupidly named directory\which is nothing but a container for another directory that contains at least another directory\which in itself is a container\possibly the matrioschkas were not invented by the good Russian guys, but were originated in Poland\but actually the idea of a path is that of being easily accessible and normally the contents of a file goes inside it and not in it’s tiitle nor in the path to it\though of course everyone has his (or her) right to freedom I find it very rare than any NT4 or Win2K (please read as Windows 2000 Professional Edition or Windows 2000 Server Edition) user has ever seen in real life a longer than (say) 200 (at the most) command line – nor I have ever seen a command line tool that – when enclosing ALL available parameters and switches has ever reached that length – so all in all if you use absolute paths to call a tool that is residing on a 256 long path and having BOTH a source and target among it’s parameters – you manage to get at the most WHAT 800 characters – let’s double it to 1600 and you still have 400 + 47 characters before hitting this limit\just for your info at this point (including spaces) we are around 1300 characters before this backslash\so we can continue writing senseless directory names that noone will ever use (in his right mind) in real life if not to prove a completely senseless point about the max length of the command line that the NT and Win2K will be able to accept\you see I made my point in much less than 2047 characters so I have to continue writing this \I wonder why the good MS guys instead of saying it’s by design which is what they normally do on actually relevant bugs took instead the time to fix it – as I see it this happened only because they found this by chance in the source code of CMD.EXE and in order to get a pat on the shoulder or however make himself more visible the anonymous programmer which found it managed to make a bug submission and solve it

working properly in NT and 2K. :whistle:

jaclaz

0

Share this post


Link to post
Share on other sites

I encountered this problem in "real life" and that's why I tried the CMD.EXE from XP and started this topic :w00t:

This is the line:

HKLM,"SYSTEM\CurrentControlSet\Services\ServiceModelEndpoint 3.0.0.0\Performance","Counter Names",%REG_BINARY%,43,00,61,00,6c,00,6c,00,73,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,4f,00,75,00,74,00,73,00,74,00,61,00,6e,00,64,00,69,00,6e,00,67,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,46,00,61,00,69,00,6c,00,65,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,46,00,61,00,69,00,6c,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,46,00,61,00,75,00,6c,00,74,00,65,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,46,00,61,00,75,00,6c,00,74,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,44,00,75,00,72,00,61,00,74,00,69,00,6f,00,6e,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,44,00,75,00,72,00,61,00,74,00,69,00,6f,00,6e,00,20,00,42,00,61,00,73,00,65,00,00,00,54,00,72,00,61,00,6e,00,73,00,61,00,63,00,74,00,69,00,6f,00,6e,00,73,00,20,00,46,00,6c,00,6f,00,77,00,65,00,64,00,00,00,54,00,72,00,61,00,6e,00,73,00,61,00,63,00,74,00,69,00,6f,00,6e,00,73,00,20,00,46,00,6c,00,6f,00,77,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,53,00,65,00,63,00,75,00,72,00,69,00,74,00,79,00,20,00,56,00,61,00,6c,00,69,00,64,00,61,00,74,00,69,00,6f,00,6e,00,20,00,61,00,6e,00,64,00,20,00,41,00,75,00,74,00,68,00,65,00,6e,00,74,00,69,00,63,00,61,00,74,00,69,00,6f,00,6e,00,20,00,46,00,61,00,69,00,6c,00,75,00,72,00,65,00,73,00,00,00,53,00,65,00,63,00,75,00,72,00,69,00,74,00,79,00,20,00,56,00,61,00,6c,00,69,00,64,00,61,00,74,00,69,00,6f,00,6e,00,20,00,61,00,6e,00,64,00,20,00,41,00,75,00,74,00,68,00,65,00,6e,00,74,00,69,00,63,00,61,00,74,00,69,00,6f,00,6e,00,20,00,46,00,61,00,69,00,6c,00,75,00,72,00,65,00,73,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,53,00,65,00,63,00,75,00,72,00,69,00,74,00,79,00,20,00,43,00,61,00,6c,00,6c,00,73,00,20,00,4e,00,6f,00,74,00,20,00,41,00,75,00,74,00,68,00,6f,00,72,00,69,00,7a,00,65,00,64,00,00,00,53,00,65,00,63,00,75,00,72,00,69,00,74,00,79,00,20,00,43,00,61,00,6c,00,6c,00,73,00,20,00,4e,00,6f,00,74,00,20,00,41,00,75,00,74,00,68,00,6f,00,72,00,69,00,7a,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,52,00,65,00,6c,00,69,00,61,00,62,00,6c,00,65,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,69,00,6e,00,67,00,20,00,53,00,65,00,73,00,73,00,69,00,6f,00,6e,00,73,00,20,00,46,00,61,00,75,00,6c,00,74,00,65,00,64,00,00,00,52,00,65,00,6c,00,69,00,61,00,62,00,6c,00,65,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,69,00,6e,00,67,00,20,00,53,00,65,00,73,00,73,00,69,00,6f,00,6e,00,73,00,20,00,46,00,61,00,75,00,6c,00,74,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,52,00,65,00,6c,00,69,00,61,00,62,00,6c,00,65,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,69,00,6e,00,67,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,65,00,73,00,20,00,44,00,72,00,6f,00,70,00,70,00,65,00,64,00,00,00,52,00,65,00,6c,00,69,00,61,00,62,00,6c,00,65,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,69,00,6e,00,67,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,65,00,73,00,20,00,44,00,72,00,6f,00,70,00,70,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,00,00

Try doing this:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET LINE=HKLM,"SYSTEM\CurrentControlSet\Services\ServiceModelEndpoint 3.0.0.0\Performance","Counter Names",%%REG_BINARY%%,43,00,61,00,6c,00,6c,00,73,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,4f,00,75,00,74,00,73,00,74,00,61,00,6e,00,64,00,69,00,6e,00,67,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,46,00,61,00,69,00,6c,00,65,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,46,00,61,00,69,00,6c,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,46,00,61,00,75,00,6c,00,74,00,65,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,46,00,61,00,75,00,6c,00,74,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,44,00,75,00,72,00,61,00,74,00,69,00,6f,00,6e,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,44,00,75,00,72,00,61,00,74,00,69,00,6f,00,6e,00,20,00,42,00,61,00,73,00,65,00,00,00,54,00,72,00,61,00,6e,00,73,00,61,00,63,00,74,00,69,00,6f,00,6e,00,73,00,20,00,46,00,6c,00,6f,00,77,00,65,00,64,00,00,00,54,00,72,00,61,00,6e,00,73,00,61,00,63,00,74,00,69,00,6f,00,6e,00,73,00,20,00,46,00,6c,00,6f,00,77,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,53,00,65,00,63,00,75,00,72,00,69,00,74,00,79,00,20,00,56,00,61,00,6c,00,69,00,64,00,61,00,74,00,69,00,6f,00,6e,00,20,00,61,00,6e,00,64,00,20,00,41,00,75,00,74,00,68,00,65,00,6e,00,74,00,69,00,63,00,61,00,74,00,69,00,6f,00,6e,00,20,00,46,00,61,00,69,00,6c,00,75,00,72,00,65,00,73,00,00,00,53,00,65,00,63,00,75,00,72,00,69,00,74,00,79,00,20,00,56,00,61,00,6c,00,69,00,64,00,61,00,74,00,69,00,6f,00,6e,00,20,00,61,00,6e,00,64,00,20,00,41,00,75,00,74,00,68,00,65,00,6e,00,74,00,69,00,63,00,61,00,74,00,69,00,6f,00,6e,00,20,00,46,00,61,00,69,00,6c,00,75,00,72,00,65,00,73,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,53,00,65,00,63,00,75,00,72,00,69,00,74,00,79,00,20,00,43,00,61,00,6c,00,6c,00,73,00,20,00,4e,00,6f,00,74,00,20,00,41,00,75,00,74,00,68,00,6f,00,72,00,69,00,7a,00,65,00,64,00,00,00,53,00,65,00,63,00,75,00,72,00,69,00,74,00,79,00,20,00,43,00,61,00,6c,00,6c,00,73,00,20,00,4e,00,6f,00,74,00,20,00,41,00,75,00,74,00,68,00,6f,00,72,00,69,00,7a,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,52,00,65,00,6c,00,69,00,61,00,62,00,6c,00,65,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,69,00,6e,00,67,00,20,00,53,00,65,00,73,00,73,00,69,00,6f,00,6e,00,73,00,20,00,46,00,61,00,75,00,6c,00,74,00,65,00,64,00,00,00,52,00,65,00,6c,00,69,00,61,00,62,00,6c,00,65,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,69,00,6e,00,67,00,20,00,53,00,65,00,73,00,73,00,69,00,6f,00,6e,00,73,00,20,00,46,00,61,00,75,00,6c,00,74,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,52,00,65,00,6c,00,69,00,61,00,62,00,6c,00,65,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,69,00,6e,00,67,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,65,00,73,00,20,00,44,00,72,00,6f,00,70,00,70,00,65,00,64,00,00,00,52,00,65,00,6c,00,69,00,61,00,62,00,6c,00,65,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,69,00,6e,00,67,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,65,00,73,00,20,00,44,00,72,00,6f,00,70,00,70,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,00,00
SET LINE=!LINE:%%REG_BINARY%%=0x00000001!
ECHO %LINE%

The above script won't work in Win2k with its original CMD.EXE.

0

Share this post


Link to post
Share on other sites

hmmm ... pathnames ... jaclaz has found a new kind of stegenography (or dirigonography something like that)?

echelon will spend all its battery juice trying to translate a hello world file, meanwhile the secret key is in the pathname

speaking of paths ... there is a larger project(?) happening here which is REALLY nice ... it's inchoate and still undefined at the moment ... a rising event still in the brewing phase

tomasz86+BWC,WB,+,+ are moving the powers and driver availability of XP (by adeeming the bubblegum) up into the higher domains of dignity and maturity (and sweetness like wine) of 2000.

there is also a parallel effort to strip away the infantile insults and commerical bubblegum from XP, thus renewing driver availabilities and raising powers to the higher dignity of 2000.

not sure one path will be easier or better than another ... they both merge into a MOST worthwhile result ...

0

Share this post


Link to post
Share on other sites

Try doing this:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET LINE=HKLM,"SYSTEM\CurrentControlSet\Services\ServiceModelEndpoint 3.0.0.0\Performance","Counter Names",%%REG_BINARY%%,43,00,61,00,6c,00,6c,00,73,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,4f,00,75,00,74,00,73,00,74,00,61,00,6e,00,64,00,69,00,6e,00,67,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,46,00,61,00,69,00,6c,00,65,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,46,00,61,00,69,00,6c,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,46,00,61,00,75,00,6c,00,74,00,65,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,46,00,61,00,75,00,6c,00,74,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,44,00,75,00,72,00,61,00,74,00,69,00,6f,00,6e,00,00,00,43,00,61,00,6c,00,6c,00,73,00,20,00,44,00,75,00,72,00,61,00,74,00,69,00,6f,00,6e,00,20,00,42,00,61,00,73,00,65,00,00,00,54,00,72,00,61,00,6e,00,73,00,61,00,63,00,74,00,69,00,6f,00,6e,00,73,00,20,00,46,00,6c,00,6f,00,77,00,65,00,64,00,00,00,54,00,72,00,61,00,6e,00,73,00,61,00,63,00,74,00,69,00,6f,00,6e,00,73,00,20,00,46,00,6c,00,6f,00,77,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,53,00,65,00,63,00,75,00,72,00,69,00,74,00,79,00,20,00,56,00,61,00,6c,00,69,00,64,00,61,00,74,00,69,00,6f,00,6e,00,20,00,61,00,6e,00,64,00,20,00,41,00,75,00,74,00,68,00,65,00,6e,00,74,00,69,00,63,00,61,00,74,00,69,00,6f,00,6e,00,20,00,46,00,61,00,69,00,6c,00,75,00,72,00,65,00,73,00,00,00,53,00,65,00,63,00,75,00,72,00,69,00,74,00,79,00,20,00,56,00,61,00,6c,00,69,00,64,00,61,00,74,00,69,00,6f,00,6e,00,20,00,61,00,6e,00,64,00,20,00,41,00,75,00,74,00,68,00,65,00,6e,00,74,00,69,00,63,00,61,00,74,00,69,00,6f,00,6e,00,20,00,46,00,61,00,69,00,6c,00,75,00,72,00,65,00,73,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,53,00,65,00,63,00,75,00,72,00,69,00,74,00,79,00,20,00,43,00,61,00,6c,00,6c,00,73,00,20,00,4e,00,6f,00,74,00,20,00,41,00,75,00,74,00,68,00,6f,00,72,00,69,00,7a,00,65,00,64,00,00,00,53,00,65,00,63,00,75,00,72,00,69,00,74,00,79,00,20,00,43,00,61,00,6c,00,6c,00,73,00,20,00,4e,00,6f,00,74,00,20,00,41,00,75,00,74,00,68,00,6f,00,72,00,69,00,7a,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,52,00,65,00,6c,00,69,00,61,00,62,00,6c,00,65,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,69,00,6e,00,67,00,20,00,53,00,65,00,73,00,73,00,69,00,6f,00,6e,00,73,00,20,00,46,00,61,00,75,00,6c,00,74,00,65,00,64,00,00,00,52,00,65,00,6c,00,69,00,61,00,62,00,6c,00,65,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,69,00,6e,00,67,00,20,00,53,00,65,00,73,00,73,00,69,00,6f,00,6e,00,73,00,20,00,46,00,61,00,75,00,6c,00,74,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,52,00,65,00,6c,00,69,00,61,00,62,00,6c,00,65,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,69,00,6e,00,67,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,65,00,73,00,20,00,44,00,72,00,6f,00,70,00,70,00,65,00,64,00,00,00,52,00,65,00,6c,00,69,00,61,00,62,00,6c,00,65,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,69,00,6e,00,67,00,20,00,4d,00,65,00,73,00,73,00,61,00,67,00,65,00,73,00,20,00,44,00,72,00,6f,00,70,00,70,00,65,00,64,00,20,00,50,00,65,00,72,00,20,00,53,00,65,00,63,00,6f,00,6e,00,64,00,00,00,00,00
SET LINE=!LINE:%%REG_BINARY%%=0x00000001!
ECHO %LINE%

The above script won't work in Win2k with its original CMD.EXE.

Oww, come off it!

I do believe that you managed to find a way to break that limit :thumbup

What I wonder is :unsure: :

  1. HOW OFTEN this happens
  2. WHY the good MS guys didn't (as they often do for much serious matters) say "it's by design" :w00t:

Back to your finding:

What is the actual GOAL of that snippet (obviously it is not that of ECHOing a long string of comma delimited numbers to the screen)?

Are you really sure that you need a XP CMD.EXE (and thus - to be "kosher" - an additional license besides the 2K one) to reach that goal?

(or there are workarounds or different methods to achieve it still using the 2K CMD.EXE)?

jaclaz

0

Share this post


Link to post
Share on other sites

The goal is pretty simple. This is just a part of a larger script. Basically speaking there's a file with strings, ex.

[strings].inf

[Strings]
FXAssemblyVersion="4.0.0.0"
VSAssemblyVersion="10.0.0.0"
URTBuildNum="30319"
WPFRegistryKey="Windows Presentation Foundation"
WPFStaticVersion="4.0"
REG_EXPAND_SZ=0x00020000
REG_DWORD=0x00010001
REG_QWORD=0x000B0001
REG_BINARY=0x00000001
REG_MULTI_SZ=0x00010000
REG_NONE=0x00020001
REG_KEYONLY=0x00000010

and there are several other files where these strings are used. I want to replace all of them with their real values.

FOR /F "skip=1 tokens=* delims=" %%B IN ([Strings].inf) DO (
FOR /F tokens^=1-2^ delims^=^=^" %%C IN ("%%B") DO (
FOR /F "tokens=* delims=" %%E IN ('DIR/B/S *.inf ^| FINDSTR/IV "Strings"') DO (
FINDSTR/IL "%%%%C%%" "%%E" >NUL
IF !ERRORLEVEL! EQU 0 (
FINDSTR/VIL "%%%%C%%" "%%E">"%%E.tmp"
FOR /F "tokens=* delims=" %%F IN ('FINDSTR/IL "%%%%C%%" "%%E"') DO (
SET STR=%%F
SET STR=!STR:%%%%C%%=%%D!
ECHO>>"%%E.tmp" !STR!
)
MOVE "%%E.tmp" "%%E"
)
)
)
)

Such long lines are not very common but they do appear sometimes.

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

And gsar doesn't work for it, right? :unsure:

jaclaz

0

Share this post


Link to post
Share on other sites

And gsar doesn't work for it, right? :unsure:

I don't know but probably will work. I think I just enjoy playing around with these CMD scripts :w00t:

In this particular case probably gsar will be indeed better as yesterday when I was running the script CMD.EXE ate up almost ~2GB of RAM :ph34r:

0

Share this post


Link to post
Share on other sites

Yep :thumbup , the point being that if you want to "replace a string of text in a file", a tool designed to "replace a string of text in a file" ;) often is more suited than using a "generic" (scriptable) command processor (as when using it, it may hit some limit :whistle: or anyway take more time/resources than a, specific, dedicated, tool).

As you might well know, I do believe that the simplest solution (for simple problems) is a bunch of lines in a batch (and I do have my part of fun playing eith them batches), but when you are trying to do something that is not simple and you have a command line, specifically designed for the specific chore, external tool, then it's usually better to use it :yes: .

jaclaz

0

Share this post


Link to post
Share on other sites

And gsar doesn't work for it, right? :unsure:

I don't know but probably will work. I think I just enjoy playing around with these CMD scripts :w00t:

In this particular case probably gsar will be indeed better as yesterday when I was running the script CMD.EXE ate up almost ~2GB of RAM :ph34r:

2 GB huh, lol, that must have been a bad memory pointer. VBS might be better for large string manipulation. MS officially states that REG.EXE cannot write binary values to the registry, but it can be done very reliably, example:

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "_offline_\MountedDevices"

r1 = oReg.GetBinaryValue(HKEY_LOCAL_MACHINE,strKeyPath,"\DosDevices\Y:",strValue)

r3 = oReg.SetBinaryValue(HKEY_LOCAL_MACHINE,strKeyPath,"\DosDevices\Y:",strValue)

For i = lBound(strValue) to uBound(strValue)
StdOut.Write Hex(strValue(i)) & " "
Next


0

Share this post


Link to post
Share on other sites

@Phenomic, Sorry for the noob questions, but I don't quite get your example. After you define both r1 and r3, where/how are they used? Are they just used to set strValue? I guess I don't understand how the GetBinaryValue and SetBinaryValue work. Can you give me a pointer to a good tutorial?

Cheers and Regards

0

Share this post


Link to post
Share on other sites

Set/GetBinaryValue returns its result in r1/r3 but is setting/getting the content of strValue to/from the registry key.

Another example at Ms Scripting Guy.

0

Share this post


Link to post
Share on other sites

Yes, r1/r3 are for error handling, strValue is a pointer to the actual string.

It was just an example, snippet only. To make it work you can first run:

REG.EXE  load "HKLM\_offline_

to load any registry file (e.g. \system32\config\system), then at the end:

REG.EXE unload "HKLM\_offline_"

For testing purposes, I used an off-line hive so I don't screw with my actual registry.

0

Share this post


Link to post
Share on other sites

And gsar doesn't work for it, right? :unsure:

jaclaz

I'm trying to use gsar now and I've encountered this problem:

gsar: command error, length of search or replace buffer must not exceed 256 chars

This happens when trying to replace strings like this one:

%BITS_DESCRIPTION%

with

BITS_DESCRIPTION="Transfers files in the background using idle network bandwidth. If the service is stopped, features such as Windows Update, and MSN Explorer will be unable to automatically download programs and other information. If this service is disabled, any services that explicitly depend on it may fail to transfer files if they do not have a fail safe mechanism to transfer files directly through IE in case BITS has been disabled."

gsar.exe -i -o -s"%BITS_DESCRIPTION%" -r"Transfers files in the background using idle network bandwidth. If the service is stopped, features such as Windows Update, and MSN Explorer will be unable to automatically download programs and other information. If this service is disabled, any services that explicitly depend on it may fail to transfer files if they do not have a fail safe mechanism to transfer files directly through IE in case BITS has been disabled." 1.inf

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

Well, then do it in a few instances, something *like*:

gsar.exe -i -o -s"%BITS_DESCRIPTION%" -r"Transfers files in the background using idle network bandwidth.§My_append§"
gsar.exe -i -o -s"§My_append§" -r" If the service is stopped, features such as Windows Update, and MSN Explorer will be unable to automatically download programs and other information.§My_append§"
gsar.exe -i -o -s"§My_append§" -r"If this service is disabled, any services that explicitly depend on it may fail to transfer files if they do not have a fail safe mechanism to transfer files directly through IE in case BITS has been disabled." 1.inf

might do.

jaclaz

0

Share this post


Link to post
Share on other sites

Hmm, OK but then the line will have to be divided automatically. At the moment the script looks like this:

[strings].inf


[Strings]
BITS_DESCRIPTION="Transfers files in the background using idle network bandwidth. If the service is stopped, features such as Windows Update, and MSN Explorer will be unable to automatically download programs and other information. If this service is disabled, any services that explicitly depend on it may fail to transfer files if they do not have a fail safe mechanism to transfer files directly through IE in case BITS has been disabled."

FOR /F "skip=1 delims=" %%A IN ([Strings].inf) DO (
FOR /F tokens^=1-2^ delims^=^=^" %%B IN ("%%A") DO (
FOR /F "delims=" %%D IN ('FINDSTR/ILM "%%%%B%%" INF\*.inf') DO (
gsar.exe -i -o -s"%%%%B%%" -r"%%C" "%%D" >NUL
)
)
)

0

Share this post


Link to post
Share on other sites

Japanese version CMD.exe has a difference between XP and 2000.

XP

echo %DATE%

2013/03/07

date /T

2013/03/07

2000

echo %DATE%

木 2013/03/07

date /t

2013/03/07 木

('木' means Thursday)

Are there any differences other ?

Edited by blackwingcat
0

Share this post


Link to post
Share on other sites

Are there any differences other ?

Unfortunately the XP's cmd.exe when run in Windows 2000 seems to have extreme memory leaks :(

0

Share this post


Link to post
Share on other sites

Japanese version CMD.exe has a difference between XP and 2000.

JFYI, the way the DATE /T and TIME/T behave in different versions of Windows (and in different "regional" versions) is a known "nightmare" :ph34r: , same happens - as an example - for "Canadian English":

http://www.robvanderwoude.com/datetiment.php

jaclaz

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

Japanese version CMD.exe has a difference between XP and 2000.

JFYI, the way the DATE /T and TIME/T behave in different versions of Windows (and in different "regional" versions) is a known "nightmare" :ph34r: , same happens - as an example - for "Canadian English":

http://www.robvanderwoude.com/datetiment.php

jaclaz

And %date% and %time% are localized even in XP.

0

Share this post


Link to post
Share on other sites

That's why I use date.exe from UnxUtils.

0

Share this post


Link to post
Share on other sites

I do the same most of the time.

0

Share this post


Link to post
Share on other sites

Well, for the record, there is a "way out" without third party tools, using WMI time classes (on XP, NOT on 2K, which misses a few classes).

http://technet.microsoft.com/en-us/library/ee198928.aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394590(v=vs.85).aspx

What is available should be:

Windows 2000

Win32_TimeZone

Win32_SystemTimeZone

Windows XP

Win32_TimeZone

Win32_SystemTimeZone

Win32_UTCTime

Win32_CurrentTime

Win32_LocalTime

For 2K (but also for XP if one wants to have the date/time format in the "full" UTC format), writing a file and immediately get it's created or last accessed time/date may be a good enough workaround :unsure:.

jaclaz

0

Share this post


Link to post
Share on other sites

AFAIK, here is a way to get the current date and time using batch/CMD script that will return a consistently formatted string in any version of Windows from WinXP through Win8 and 2012, (I believe it should also work in Win2K but I would appreciate someone validating that), where the OS is either 32-bit or 64-bit, in any language, in any locale, even if the date/time separators have been modified by the user.

Date:


:: #############################################################################
:: :f_GetDate _TodayDate _Year _Month _DayOfMonth
::
:: Load the ISO format date for today and local date components into variables.
::
:: Usage: CALL :f_GetDate _TodayVariable _YearVariable _MonthVariable _DayOfMonthVariable
::
:: This function should get the correct local system date components copied
:: into the arguments, passed by reference, regardless of where in the world
:: this is run, independent of "International" settings. The arguments are:
::
:: %1 - Variable to receive the date in ISO format (by ref)
:: %2 - Variable to receive year, 4 digits (by ref)
:: %3 - Variable to receive month, 2 digits, 01 to 12 (by ref)
:: %4 - Variable to receive day of month, 2 digits, 01 to 31 (by ref)
::
:: The date in ISO format is equivalent to: %_Year%-%_Month%-%_DayOfMonth%
::
:: Dependencies: START, REGEDIT [Utilizes a temp file %TEMP%.\_Temp.reg]
::
:: Originally writen by Rob van der Woude - http://www.robvanderwoude.com as
:: SortDate, Version 3.10 for Windows NT4/2000/XP. Adapted for Windows XP with
:: help from Kailash Chanduka. Modified slightly by bphlpt.
::
:: Upon exit, ERRORLEVEL is set to 0.
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
::
:f_GetDate _TodayDate _Year _Month _DayOfMonth
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
:: Export registry settings to temp file, read exported data
START "GET iDATE and sDATE" /WAIT REGEDIT /E "%TEMP%.\_Temp.reg" "HKEY_CURRENT_USER\Control Panel\International"
FOR /F "tokens=1* delims==" %%G IN ('TYPE "%TEMP%.\_Temp.reg" ^| FIND /I "iDate"') DO (SET _iDate=%%H)
FOR /F "tokens=1* delims==" %%G IN ('TYPE "%TEMP%.\_Temp.reg" ^| FIND /I "sDate"') DO (SET _sDate=%%H)
:: Delete quotes and delete temp file
(SET _iDate=%_iDate:"=%)
(SET _sDate=%_sDate:"=%)
del "%TEMP%.\_Temp.reg" >nul 2>&1
:: Parse today's date depending on registry's date format settings
IF %_iDate%==0 (FOR /F "tokens=1-4* delims=%_sDate%" %%G IN ('DATE/T') DO (SET "_Year=%%I"&SET "_Month=%%G"&SET "_Day=%%H")) ELSE (
IF %_iDate%==1 (FOR /F "tokens=1-4* delims=%_sDate%" %%G IN ('DATE/T') DO (SET "_Year=%%I"&SET "_Month=%%H"&SET "_Day=%%G")) ELSE (
IF %_iDate%==2 (FOR /F "tokens=1-4* delims=%_sDate%" %%G IN ('DATE/T') DO (SET "_Year=%%G"&SET "_Month=%%H"&SET "_Day=%%I"))))
:: Remove the day of week if applicable
(FOR %%G IN (%_Year%) DO (SET "_Year=%%G"))&(FOR %%G IN (%_Month%) DO (SET "_Month=%%G"))&(FOR %%G IN (%_Day%) DO (SET "_Day=%%G"))
:: Return date and components
ENDLOCAL&(SET "%2=%_Year%"&SET "%3=%_Month%"&SET "%4=%_Day%"&SET "%1=!%2!-!%3!-!%4!")&EXIT /B 0
::
:: #############################################################################

Time:


:: #############################################################################
:: :f_GetTime _Time
::
:: Load time in a variable, zero padded using ONLY "standard" delimiters (:.)
::
:: Usage: CALL :f_GetTime _Time
::
:: %_Time% will be set to HH:MM:SS.MSC - NOTE: that MS is now THREE digits
::
:: Although the default time delimiter, in Windows XP and above is either . or :
:: users can change the delimiter to just about any character they like. And you
:: know theres always that one guy, the one who writes everything in green ink,
:: who will do this! This script always returns HH:MM:SS.MSC, note that MS
:: is now 3 digits, no matter which time delimiter has been set in the control
:: panel. Based on a discussion at ss64.com, with input from avery_larry and
:: bluesxman, and tweaks by bphlpt using examples by Frank Westlake.
::
:: Dependencies: None
::
:: Upon exit, ERRORLEVEL is set to 0.
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
::
:f_GetTime _Time
SETLOCAL ENABLEEXTENSIONS
FOR /F "tokens=1-3 delims=1234567890 " %%G IN ("%TIME%") DO (SET "_Delims=%%G%%H%%I")
FOR /F "tokens=1-4 delims=%_Delims% " %%G IN ("%TIME%") DO (SET "_hh=00%%G"&SET "_min=00%%H"&SET "_ss=00%%I"&SET "_ms=00%%J0")
ENDLOCAL&(SET %1=%_hh:~-2%:%_min:~-2%:%_ss:~-2%.%_ms:~-3%)&EXIT /B 0
::
:: #############################################################################

Cheers and Regards

0

Share this post


Link to post
Share on other sites

AFAIK, here is a way to get the current date and time using batch/CMD script that will return a consistently formatted string in any version of Windows from WinXP through Win8 and 2012, (I believe it should also work in Win2K but I would appreciate someone validating that), where the OS is either 32-bit or 64-bit, in any language, in any locale, even if the date/time separators have been modified by the user.

They must be VERY different from the ones in the link I gave in post #19 :whistle:

Seriously :), what are the changes (improvements) when compared against the "official" SORTDATE/SORTTIME? (which are already "certified" to be working also on NT 4 and 2K)

Nesting the IF's with IF/ELSE? :blink:

jaclaz

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.