Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

System Time

66 views
Skip to first unread message

Zaidy036

unread,
Nov 6, 2020, 12:37:26 PM11/6/20
to
In a batch we use %Time% to find the current system time.

I am using NirSoft\runasdate-x64\RunAsDate.exe to run a batch but then
time is "frozen" and I still want to read the system time.

Any suggestions to directly retrieve the system time or have batch
commands to run its own timer function independent of the system time?

Robert Roland

unread,
Nov 6, 2020, 2:55:24 PM11/6/20
to
On Fri, 6 Nov 2020 12:37:24 -0500, Zaidy036 <Zaid...@air.isp.spam>
wrote:

>I am using NirSoft\runasdate-x64\RunAsDate.exe to run a batch but then
>time is "frozen" and I still want to read the system time.

So, you want to see both the real time and the fake time at the same
time?

>Any suggestions to directly retrieve the system time or have batch
>commands to run its own timer function independent of the system time?

There is a hint in the description for RunAsTime.exe:

RunAsDate Limitations:
RunAsDate will not affect applications that take the current date/time
from another source. For example: application that loads the current
date from remote server.

If we simply use our own computer as a remote server, it seems to
work:


echo Apparent time is %date% %time%

for /F "tokens=6,7" %%n in ('NET TIME \\%computername%^|find "Current
time"') do set realdate=%%n&set realtime=%%o

echo Real time is %realdate% %realtime%
--
RoRo

Zaidy036

unread,
Nov 6, 2020, 4:25:27 PM11/6/20
to
I did not know of "Net Time" so I turned the service on and ran the
following test batch using RunAsDate:

NET TIME \\i7 > F:\Timex1.txt
TIMEOUT 10
NET TIME \\i7 > F:\Timex2.txt
TYPE F:\Timex1.txt
TYPE F:\Timex2.txt
PAUSE & EXIT

It Worked....Thank you for pointing me to this command




Kenny McCormack

unread,
Nov 6, 2020, 5:27:12 PM11/6/20
to
In article <jq9bqfpj19pibo125...@4ax.com>,
Robert Roland <fa...@ddress.no> wrote:
...
>If we simply use our own computer as a remote server, it seems to
>work:
>
>echo Apparent time is %date% %time%
>
>for /F "tokens=6,7" %%n in ('NET TIME \\%computername%^|find "Current
>time"') do set realdate=%%n&set realtime=%%o

You can also use: net time \\127.0.0.1

to save the hassle of making sure that "computername" is meaningfully set.

--
"Everything Roy (aka, AU8YOG) touches turns to crap."
--citizens of alt.obituaries--

Zaidy036

unread,
Nov 6, 2020, 5:55:30 PM11/6/20
to
Sorry, but I am weak on FOR /F statements and having trouble with it. I
know it is a one line command but it is not picking up the "real"
values. I have tried various "tokens=" combinations without success.

I only need the realtime value to display the start and end times for
batch operations.



Zaidy036

unread,
Nov 6, 2020, 8:25:08 PM11/6/20
to
I figured it out:
FOR /F "tokens=7 delims= " %%n IN ('NET TIME \\%computername%') DO SET
_TX=%%n

Kerr-Mudd,John

unread,
Nov 7, 2020, 5:32:50 AM11/7/20
to
On Fri, 06 Nov 2020 22:27:10 GMT, gaz...@shell.xmission.com (Kenny
McCormack) wrote:

> In article <jq9bqfpj19pibo125...@4ax.com>,
> Robert Roland <fa...@ddress.no> wrote:
> ...
>>If we simply use our own computer as a remote server, it seems to
>>work:
>>
>>echo Apparent time is %date% %time%
>>
>>for /F "tokens=6,7" %%n in ('NET TIME \\%computername%^|find "Current
>>time"') do set realdate=%%n&set realtime=%%o
>
> You can also use: net time \\127.0.0.1
>
> to save the hassle of making sure that "computername" is meaningfully
> set.
>

Sadly for me (UK, date format yyyy-mm-dd)
gives the date in US format:


C:\>net time \\127.0.0.1
Current time at \\127.0.0.1 is 11/7/2020 10:32 AM

The command completed successfully.


C:\>date
The current date is: 2020-11-07
Enter the new date: (yy-mm-dd)

--
Bah, and indeed, Humbug.

Robert Roland

unread,
Nov 7, 2020, 8:58:49 AM11/7/20
to
On Sat, 7 Nov 2020 10:32:49 -0000 (UTC), "Kerr-Mudd,John"
<nots...@127.0.0.1> wrote:

>Sadly for me (UK, date format yyyy-mm-dd)
>gives the date in US format:
>
>
>C:\>net time \\127.0.0.1
>Current time at \\127.0.0.1 is 11/7/2020 10:32 AM

That is because your local SYSTEM account is configured for US locale.

The NET TIME command is served by the Server service, which is running
under the local SYSTEM account.

>C:\>date
>The current date is: 2020-11-07
>Enter the new date: (yy-mm-dd)

The issue of different locales around the world is a spectacular can
of worms. Making a batch file that works with every possible
combination of language and locale is a LOT more difficult that making
it work on your own computer only.

In addition to the multitude for formats for date and time, the
response text from the NET command is translated to the language of
the Windows GUI. On a Norwegian Windows, it looks like this:

---
C:\test>net time \\localhost
Gjeldende tid på \\localhost er 07.11.2020 14:35:17

Kommandoen er fullført.
---

I can't imagine a way to make this universal.
--
RoRo

Kerr-Mudd,John

unread,
Nov 7, 2020, 10:25:19 AM11/7/20
to
On Sat, 07 Nov 2020 13:58:46 GMT, Robert Roland <fa...@ddress.no> wrote:

> On Sat, 7 Nov 2020 10:32:49 -0000 (UTC), "Kerr-Mudd,John"
> <nots...@127.0.0.1> wrote:
>
>>Sadly for me (UK, date format yyyy-mm-dd)
>>gives the date in US format:
>>
>>
>>C:\>net time \\127.0.0.1
>>Current time at \\127.0.0.1 is 11/7/2020 10:32 AM
>
> That is because your local SYSTEM account is configured for US locale.
>
> The NET TIME command is served by the Server service, which is running
> under the local SYSTEM account.

Thanks; I don't think I've ever logged in as SYSTEM
>
> The issue of different locales around the world is a spectacular can

Agreed

Kenny McCormack

unread,
Nov 7, 2020, 10:30:51 AM11/7/20
to
In article <vs5dqfhsneo54hkfj...@4ax.com>,
Robert Roland <fa...@ddress.no> wrote:
...
>The issue of different locales around the world is a spectacular can
>of worms. Making a batch file that works with every possible
>combination of language and locale is a LOT more difficult that making
>it work on your own computer only.

I have 3 distinct comments to make on this thread.

>In addition to the multitude for formats for date and time, the
>response text from the NET command is translated to the language of
>the Windows GUI. On a Norwegian Windows, it looks like this:
>
>---
>C:\test>net time \\localhost

1) For whatever reason, it didn't work on my system with "localhost" (I
tried that first), but it works with 127.0.0.1.

2) Shouldn't this be: "netto tid \\lokalvert"?

