HelpViewerUIFramework.RunAsAdmin AdminRun = new RunAsAdmin(this.TestContext);

 

AdminRun.ExeCode = "HelpViewerUIFramework.RunAsAdminStaticMethod.ReadWriteRegedit.WriteRegistryValueEx(Microsoft.Win32.Registry.LocalMachine, HelpViewerUIFramework.HelpViewerSettings.DefaultStoreRegistryLocation, HelpViewerUIFramework.HelpViewerSettings.LocalStoreRegistryKey, @\"" + LocalStoreDefaultPath + "temp\");";

AdminRun.RunProcess();

 

--------------------------------------------------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Diagnostics;

using System.Runtime.InteropServices;

using System.CodeDom.Compiler;

using Microsoft.CSharp;

using Microsoft.Win32;

 

namespace HelpViewerUIFramework

{

    public class RunAsAdmin

    {

        #region Fields

        private string m_AddUsing = "";

        private string m_PreClassCode = "";

        private string m_PreMainCode = "";

        private string m_ExeCode = "";

        private const string m_RunAsAdminExeName = "RunAsAdmin.exe";

        SHELLEXECUTEINFO m_lpExecInfo = new SHELLEXECUTEINFO();

        private Microsoft.VisualStudio.TestTools.UnitTesting.TestContext m_testContext;

        #endregion

        #region Constructors

        public RunAsAdmin(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext)

        {

            this.m_testContext = testContext;

        }

        #endregion

        #region proerpties

 

        public string AddUsing

        {

            get { return m_AddUsing; }

            set { m_AddUsing = value; }

        }

        public string PreClassCode

        {

            get { return m_PreClassCode; }

            set { m_PreClassCode = value; }

        }

        public string PreMainCode

        {

            get { return m_PreMainCode; }

            set { m_PreMainCode = value; }

        }

        public string ExeCode

        {

            get { return m_ExeCode; }

            set { m_ExeCode = value; }

        }

        #endregion

        #region ImportAPI

        [StructLayout(LayoutKind.Sequential)]

        private struct SHELLEXECUTEINFO //using in ShellExecuteEx

        {

            public int cbSize;

            public uint fMask;

            public IntPtr hwnd;

            [MarshalAs(UnmanagedType.LPWStr)]

            public string lpVerb;

            [MarshalAs(UnmanagedType.LPWStr)]

            public string lpFile;

            [MarshalAs(UnmanagedType.LPWStr)]

            public string lpParameters;

            [MarshalAs(UnmanagedType.LPWStr)]

            public string lpDirectory;

            public int nShow;

            public IntPtr hInstApp;

            public IntPtr lpIDList;

            [MarshalAs(UnmanagedType.LPWStr)]

            public string lpClass;

            public IntPtr hkeyClass;

            public uint dwHotKey;

            public IntPtr DUMMYUNIONNAME;

            public IntPtr hProcess;

        }

        [System.Runtime.InteropServices.DllImport("Shell32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]