Monday 3 August 2020

Start Stop Window Service of Remote Machine

using System;
using System.Drawing;
using System.Management;
using System.Web.Configuration;
using System.Web.UI;

namespace WebApplication2_winservice
{
    public partial class _Default : Page
    {
        string serviceName = WebConfigurationManager.AppSettings["ServiceName"].ToString();
        string machineName = WebConfigurationManager.AppSettings["MachineName"].ToString();
        string userName = WebConfigurationManager.AppSettings["UserName"].ToString();
        string password = WebConfigurationManager.AppSettings["Password"].ToString();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                StatusShow();
            }
        }
        private void StatusShow()
        {
            string serviceStatus = Convert.ToString(ViewState["Status"]);
            if (serviceStatus != "")
            {
                if (serviceStatus == "Running")
                {
                    LblServiceStatus.ForeColor = Color.Green;
                    LblServiceStatus.Text = "Deploy Service is Running!";
                }
                else
                {
                    LblServiceStatus.ForeColor =Color.Red;
                    LblServiceStatus.Text = "Deploy Service is Stopped!";
                }

            }
            else if (ServiceStatus())
            {
                LblServiceStatus.ForeColor = Color.Green;
                LblServiceStatus.Text = "Deploy Service is Running!";
            }
            else
            {
                LblServiceStatus.ForeColor = Color.Red;
                LblServiceStatus.Text = "Deploy Service is Stopped!";
            }
        }
        private void StartStopService()
        {         
            ConnectionOptions connectoptions = new ConnectionOptions();
            connectoptions.Username = userName;
            connectoptions.Password = password;

            //IP Address of the remote machine
            ManagementScope scope = new ManagementScope(@"\\" + machineName + @"\root\cimv2");
            scope.Options = connectoptions;

            //WMI query to be executed on the remote machine
            SelectQuery query = new SelectQuery("select * from Win32_Service where name = '" + serviceName + "'");

            using (ManagementObjectSearcher searcher = new
                        ManagementObjectSearcher(scope, query))
            {
                ManagementObjectCollection collection = searcher.Get();
                foreach (ManagementObject service in collection)
                {

                    if (service["Started"].Equals(true))
                    {
                        //Stop the service                       
                        service.InvokeMethod("StopService", null);
                        ViewState["Status"] = "Running";
                    }
                    if (service["Started"].Equals(false))
                    {
                        //Start the service                     
                        service.InvokeMethod("StartService", null);
                        ViewState["Status"] = "Stopped";
                    }

                }
            }
            Response.Redirect("Default.aspx");
        }
        private bool ServiceStatus()
        {
            bool status = false;
           
            ConnectionOptions connectoptions = new ConnectionOptions();
            connectoptions.Username = userName;
            connectoptions.Password = password;

            //IP Address of the remote machine
            ManagementScope scope = new ManagementScope(@"\\" + machineName + @"\root\cimv2");
            scope.Options = connectoptions;

            //WMI query to be executed on the remote machine
            SelectQuery query = new SelectQuery("select * from Win32_Service where name = '" + serviceName + "'");

            using (ManagementObjectSearcher searcher = new
                        ManagementObjectSearcher(scope, query))
            {
                ManagementObjectCollection collection = searcher.Get();
                foreach (ManagementObject service in collection)
                {

                    if (service["Started"].Equals(true))
                    {
                        status = true;
                    }
                    if (service["Started"].Equals(false))
                    {
                        status = false;
                    }
                }
            }
            return status;
        }
        protected void btnStartStop_Click(object sender, EventArgs e)
        {
            StartStopService();
        }
    }
}

Saturday 26 August 2017

IIS version List


  • IIS 1.0 was initially released as a free add-on for Windows NT 3.51.
  • IIS 2.0 was included with Windows NT 4.0.
  • IIS 3.0, which was included with Service Pack 2 of Windows NT 4.0, introduced the Active Server Pages dynamic scripting environment.
  • IIS 4.0 was released as part of the "Option Pack" for Windows NT 4.0. It introduced the new MMC-based administration application.
  • IIS 5.0 shipped with Windows 2000 and introduced additional authentication methods, support for the WebDAV protocol, and enhancements to ASP. IIS 5.0 also dropped support for the Gopher protocol
  • IIS 5.1 was shipped with Windows XP Professional, and was nearly identical to IIS 5.0 on Windows 2000.
  • IIS 6.0, included with Windows Server 2003 and Windows XP Professional x64 Edition, added support for IPv6 and included a new worker process model that increased security as well as reliability.
  • IIS 7.0 was a complete redesign and rewrite of IIS, and was shipped with Windows Vista and Windows Server 2008. IIS 7.0 included a new modular design that allowed for a reduced attack surface and increased performance. It also introduced a hierarchical configuration system allowing for simpler site deploys, a new Windows Forms-based management application, new command-line management options and increased support for the .NET Framework. IIS 7.0 on Vista does not limit the number of allowed connections as IIS on XP did, but limits concurrent requests to 10 (Windows Vista Ultimate, Business, and Enterprise Editions) or 3 (Vista Home Premium). Additional requests are queued, which hampers performance, but they are not rejected as with XP.
  • IIS 7.5 was included in Windows 7 (but it must be turned on in the side panel of Programs and Features) and Windows Server 2008 R2. IIS 7.5 improved WebDAV and FTP modules as well as command-line administration in PowerShell. It also introduced TLS 1.1 and TLS 1.2 support and the Best Practices Analyzer tool and process isolation for application pools.
  • IIS 8.0 is only available in Windows Server 2012 and Windows 8. IIS 8.0 includes SNI (binding SSL to hostnames rather than IP addresses), Application Initialization, centralized SSL certificate support, and multicore scaling on NUMA hardware, among other new features.
  • IIS 8.5 is included in Windows Server 2012 R2 and Windows 8.1. This version includes Idle worker-Process page-out, Dynamic Site Activation, Enhanced Logging, ETW logging, and Automatic Certificate Rebind.
  • IIS 10 is included in Windows Server 2016 and Windows 10. This version includes support for HTTP/2.

Tuesday 22 August 2017

Generic Collection Vs Non Generic Collection in C#



Generic collections - These are the collections that can hold data of same type and we can decide while initializing what type of data that collections can hold. 
Advantages - Type Safe, Secure, reduced overhead of implicit and explicit conversions. 

Generic collections Example: (List<T>, Dictionary<T, U>, SortedList<T, U>, Queue<T> etc) 

Non generic collections hold elements of different data types, it hold all elements as object type. 
so it includes overhead of implicit and explicit conversions.

Non-generic collections Example: (ArrayList, Hashtable, SortedKist, Queue etc.) 

List of JavaScript libraries

Web-application related (MVC, MVVM)

  • AngularJS
  • Aurelia
  • Backbone.js
  • Cappuccino
  • Chaplin.js
  • Echo 
  • Ember.js
  • Enyo
  • Ext JS
  • Google Web Toolkit
  • Inferno
  • JavaScriptMVC
  • Knockout
  • Meteor
  • Mojito
  • MooTools
  • Node.js
  • Prototype JavaScript Framework
  • React
  • Rialto Toolkit
  • SproutCore
  • Vue.js
  • Wakanda Framework