How to get current user logon time windows 10 using uipath

How to get current user logon time windows 10 using UiPath
Thanks in advance

Hi @vinod_badgujar

Welcome to UiPath community

  • You use System.DateTime.Now to get the current system date and time.

  • You can use an Assign activity in UiPath to assign this value to a variable. However, this method may not give you the exact logon time, but rather the current time.

Check out this thread

Regards
Gokul

1 Like

Hi @vinod_badgujar

give a try with

 System.Diagnostics.Process.GetCurrentProcess().StartTime.ToString()

Regards

Thank for quick response but it will give last logon date and time. I am looking for current logon time.

Hi @vinod_badgujar

just use

Now.ToString()

I looking for window logon time. Not current time

Hey

Can you scrape the text from the CMD window and paste the raw text in here?

We can then create a Regex pattern to scrape the logon time.

Cheers

Steve

Is any approach using system variable direct read using code.
Thanks

Hi

I’d prefer that solution too. I don’t know any option to achieve that.

But you can scrape and extract it reliably.

Cheers

Steve

You can run the command with Invoke Power Shell and then extract the time from the active row.

logonTime = Right(psOutput.Where(Function(x) x.Contains("Active")).First.ToString, 14)

image

image

2 Likes


Hi
Solution its work but attached validation error. How resolve same, please help.

Thanks in advanced

When validating on my computer, I don’t get any warning about the Invoke Power Shell activity. Attaching the xaml-file in case you want to test.

image

CurrentUserLogonTime.xaml (8.0 KB)

  1. Drag and drop the “Assign” activity onto the workflow canvas.
  2. In the “To” field of the “Assign” activity, enter a variable name to store the logon time.
  3. In the “Value” field of the “Assign” activity, enter the following code:

System.Diagnostics.EventLog.GetEventLogs("System", Environment.MachineName).Where(Function(x) x.Log == "System" And x.Source == "Microsoft-Windows-Winlogon").OrderByDescending(Function(x) x.Entries(x.Entries.Count - 1).TimeGenerated).FirstOrDefault().Entries.LastOrDefault(Function(x) x.InstanceId == 7001).TimeGenerated

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.