New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substitute for System.Windows.Forms.BootMode? #33853

Closed
rjmholt opened this Issue Dec 6, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@rjmholt

rjmholt commented Dec 6, 2018

Quick question -- I have a DLL that uses System.Windows.Forms only for BootMode and SystemInformation.BootMode. Is there any clear dependency/anything in the Windows Compatibility Pack I could use to get the same information in .NET Core today (rather than waiting for .NET Core 3)?

Thanks!

@rjmholt

This comment has been minimized.

rjmholt commented Dec 6, 2018

Ok I think I've found the relevant bit now that WinForms is open source!

SystemInformation.BootMode

native API call

@rjmholt

This comment has been minimized.

rjmholt commented Dec 6, 2018

Here is a contained, naive implementation:

    enum BootMode
    {
        Normal = 0,
        FailSafe = 1,
        FailSafeWithNetwork = 2
    }

    class Program
    {
        private const int SM_CLEANBOOT = 67;

        static void Main(string[] args)
        {
            BootMode bootMode = GetBootMode();
            Console.WriteLine($"System boot mode: {bootMode}");
        }

        static BootMode GetBootMode()
        {
            return (BootMode)GetSystemMetrics(SM_CLEANBOOT);
        }

        [DllImport("user32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
        static extern int GetSystemMetrics(int nIndex);
    }

@jkotas jkotas added the question label Dec 6, 2018

@jkotas jkotas closed this Dec 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment