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.
Articles
- Articles(C#.NET) (3)
- ASP.NET (6)
- Asp.Net(Email) (1)
- Asp.net(Image) (2)
- Asp.Net(Web.Config) (2)
- C#.NET (5)
- C#.NET Threading (3)
- C#.NET(ASP.NET) (4)
- Comments in PHP (1)
- Encryption In PHP (1)
- iPhone (Articles) (1)
- JavaScript (1)
- Json with PHP (1)
- LINQ (1)
- PHP (2)
- PHP Constant (1)
- PHP Operators (1)
- PHP Print Command (1)
- PHP Tutorial (2)
- Strings In PHP (1)
- Variable Declaration In PHP (1)
- WPF (1)
- XAML (2)
About Me
Help Link
Followers
Posted by
Sreejith A.K
Wednesday, November 11, 2009
comments (0)
Subscribe to:
Posts (Atom)