How does notepad.exe obtain the current system date format

1

I was trying to find out how Notepad.exe is able to get the current system date format saved in the Windows registry without appearing to access the registry.

I added a filter on the HKCU\Control Panel\International key in the registry using the Process Monitor tool to detect if Notepad.exe is accessing the registry or not

I tried out the steps listed below

  1. Opened Notepad

  2. Started Process Monitor

  3. Opened The Registry editor and changed the value of the sShortDate subkey
    in the registry(HKCU\Control Panel\International)

  4. As expected Process Monitor shows that the HKCU\Control
    Panel\International registry key has been accessed by the Registry editor
  5. Make the Notepad window active and press F5 to insert the current
    date and time
  6. A date in the new date format is inserted in Notepad

I was expecting Notepad to access the HKCU\Control Panel\International key for the latest date format. But it does not seem to access that

I would like to know how Notepad gets the date format without accessing the registry

I would like to use this information in another project where accessing the registry is taking a lot of time

mjk6035

Posted 2019-02-19T07:53:14.447

Reputation: 11

I would address the problem of "accessing the registry is taking a lot of time". Sounds like something is seriously wrong, or you've completely misdiagnosed the actual problem. – Bill_Stewart – 2019-02-21T01:15:07.457

Answers

1

Notepad uses Short Date and Short Time set in Control Panel → Region enter image description here

For another project of yours, you should use built-in methods of whatever language you are using to get date and time rather than reading it from registry.

Example : You can use Get-Date cmdlet in PowerShell. This is far better than reading date and time from registry.

It allows you to get system date and time in an Object format.

Simple operations like comparison of two dates or getting specific information like day, month etc becomes very easy.

enter image description here

Update post chatting with OP

VBScript also provides various methods for accessing system date and time. You can use built-in Date and Time functions or you can call WMI.

Example use of Date and Time function in VBScript below enter image description here

Some resources:

pun

Posted 2019-02-19T07:53:14.447

Reputation: 5 311

Thanks for the response.

Currently I am directly accessing the registry key HKCU\Control Panel\International in a VBScript (.vbs extension) file. When the operating system is newly installed there is no problem. But after a few months the registry becomes bloated and the access starts to take a long time.

That is why I am trying to find out how Notepad accesses the date format without appearing to access the registry – mjk6035 – 2019-02-19T08:20:55.617

@mjk6035 VBScript has built in Date and Time methods. Why don't you use them ? – pun – 2019-02-19T08:28:40.877

I need the current system date format as I need to perform different actions depending on the system date format that has been set on that computer. – mjk6035 – 2019-02-19T08:32:13.300

@mjk6035 Whatever it is, you don't have to rely on registry value to get date and time. You can use Date and Time function in VBscript. See updated answer – pun – 2019-02-19T08:53:52.623

Thanks for the response

I am trying to find out if there is a way to get the system date format like dd/mm/yy or mm/dd/yy etc without accessing the registry. I do not want to get the current date or time which I know are available using inbuit VBScript functions – mjk6035 – 2019-02-19T09:19:51.013

Date and Time will return the date and time, you can convert it to whatever format you want. – pun – 2019-02-19T09:24:50.377

Thanks for the response. Just to clarify I dont want the date or time like 01/01/2019. I want the value that is stored in the HKCU\Control Panel\International registry key under the subkey sShortDate

I just want to know if it is possible to access this value from some location other than the registry – mjk6035 – 2019-02-19T09:28:30.877

Windows has a number of system functions that can either obtain the configured date format or format the date using this information. I am sure Notepad is using one of them. VBScript has corresponding functions and they should be used. Microsoft has always recommended using these system functions whenever possible and avoid accessing the registry directly. – LMiller7 – 2019-02-19T17:51:59.587

I am unable to find what system function Notepad is using to get the current system date format event after using a Windows APi call monitor. Monitoring the key HKCU\Control Panel\International using the 'Process Monitor' tool also indicates that Notepad is not accessing that key to get the system date format. – mjk6035 – 2019-02-20T03:23:08.413