Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

How to get around the 2047 characters CMD string limitation

- - - - -

  • Please log in to reply
35 replies to this topic

#1
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,525 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
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).

post-47483-1123010975.png



How to remove advertisement from MSFN

#2
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,654 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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

Just in case:
http://dictionary.re...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

#3
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,525 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
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.

post-47483-1123010975.png


#4
Molecule

Molecule

    Member

  • Member
  • PipPip
  • 190 posts
  • Joined 11-November 05
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 ...
can the platonic solids be constructed by gaussian modulation of rotational action, rotational action itself being an artifact of intersection of two sphaeric actions--the tetrahedron for example

#5
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,654 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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: :
  • HOW OFTEN this happens
  • 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

#6
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,525 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
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, 11 October 2012 - 02:28 PM.

post-47483-1123010975.png


#7
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,654 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
And gsar doesn't work for it, right? :unsure:

jaclaz

#8
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,525 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag

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:

post-47483-1123010975.png


#9
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,654 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
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

#10
Phenomic

Phenomic

    Member

  • Member
  • PipPip
  • 279 posts
  • Joined 31-July 09
  • OS:none specified
  • Country: Country Flag


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




#11
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,800 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag
@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

Posted Image


#12
allen2

allen2

    Not really Newbie

  • Member
  • PipPipPipPipPipPipPip
  • 1,814 posts
  • Joined 13-January 06
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.

#13
Phenomic

Phenomic

    Member

  • Member
  • PipPip
  • 279 posts
  • Joined 31-July 09
  • OS:none specified
  • Country: Country Flag
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.

#14
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,525 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag

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, 06 March 2013 - 01:08 PM.

post-47483-1123010975.png


#15
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,654 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
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

#16
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,525 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
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
		)
	)
)

post-47483-1123010975.png


#17
blackwingcat

blackwingcat

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 792 posts
  • Joined 31-May 08
  • OS:Windows 2000 Professional
  • Country: Country Flag
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, 06 March 2013 - 06:07 PM.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
BlackWingCat =^^=
http://blog.livedoor.jp/blackwingcat/
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

#18
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,525 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag

Are there any differences other ?

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

post-47483-1123010975.png


#19
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,654 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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.robvander.../datetiment.php

jaclaz

Edited by jaclaz, 07 March 2013 - 05:55 AM.


#20
allen2

allen2

    Not really Newbie

  • Member
  • PipPipPipPipPipPipPip
  • 1,814 posts
  • Joined 13-January 06


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.robvander.../datetiment.php

jaclaz

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

#21
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,525 posts
  • Joined 27-November 10
  • OS:none specified
  • Country: Country Flag
That's why I use date.exe from UnxUtils.

post-47483-1123010975.png


#22
allen2

allen2

    Not really Newbie

  • Member
  • PipPipPipPipPipPipPip
  • 1,814 posts
  • Joined 13-January 06
I do the same most of the time.

#23
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,654 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
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.micro...y/ee198928.aspx
http://msdn.microsof...0(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

#24
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,800 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag
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:
Spoiler


Time:

Spoiler


Cheers and Regards

Posted Image


#25
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,654 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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:
http://www.msfn.org/...ost__p__1032424

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, 11 March 2013 - 03:27 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users