PDA

View Full Version : Difficulty in reading Network List and login time & logout time from the registry



dinesh123
15th June 2015, 10:29
I am doing small application using QT4 which can display the list of the network accessed by the user, for that i have to read Network List key and its values from the registry but i am unable to read its value.I have read other keys using Qsettings , but could not do so for NetworkList available in HKLM and the users logged on onto the system.
Also I am facing difficulty in reading the last login time and shutdown time of the user.

Please respond to this.
Thanks

d_stranz
15th June 2015, 22:27
I have read other keys using Qsettings , but could not do so for NetworkList available in HKLM

What have you done, and what is the debugger telling you when you ask for one of these keys? Does you account have the admin authority to read these keys?

Edit: from QSettings docs:


On Windows, NativeFormat settings are stored in the following registry paths:

HKEY_CURRENT_USER\Software\MySoft\Star Runner
HKEY_CURRENT_USER\Software\MySoft\OrganizationDefa ults
HKEY_LOCAL_MACHINE\Software\MySoft\Star Runner
HKEY_LOCAL_MACHINE\Software\MySoft\OrganizationDef aults

This implies that you cannot access an arbitrary location in the Registry using QSettings, but only one of these four locations ("MySoft" and "StarRunner" are just example names), depending on the user's access rights and whether SystemScope or UserScope is requested.

Further edit:


Accessing the Windows Registry Directly

On Windows, QSettings lets you access settings that have been written with QSettings (or settings in a supported format, e.g., string data) in the system registry. This is done by constructing a QSettings object with a path in the registry and QSettings::NativeFormat.

For example:

QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Office",
QSettings::NativeFormat);


But this implies that you can access arbitrary keys. So I go back to my original question - what is the debugger telling you?

dinesh123
19th June 2015, 12:13
Thanks d_stranz for replying .
Debugger does not give any message, no errors but i do not get any result in the list box or in the line edits. But at the same time for other keys i am getting their details.
Is it due to acess limitation?
if so then how to overcome it.
Also i wanted to get last login time and shutdown time of the user using QT4 and display it on the lineEdits , is there any way of getting it?
Please response to this.

d_stranz
19th June 2015, 16:33
Is it due to access limitation?

Possibly. I do not know how QSettings opens the Registry. If it opens and asks for read / write access and the key is restricted by Windows, then it could fail (which makes sense, since the area you are looking at is probably under the control of the network services).

Did you check QSettings::status() after creating your QSettings instance and after trying to read a setting?


Also i wanted to get last login time and shutdown time of the user using QT4 and display it on the lineEdits , is there any way of getting it?

No idea. You might have to dip into the Windows API to do this. Once you have a string, you can convert it to a QString and display it.

ChrisW67
20th June 2015, 03:44
Network interfaces. QNetworkInterface, no need for Windows specific coding. If you do not wish to use the Qt class then the correct way to do it is the Windows API calls GetInterfaceInfo and/or GetAdaptersInfo (NOT reading the registry which is annoyingly variable across Win versions).

On Windows the last login time can be had from Windows command line:


rem For a local user
C:\> net user dinesh123 | findstr /B /C:"Last logon"
rem or if a domain is involved
C:\> net user dinesh123 /domain | findstr /B /C:"Last logon"

You could get at this with QProcess (parse the net user command output in C++).

dinesh123
23rd June 2015, 12:25
Thanks once again. I have to check QSettings::status().

Thanks Chris
I will have to try it on QT4.

dinesh123
25th June 2015, 10:54
I think these are the commands on the cmd.exe.
I tried them in the QT program but they does not work.