Software Programs and Projects

This Software Programs and Projects include programing tips and technology using different languages like VC++,ASP,JSP C#.Net,PHP,VB.Net,JavaScript,ASP.NET .Software Programs and Projects blog mainly support to software programmers and provide help through the mail.

Get All Windows Services and Service Path in ASP.NET using C# .Check If directory and Files existing in the current location. This code also explain how to get values from the xml document.

protected void Button1_Click(object sender, EventArgs e)
{
//Get All Windows Services
RegistryKey services = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services");
if (services != null)
{
//Get Service Path
object pathtoexecutable = services.OpenSubKey("KTSInfoMateServer").GetValue("ImagePath");
string strServicePath = pathtoexecutable.ToString();
int iStartPosition = strServicePath.LastIndexOf('\\');
string strServiceFoldePath = strServicePath.Remove(iStartPosition);
strServiceFoldePath = strServiceFoldePath.Replace('\\', '/');
strServiceFoldePath = strServiceFoldePath.Remove(0, 1);
strServiceFoldePath += "/";
try
{
//Check Direcory Existing
DirectoryInfo objDirectoryInfo = new DirectoryInfo(strServiceFoldePath);
if (objDirectoryInfo.Exists)
{
//Check File Existing in the Service directory
string strSettingsFileName = strServiceFoldePath + "/" + "EmSettings.xml";
FileInfo objFileInfo = new FileInfo(strSettingsFileName);
if (objFileInfo.Exists)
{
XmlNode xNode;
XmlDocument objDoc = new XmlDocument();
objDoc.Load(strSettingsFileName);
string strSettingsXML = objDoc.InnerXml;
XmlNode inXmlNode = objDoc.DocumentElement;
XmlNodeList nodeList;
if (inXmlNode.HasChildNodes)
{
nodeList = inXmlNode.ChildNodes;
for (int iNodeIndex = 0; iNodeIndex <= nodeList.Count - 1; iNodeIndex++)
{
xNode = inXmlNode.ChildNodes[iNodeIndex];
if (xNode != null)
{
if (xNode.Name == "StreamingPort")
{
m_strStreamingPort = xNode.InnerText.ToString();
break;
}
}
}
}
Preview();
lblStatus.Text = "File Exists";
}
else
{
lblStatus.Text = "Not Exists";
}
}
}
catch (Exception objException)
{
string strErrorMessage = objException.Message.ToString();
}

}

}

tag:-
Get All Windows Services and Service Path in ASP.NET using C# .Check If directory and Files existing in the current location. This code also explain how to get values from the xml document.