How can I find out when the computer shuts down after executing the shutdown command?

67 views Asked by At

The user ran the command "shutdown -s -t 8000" on the command line. I need to write code in C# that will return the exact date and time when the computer will be turned off. I tried to get information from the windows event log:

int shutdownEventId = 1074;
string queryString = $@"*[System/EventID={shutdownEventId}]";
EventLogQuery query = new EventLogQuery ( "System", PathType.LogName, queryString );

But the log only contains information about when and by whom the shutdown command was executed. Then I tried using schtasks. But I also didn’t find any information about the computer shutdown time. It appears that the shutdown utility is not creating tasks in the task scheduler. I found this old article: https://web.archive.org/web/20160604093253/http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/windows-nt-6-shutdown-process.html Here we are talking about a process called "winlogon". But it is not specified how its flags can be read. So... how can I get the exact date and time the computer shut down after running the shutdown command?

1

There are 1 answers

2
Ludwig Vitovskiy On

You can get the time when command was executed, can you get executed command text too? If is it so, you can just add time in seconds from command text to command execution time