0

I am trying to get the time of the last system shutdown time of a client machine and I am using the following method:

public static DateTime GetLastSystemShutdown()
    {
        string sKey = @"System\CurrentControlSet\Control\Windows";
        Microsoft.Win32.RegistryKey key =  Microsoft.Win32.Registry.LocalMachine.OpenSubKey(sKey);

        string sValueName = "ShutdownTime";
        byte[] val = (byte[])key.GetValue(sValueName);
        long valueAsLong = BitConverter.ToInt64(val, 0);
        return DateTime.FromFileTime(valueAsLong);
    }

It works fine within the debugger on my system, however, when I publish to the server where IIS is hosting, whenever the user triggers method it displays the last shutdown time of the IIS server instead of the client machine.

Is it possible to get that information from the client machine? I am using Windows Authentication.

EyeSeeSharp
  • 604
  • 1
  • 8
  • 21
  • 1
    You think every (Windows) machine on the Internet should be exposing its registry to any random servers on the Internet? – Damien_The_Unbeliever Mar 22 '17 at 14:58
  • This code runs on your server so returns results about your server. When debugging, your machine *is* the server - so that's why it seemed to work. – Hans Kesting Mar 22 '17 at 14:59
  • When you say you want to get information from "the client machine", do you mean you want the shutdown time of the IIS server where this code runs or the machine actually running the web browser? (hint: you you *never* be able to get the latter) – DavidG Mar 22 '17 at 15:04
  • @DavidG The latter. I guess I won't be getting that then, lol. Thank you – EyeSeeSharp Mar 22 '17 at 15:54
  • Remember that your IIS code is running on the server, it's only sending out HTML to the browser to be rendered. – DavidG Mar 22 '17 at 15:55

0 Answers0