Jump to content

How to get around the 2047 characters CMD string limitation


tomasz86

Recommended Posts

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

Link to comment
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
Link to comment
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
Link to comment
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.

Link to comment
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

Link to comment
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

Link to comment
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
Link to comment
Share on other sites

I came up with both of those about 2 and a half years ago. For Date, you are correct that the core of the code is essentially a reformatting of Rob's SortDate Version 3.10, which is why he is given specific credit, with the only change really being in the added output of the individual components in addition to the combined date string. (I never really saw the advantage of Rob's Version 4 of SortDate.) Time did not come from any version of Rob's SortTime code at all. (The core code for it came from ss64.com as credited, including the comment about the guy with green ink. LOL) I guess really the shortest solution to get both date and time is Rob's SortDate Version 5.

Cheers and Regards

Edited by bphlpt
Link to comment
Share on other sites

I guess really the shortest solution to get both date and time is Rob's SortDate Version 5.

Yep :), but that, as already posted, only applies to XP and later.

The shortest version (in XP) is using the WMIC approach, the shortest for 2K (as I see it) is something *like*:

@ECHO OFF
SETLOCAL
cd.>datefile.$
FOR /F "tokens=1,2 delims= " %%A IN ('dir datefile.$ ^| FIND "datefile.$"') DO SET my_date=%%A & SET my_time=%%B
del datefile.$
set my_

but it misses seconds (and of course it is only useful to get rid of the "day of the week feature").

What could also work on 2K (haven't a test bed handy, so needs to be checked/tested) may be variable expansion:

 @ECHO OFF
SETLOCAL ENABLEEXTENSIONS
cd.>datefile.$
Call :do_date datefile.$
GOTO :EOF
:do_date
FOR /F "tokens=1,2 delims= " %%A IN ("%~t1") DO SET my_date=%%A & SET my_time=%%B
del datefile.$
set my_

jaclaz

Link to comment
Share on other sites

The great advantage of unix tools date is that you get easily and without hassle the date / time in almost whatever format you might imagine.

Yep, but the point (mine) was to not use external programs.

There is also a debug script, that should work on 2K as well:

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

Now, Today and Todaynow

jaclaz

Link to comment
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.
×
×
  • Create New...