Example #1
0
 public static extern bool CreateProcessAsUser(
     IntPtr hToken,
     string lpApplicationName,
     string lpCommandLine,
     ref SecurityAttributes lpProcessAttributes,
     ref SecurityAttributes lpThreadAttributes,
     bool bInheritHandles,
     uint dwCreationFlags,
     IntPtr lpEnvironment,
     string lpCurrentDirectory,
     ref StartupInfo lpStartupInfo,
     out ProcessInformation lpProcessInformation
 );
Example #2
0
 public static extern bool CreateProcessAsUser(
     IntPtr hToken,
     string lpApplicationName,
     string lpCommandLine,
     ref SecurityAttributes lpProcessAttributes,
     ref SecurityAttributes lpThreadAttributes,
     bool bInheritHandles,
     uint dwCreationFlags,
     IntPtr lpEnvironment,
     string lpCurrentDirectory,
     ref StartupInfo lpStartupInfo,
     out ProcessInformation lpProcessInformation
     );
Example #3
0
        /* ----------------------------------------------------------------- */
        ///
        /// RunOpenFolderEm
        ///
        /// <summary>
        /// EmergencyMode 下で、フォルダを開くポストプロセスを実行します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void RunOpenFolderEm(string path)
        {
            const uint TOKEN_ASSIGN_PRIMARY = 0x00000001;
            const uint TOKEN_DUPLICATE      = 0x00000002;
            const uint TOKEN_IMPERSONATE    = 0X00000004;
            const uint TOKEN_READ           = 0x00020008;

            var empty = new SecurityAttributes();
            empty.nLength = (uint)Marshal.SizeOf(empty);

            var hsrc = IntPtr.Zero;
            AdvApi32.OpenThreadToken(Kernel32.GetCurrentThread(), TOKEN_DUPLICATE, true, ref hsrc);

            var hdup = IntPtr.Zero;
            AdvApi32.DuplicateTokenEx(hsrc,
                TOKEN_IMPERSONATE | TOKEN_READ | TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE,
                ref empty,
                2 /* SecurityImpersonation */,
                1 /* TokenPrimary */,
                ref hdup
            );

            Kernel32.CloseHandle(hsrc);
            AdvApi32.RevertToSelf();

            var env = IntPtr.Zero;
            UserEnv.CreateEnvironmentBlock(ref env, hdup, false);

            var cmdline = string.Format("explorer.exe \"{0}\"", IoEx.Path.GetDirectoryName(path));
            var message = string.Format("CubePdf.PostProcess.RunOpenFolderEm: {0}", cmdline);
            _messages.Add(new Message(Message.Levels.Debug, message));

            var pi = new ProcessInformation();
            var startup = new StartupInfo();
            startup.cb = (uint)Marshal.SizeOf(startup);
            startup.lpDesktop = @"winsta0\default";

            var status = AdvApi32.CreateProcessAsUser(hdup,
                null,
                cmdline,
                ref empty, /* SecurityAttributes for process */
                ref empty, /* SecurityAttributes for thread */
                false,
                0x0400, /* CREATE_UNICODE_ENVIRONMENT */
                env,
                null,
                ref startup,
                out pi
            );

            if (!status) throw new Win32Exception(Marshal.GetLastWin32Error());
        }
Example #4
0
        /* ----------------------------------------------------------------- */
        ///
        /// RunOpenFolderEm
        ///
        /// <summary>
        /// EmergencyMode 下で、フォルダを開くポストプロセスを実行します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void RunOpenFolderEm(string path)
        {
            const uint TOKEN_ASSIGN_PRIMARY = 0x00000001;
            const uint TOKEN_DUPLICATE      = 0x00000002;
            const uint TOKEN_IMPERSONATE    = 0X00000004;
            const uint TOKEN_READ           = 0x00020008;

            var empty = new SecurityAttributes();

            empty.nLength = (uint)Marshal.SizeOf(empty);

            var hsrc = IntPtr.Zero;

            AdvApi32.OpenThreadToken(Kernel32.GetCurrentThread(), TOKEN_DUPLICATE, true, ref hsrc);

            var hdup = IntPtr.Zero;

            AdvApi32.DuplicateTokenEx(hsrc,
                                      TOKEN_IMPERSONATE | TOKEN_READ | TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE,
                                      ref empty,
                                      2 /* SecurityImpersonation */,
                                      1 /* TokenPrimary */,
                                      ref hdup
                                      );

            Kernel32.CloseHandle(hsrc);
            AdvApi32.RevertToSelf();

            var env = IntPtr.Zero;

            UserEnv.CreateEnvironmentBlock(ref env, hdup, false);

            var cmdline = string.Format("explorer.exe \"{0}\"", IoEx.Path.GetDirectoryName(path));
            var message = string.Format("CubePdf.PostProcess.RunOpenFolderEm: {0}", cmdline);

            _messages.Add(new Message(Message.Levels.Debug, message));

            var pi      = new ProcessInformation();
            var startup = new StartupInfo();

            startup.cb        = (uint)Marshal.SizeOf(startup);
            startup.lpDesktop = @"winsta0\default";

            var status = AdvApi32.CreateProcessAsUser(hdup,
                                                      null,
                                                      cmdline,
                                                      ref empty, /* SecurityAttributes for process */
                                                      ref empty, /* SecurityAttributes for thread */
                                                      false,
                                                      0x0400,    /* CREATE_UNICODE_ENVIRONMENT */
                                                      env,
                                                      null,
                                                      ref startup,
                                                      out pi
                                                      );

            if (!status)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }