Esempio n. 1
0
        private static SafeProcessHandle CreateProcessAsUser(SafeTokenHandle newToken, string appToRun, string args, string startupFolder, bool newWindow, bool hidden)
        {
            var si = new STARTUPINFO();

            if (newWindow)
            {
                si.dwFlags     = 0x00000001; // STARTF_USESHOWWINDOW
                si.wShowWindow = (short)(hidden ? 0 : 1);
            }

            si.cb = Marshal.SizeOf(si);

            var  pi = new PROCESS_INFORMATION();
            uint dwCreationFlags = newWindow ? (uint)CreateProcessFlags.CREATE_NEW_CONSOLE : 0;

            if (!TokensApi.CreateProcessAsUser(newToken, ArgumentsHelper.UnQuote(appToRun), $"{appToRun} {args}",
                                               IntPtr.Zero, IntPtr.Zero, false, dwCreationFlags, IntPtr.Zero, startupFolder, ref si,
                                               out pi))
            {
                throw new Win32Exception();
            }

            CloseHandle(pi.hThread);
            return(new SafeProcessHandle(pi.hProcess, true));
        }
Esempio n. 2
0
        public static bool IsWindowsApp(string exe)
        {
            var       path          = FindExecutableInPath(ArgumentsHelper.UnQuote(exe));
            var       shinfo        = new Native.FileApi.SHFILEINFO();
            const int SHGFI_EXETYPE = 0x000002000;
            var       fileInfo      = Native.FileApi.SHGetFileInfo(path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_EXETYPE);
            var       retval        = (fileInfo.ToInt64() & 0xFFFF0000) > 0;

            return(retval);
        }