0

I want o develop a console application to get IIS application pool status as of check the status of IIS Application Pool.

I got the similar code and in the DirectoryEntry class,when i add the given line of code I get errors.(I added only the below line in that class)

 appPools = new DirectoryEntry("IIS://" + ServerName + "/W3SVC/AppPools", UName, Pwd).Children;

Can someone please let me know what are the packages that I should include and what should i include more to get rid of the errors.

errors I get in the DirectoryEntry class-:

         name 'appPools' does not exist in the current context.
         name 'Children' does not exist in the current context.
         the type or namespace name 'Pwd' could not be found(are u missing a using directory or an assembly reference)
         the type or namespace name 'ServerName' could not be found(are u missing a using directory or an assembly reference)
         the type or namespace name 'UName' could not be found(are u missing a using directory or an assembly reference)
         the modifier 'new' is not valid for this item
         identifier expected

can somone please help me as I am new to c#.

Thankyou.

rissa
  • 57
  • 1
  • 7
  • Please [edit] your question to include the full source code of your file. It looks like you have placed this line of code at a location where it doesn't belong. – Progman Jul 31 '21 at 18:30
  • @Progman Editted. – rissa Jul 31 '21 at 19:06
  • You forgot a type for the field `appPools` in the `DirectoryEntry` class. It looks like it should be `DirectoryEntries appPools = new Directory....`. Also, you are defining a new class named `DirectoryEntry`, but also create an instance of `DirectoryEntry`. Not sure what you are trying to do with your `DirectoryEntry` class, but there is already a class `System.DirectoryServices.DirectoryEntry`. Most likely you want to simply delete your `DirectoryEntry` class there. – Progman Jul 31 '21 at 19:50
  • @Progman i referred https://stackoverflow.com/questions/37613513/check-the-status-of-iis-application-pool.Here there is a class called DirectoryEntory.Thats why I used it but I didnt understand the purpose of that class.If i delete the DirectoryEntry class,will it harm the functionality in the program.cs?or if I delete the DirectoryEntry class,how do I have to modify the program.cs class? – rissa Aug 01 '21 at 03:29
  • when I delete the DirectoryEntry class, I still get the same error as mentined above in the line,"if (appPool.Name.ToString().ToLower().Trim() == DT.Rows[i]["AppPoolSrvName"].ToString().ToLower().Trim())".And if I remove the code segment for Getting Server Credentials and Server Name from config file in program.cs class,then how can I modify it?(like without getting the Uname and Pwd,can I do like getting the process name from appsettings.json file?If its possible,how to implement it)or is there any other way I can do this?Can you please help me,Iam really confused – rissa Aug 01 '21 at 03:43
  • The `DT.Rows` is a variable with the data from a database, the [author of the post](https://stackoverflow.com/a/48262795/286934) is using. Check the comment behind that line with the `DT.Rows` code. Replace that line with your server name you have. When you want to read the data from the "appsettings.json" file, check other questions like https://stackoverflow.com/questions/31453495/how-to-read-appsettings-values-from-a-json-file-in-asp-net-core – Progman Aug 01 '21 at 06:54

1 Answers1

1

You should install NuGet package System.DirectoryEntry and then add a using to System.DirectoryServices.DirectoryEntry and then it should compile.

Regarding UName & Pwd you just need to provide strings that represent your user name and password.

Misha Zaslavsky
  • 8,414
  • 11
  • 70
  • 116