Ejemplo n.º 1
0
        internal static SecurityIdentifier GetCurrentAppContainerSid()
        {
            Fx.Assert(AppContainerInfo.IsAppContainerSupported, "AppContainers are not supported.");
            if (currentAppContainerSid == null)
            {
                lock (thisLock)
                {
                    if (currentAppContainerSid == null)
                    {
                        SafeCloseHandle tokenHandle = null;
                        try
                        {
                            tokenHandle            = AppContainerInfo.GetCurrentProcessToken();
                            currentAppContainerSid = UnsafeNativeMethods.GetAppContainerSid(tokenHandle);
                        }
                        finally
                        {
                            if (tokenHandle != null)
                            {
                                tokenHandle.Dispose();
                            }
                        }
                    }
                }
            }

            return(currentAppContainerSid);
        }
Ejemplo n.º 2
0
        static SafeCloseHandle GetCurrentProcessToken()
        {
            SafeCloseHandle tokenHandle = null;

            if (!UnsafeNativeMethods.OpenProcessToken(
                    UnsafeNativeMethods.GetCurrentProcess(),
                    TokenAccessLevels.Query,
                    out tokenHandle))
            {
                int error = Marshal.GetLastWin32Error();
                throw FxTrace.Exception.AsError(new Win32Exception(error));
            }

            return(tokenHandle);
        }
Ejemplo n.º 3
0
        static int GetCurrentSessionId()
        {
            Fx.Assert(AppContainerInfo.IsAppContainerSupported, "AppContainers are not supported.");
            SafeCloseHandle tokenHandle = null;

            try
            {
                tokenHandle = AppContainerInfo.GetCurrentProcessToken();
                return(UnsafeNativeMethods.GetSessionId(tokenHandle));
            }
            finally
            {
                if (tokenHandle != null)
                {
                    tokenHandle.Dispose();
                }
            }
        }