>Gjeldende tid p \\localhost er 07.11.2020 14:35:17
>
>Kommandoen er fullfrt.

3) In a way, I'm surprised that the general solution advanced in this
thread actually works. If you think about it, the most common scenario for
this sort of "time faking" thing is people wanting to beat software
licensing arrangements based on the date.

A company I used to work for routinely did this (changed their system
times, in the era before widespread availability of the Internet) for a
short period of time after the beginning of each calendar year, for a
certain well-known software product, before the bean counters got around to
authorizing the money to renew the licenses. It was more or less done with
the tacit acceptance of the software vendor, since everybody understood
what was going on and why.

The point of all this is that nowadays, faking the local system time
doesn't do any good if the software can just go out on the Internet and get
the real date/time. So, the upshot of this last observation is that in
order to be effective, any "time faking" software should trap calls out to
the Internet (and, in fact, also to any local hosts such as 127.0.0.1 and
anything else on the local LAN) and deal with those as well. Doing this in
full generality is, of course, tricky, and, probably, ultimately,
impossible.

Thus, the fact that this hack (the one being advanced in this thread) does
actually seem to work, implies that the "time faking" software used by OP
doesn't do everything it needs to, to handle its most common use case.

Interesting, that.

--
b w r w g y b r y b

mokomoji

unread,
Nov 7, 2020, 11:53:38 AM11/7/20
to
2020년 11월 7일 토요일 오전 2시 37분 26초 UTC+9에 Zaidy036님이 작성한 내용:
Crazy way
[code]

@echo off
cd /d "%~dp0"
setlocal
rem chcp 437
title=time.windows.com NTP server use date/time
echo [auto country word type]
chcp|find "437" 2>nul>nul&&(
set "z_time.pm=PM"
set "z_time.s_Capital=seoul"
set "z_time.n_Capital=pyongyang"
)
chcp|find "949" 2>nul>nul&&(
set "z_time.pm=오후"
set "z_time.s_Capital=서울"
set "z_time.n_Capital=평양"
)


for /f "delims=" %%f in ('tzutil /l') do (
echo "%%f"|find /i "(UTC+00:00)"
echo "%%f"|find /i "%z_time.s_Capital%"
echo "%%f"|find /i "%z_time.n_Capital%"
)

echo AM/PM TYPE %z_time.pm%
for /f "skip=2 tokens=4,5,6,7,8,9 delims=:- " %%f in (
'w32tm /stripchart /computer:time.windows.com /samples:1'
) do (
call set z_hour=%%j
if /i "%%i" equ "%z_time.pm%" call set /a z_hour=%%j+12
if "%%j" lss "10" call set z_hour=0%%j
echo "%%f-%%g-%%h"|findstr "20[0-9][0-9]-[0-1][0-9]-[0-3]" 2>nul>nul&&call set "z_reardate=%%f-%%g-%%h"
call echo "%%z_hour%%:%%k"|findstr "[0-2][0-9]:[0-5][0-9]" 2>nul>nul&&call set z_reartime=%%z_hour%%:%%k
)
echo republic of s.korea
echo date %z_reardate%
echo time %z_reartime%
pause




