Show all posts.
If you've ever wondered how could you list all your usernames and passwords that are set on the 'Directory Security' tab on each website's properties (in inetmgr) then this small C# code snippet would be for you ..
Just a note: so far it seems that this code snippet works only on Windows Server 2003 - i have no ideea why doesn't it work on XP / Vista as well (don't care actually :) - i needed it for win 2003)...
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
static void Main(string{} args)
{
DirectoryEntry iisBase = new DirectoryEntry("IIS://localhost/W3SVC");
PrintUserNameAndPass(iisBase);
}
private static void PrintUserNameAndPass(DirectoryEntry iisChild)
{
String userName = null;
String password = null;
if (iisChild.Properties{"AnonymousUserName"} != null)
{
userName = iisChild.Properties{"AnonymousUserName"}.Value as String;
}
if (iisChild.Properties{"AnonymousUserPass"} != null)
{
password = iisChild.Properties{"AnonymousUserPass"}.Value as String;
}
if (userName != null && password != null)
{
if (!userNames.Contains(userName))
{
byte{} passwordChars = ASCIIEncoding.ASCII.GetBytes(password);
Console.WriteLine(String.Format("{0}\t{1}", userName,
System.Convert.ToBase64String(passwordChars)));
userNames.Add(userName);
}
}
foreach (DirectoryEntry newChild in iisChild.Children)
{
PrintUserNameAndPass(newChild);
}
iisChild.Dispose();
}
|
Update: Actually I've found out that the exception on Windows Vista was caused by the lack of IIS6 compatibility module. So I've just had to install this compatibility module from Windows features and everything works as expected.
|