Ejemplo n.º 1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            NameValueCollection _aa = new NameValueCollection();

            _aa.Add("bb", "cc");
            _aa.Add("cc", "dd");
            CookieManger.AddValue("name", _aa);
        }
Ejemplo n.º 2
0
        public static void CreateProcess(string app, string parm, string path = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = System.IO.Path.GetDirectoryName(app);
            }
            logger = LogManager.LogManager.GetLogger("CreateProcess");
            bool   result;
            IntPtr hToken      = WindowsIdentity.GetCurrent().Token;
            IntPtr hDupedToken = IntPtr.Zero;

            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
            SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();

            sa.Length = Marshal.SizeOf(sa);

            STARTUPINFO si = new STARTUPINFO();

            si.cb = Marshal.SizeOf(si);

            hToken = CookieManger.GetCurrentUserToken();
            //int dwSessionID = WTSGetActiveConsoleSessionId();
            //result = WTSQueryUserToken(dwSessionID, out hToken);

            //if (!result)
            //{
            //    ShowMessageBox("WTSQueryUserToken failed", "AlertService Message");
            //}
            logger.Debug("hToken:" + hToken.ToString());

            result = DuplicateTokenEx(
                hToken,
                GENERIC_ALL_ACCESS,
                ref sa,
                (int)SECURITY_IMPERSONATION_LEVEL.SecurityIdentification,
                (int)TOKEN_TYPE.TokenPrimary,
                ref hDupedToken
                );

            if (!result)
            {
                int    error        = Marshal.GetLastWin32Error();
                string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
                logger.Error("DuplicateTokenEx:" + errorMessage);
                //ShowMessageBox("DuplicateTokenEx failed", "AlertService Message");
            }

            IntPtr lpEnvironment = IntPtr.Zero;

            result = CreateEnvironmentBlock(out lpEnvironment, hDupedToken, false);

            if (!result)
            {
                int    error        = Marshal.GetLastWin32Error();
                string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
                logger.Error("CreateEnvironmentBlock:" + errorMessage);
                //ShowMessageBox("CreateEnvironmentBlock failed", "AlertService Message");
            }
            string lpCommandline = string.Empty;

            if (!string.IsNullOrEmpty(parm))
            {
                lpCommandline = parm;
            }
            result = CreateProcessAsUser(
                hDupedToken,
                app,                 //file to execute
                lpCommandline,       //command line
                ref sa, ref sa,
                false, 0, IntPtr.Zero,
                path, ref si, ref pi);

            if (!result)
            {
                int    error        = Marshal.GetLastWin32Error();
                string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
                logger.Error("CreateProcessAsUser:"******"CreateProcessAsUser Error: {0}", error);
                //ShowMessageBox(message, "AlertService Message");
            }

            if (pi.hProcess != IntPtr.Zero)
            {
                CloseHandle(pi.hProcess);
            }
            if (pi.hThread != IntPtr.Zero)
            {
                CloseHandle(pi.hThread);
            }
            if (hDupedToken != IntPtr.Zero)
            {
                CloseHandle(hDupedToken);
            }
        }