🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# RMOS / cmd yönetici çalıştırma ve kod çalıştırma

1-) C# RMOS - cmd yönetici çalıştırma ve kod çalıştırma

 

açıklama : .bat dosyasına kodları yaz onu yönetici olarak çalıştır  yani "runas"

 

  public void SqlStopStart()

        {

            try

            {

                string path = "SqlStopStart.bat";

                if (!File.Exists(path))

                {

                    string sqlInstanceName = getInstanceName();

                    File.WriteAllText("SqlStopStart.bat", "net stop "+ sqlInstanceName + " && net start "+ sqlInstanceName + "");

                }

                Process p = new Process();

                ProcessStartInfo psi = new ProcessStartInfo(path);

                psi.WindowStyle = ProcessWindowStyle.Hidden;

                psi.Verb = "runas";

                p.StartInfo = psi;

                p.Start();

            }

            catch (Exception ex)

            {

                MessageBox.Show("HATA " + ex.Message);

 

            }

        }

 

        public string getInstanceName()

        {

            string query = @"DECLARE @GetInstances TABLE

( Value nvarchar(100),

 InstanceNames nvarchar(100),

 Data nvarchar(100))

 

Insert into @GetInstances

EXECUTE xp_regread

  @rootkey = 'HKEY_LOCAL_MACHINE',

  @key = 'SOFTWARE\Microsoft\Microsoft SQL Server',

  @value_name = 'InstalledInstances'

 

Select InstanceNames from @GetInstances ";

 

            return dbtools.DegerGetir(query);

        }

 

 2021 Ağustos 12 Perşembe
 440