🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# RMOS / RunPowerShellCommand copy as power shell olarak kopyaladığımız request curl olarak dinamik çalıştırır

1-) C# RMOS - RunPowerShellCommand copy as power shell olarak kopyaladığımız request curl olarak dinamik çalıştırır

 

nuget console yaz çalıştır -> Install-Package System.Management.Automation.dll -Version 10.0.10586

 

chrome -> copy as PowerShell

YENİ

 

static string RunPowerShellCommand(string copyaspowershell)

{

    try

    {

        int timeoutSeconds = 30; // 30 saniye de cevap gelmezse boş döner

        using (PowerShell PowerShellInstance = PowerShell.Create())

        {

            PowerShellInstance.AddScript(copyaspowershell);

 

            IAsyncResult result = PowerShellInstance.BeginInvoke();

 

            bool completed = result.AsyncWaitHandle.WaitOne(timeoutSeconds * 1000);

 

            if (!completed)

            {

                PowerShellInstance.Stop();

                return "PowerShell Komutu Zaman Aşımına Uğradı";

            }

 

            Collection<PSObject> PSOutput = new Collection<PSObject>(PowerShellInstance.EndInvoke(result));

 

            if (PowerShellInstance.HadErrors)

            {

                string errorMessage = string.Join("\n", PowerShellInstance.Streams.Error);

                return $"PowerShell Error:\n{errorMessage}";

            }

 

            string output = string.Join("\n", PSOutput);

            return output;

        }

    }

    catch (Exception ex)

    {

        return "Hata!!\n" + ex.Message;

    }

}

 

ESKİ

 

static string RunPowerShellCommand(string copyaspowershell)

{

 

    using (PowerShell PowerShellInstance = PowerShell.Create())

    {

        // PowerShell komutlarını eklemek

        PowerShellInstance.AddScript(copyaspowershell);

 

        // Çalıştır ve sonuçları al

        Collection<PSObject> PSOutput = PowerShellInstance.Invoke();

 

        // Hataları kontrol et

        if (PowerShellInstance.HadErrors)

        {

            string errorMessage = string.Join("\n", PowerShellInstance.Streams.Error);

            return $"PowerShell Error:\n{errorMessage}";

        }

 

        // Sonucu birleştir ve döndür

        string result = string.Join("\n", PSOutput);

        return result;

    }

}

 

 

nugette bulunan Jint kütüphanesi javascript çalıştırmaya yarar c# ile

 2024 Ocak 06 Cumartesi
 216