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); }
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); }
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(); } } }