[code]

Zaidy036

unread,
Nov 7, 2020, 3:14:35 PM11/7/20
to
>>FOR /F "tokens=7 delims= " %%n IN ('NET TIME \\i7') DO SET _TX=%%n
SET "_LineD=%_Spc12%%_TX%
>>
> I figured it out:
> FOR /F "tokens=7 delims= " %%n IN ('NET TIME \\%computername%') DO SET
> _TX=%%n

Just to report how my batch uses the above with success until Win 10
changes something again!!

Setup.bat for _Overnight.bat ends with the following(GDate=today+1 day):
SET _RunAsDate=D:\_NirSoft\runasdate-x64\RunAsDate.exe %GDate% 00:07:07
%_RunAsDate% "C:\Users\xxxx\Dropbox\Batch_Files\_Overnight.bat"

Multiple places in _Overnight.bat(_RPT is batch log):
FOR /F "tokens=7 delims= " %%n IN ('NET TIME \\i7') DO SET _TX=%%n
SET "_LineD= %_TX%
[do something]
FOR /F "tokens=7 delims= " %%n IN ('NET TIME \\i7') DO SET _TX=%%n
SET "_LineD=%_LineD% - %_TX% [something text]"
ECHO %_LineD% >> %_RPT%

I defined _RunAsDate because I expect that a few operations in
_Overnight.bat will require that to function correctly.

mokomoji

unread,
Nov 7, 2020, 9:19:45 PM11/7/20
to
2020년 11월 7일 토요일 오전 2시 37분 26초 UTC+9에 Zaidy036님이 작성한 내용:
Sorry.. mistake in source.

[code]


@echo off
cd /d "%~dp0"
setlocal
rem chcp 437
title=time.windows.com NTP server use date/time
echo [auto country word type]
chcp|find "437" 2>nul>nul&&(
set "z_time.pm=PM"
set "z_time.s_Capital=seoul"
set "z_time.n_Capital=pyongyang"
set "z_time.ment_head=Time is now"
set "z_time.ment_poot=a clack"
)
chcp|find "949" 2>nul>nul&&(
set "z_time.pm=오후"
set "z_time.s_Capital=서울"
set "z_time.n_Capital=평양"
set "z_time.ment_head=지금 시각은?"
set "z_time.ment_poot=입니다."
)
echo
for /f "delims=" %%f in ('tzutil /l') do (
echo "%%f"|findstr /i "(UTC\+[0][0]:[0][0])"
echo "%%f"|find /i "%z_time.s_Capital%"
echo "%%f"|find /i /v "태평양"|find /i "%z_time.n_Capital%"
)
echo AM/PM TYPE %z_time.pm%
for /f "skip=2 tokens=4,5,6,7,8,9 delims=:- " %%f in (
'w32tm /stripchart /computer:time.windows.com /samples:1'
) do (
call set z_hour=%%j
if /i "%%i" equ "%z_time.pm%" call set /a z_hour=%%j+12
if "%%j" lss "10" call set z_hour=0%%j
echo "%%f-%%g-%%h"|findstr "20[0-9][0-9]-[0-1][0-9]-[0-3]" 2>nul>nul&&call set "z_reardate=%%f-%%g-%%h"
call echo "%%z_hour%%:%%k"|findstr "[0-2][0-9]:[0-5][0-9]" 2>nul>nul&&call set "z_reartime=%%z_hour%%:%%k"

)
echo
echo republic of s.korea
echo date %z_reardate%
echo time %z_reartime%
echo CreateObject^("SAPI.spvoice"^).Speak"%z_time.ment_head% %z_time.pm% %z_reartime% %z_time.ment_poot%">speack.vbs
call speack.vbs&&del speack.vbs
echo
:end
endlocal
pause

[code]

voice&sound add on..~!!

Robert Roland

unread,
Nov 8, 2020, 1:05:20 PM11/8/20
to
On Sat, 7 Nov 2020 15:30:49 -0000 (UTC), gaz...@shell.xmission.com
(Kenny McCormack) wrote:

>>C:\test>net time \\localhost
>2) Shouldn't this be: "netto tid \\lokalvert"?

Fortunately for me, they did not translate the commands, only the
responses.

In Excel, however, they also translated the formula keywords. But if
you write a macro in VBS, it's all English regardless of display
language. Absolute chaos.
--
RoRo

Kenny McCormack

unread,
Nov 8, 2020, 3:15:34 PM11/8/20
to
In article <mfcgqflhpan45p6ir...@4ax.com>,
Heh heh. Funny stuff.

Well done.

--
"Every time Mitt opens his mouth, a swing state gets its wings."

(Should be on a bumper sticker)
0 new messages