Cannot create a Virtual Directory using System.DirectoryServices on Windows Vista RC1

F

fredfrog22

The following is an extract from a C# console application that creates
a Virtual Directory on IIS 5 or 6.

This code works on XP, Windows 2003 Server, Windows 2000.

It does not work on Windows Vista Release Candidate 1 (IIS 7).

The below line

pcProps[VDPROP_PATH].Value = strPath;

throws the exception "Path not found".

Note that the user running the exe has administrator rights on the
machine.

Also, this may be a related issue:

The Microsoft VB script C:\Inetpub\Adminscripts\mkwebdir.vbs no longer
works on Windows Vista RC1 when logged in as an administrator. The
exact same script and parameters runs on Windows XP.

Interestingly, I have found that other sample code downloaded from the
Internet that creates virtual directories does not work on Vista
either.

I suspect that this is a rights issue, but I do not know how to solve
this.

Thanks for your help.

+++++++++++

Code extract:
DirectoryEntry deRoot = new DirectoryEntry(IIS_DIR);

if (null != deRoot)

try
{
// check to see if this Virtual Directory already exists
m_deVirtualDir = deRoot.Children.Add(m_strVirtualDir,
IIS_SCHEMA_VIRTUAL_DIR);
}
catch
{
try
{
String strDir = IIS_DIR + "/" + m_strVirtualDir;
m_deVirtualDir = new DirectoryEntry(IIS_DIR + "/" +
m_strVirtualDir);
}
catch
{
}
}

if (null != m_deVirtualDir)
{
// commit the changes so far!
deRoot.CommitChanges();
m_deVirtualDir.CommitChanges();

// now we need to set up some properties of the new virtual
// directory
PropertyCollection pcProps = m_deVirtualDir.Properties;


// set the Path to the Virtual Directory
string strPath = m_strIISPath + "\\" + m_strVirtualDir;

// exception generated here
pcProps[VDPROP_PATH].Value = strPath;

etc etc
 
W

Willy Denoyette [MVP]

Please post Vista related problems to the Vista forums, check following URL
for available NG's and Forums
http://msdn.microsoft.com/windowsvista/community/default.aspx.
Be aware that on Vista, even an administrator runs with reduced privileges
(by default), I suggest you try to strat this with elevated privileges.

Willy.


| The following is an extract from a C# console application that creates
| a Virtual Directory on IIS 5 or 6.
|
| This code works on XP, Windows 2003 Server, Windows 2000.
|
| It does not work on Windows Vista Release Candidate 1 (IIS 7).
|
| The below line
|
| pcProps[VDPROP_PATH].Value = strPath;
|
| throws the exception "Path not found".
|
| Note that the user running the exe has administrator rights on the
| machine.
|
| Also, this may be a related issue:
|
| The Microsoft VB script C:\Inetpub\Adminscripts\mkwebdir.vbs no longer
| works on Windows Vista RC1 when logged in as an administrator. The
| exact same script and parameters runs on Windows XP.
|
| Interestingly, I have found that other sample code downloaded from the
| Internet that creates virtual directories does not work on Vista
| either.
|
| I suspect that this is a rights issue, but I do not know how to solve
| this.
|
| Thanks for your help.
|
| +++++++++++
|
| Code extract:
| DirectoryEntry deRoot = new DirectoryEntry(IIS_DIR);
|
| if (null != deRoot)
|
| try
| {
| // check to see if this Virtual Directory already exists
| m_deVirtualDir = deRoot.Children.Add(m_strVirtualDir,
| IIS_SCHEMA_VIRTUAL_DIR);
| }
| catch
| {
| try
| {
| String strDir = IIS_DIR + "/" + m_strVirtualDir;
| m_deVirtualDir = new DirectoryEntry(IIS_DIR + "/" +
| m_strVirtualDir);
| }
| catch
| {
| }
| }
|
| if (null != m_deVirtualDir)
| {
| // commit the changes so far!
| deRoot.CommitChanges();
| m_deVirtualDir.CommitChanges();
|
| // now we need to set up some properties of the new virtual
| // directory
| PropertyCollection pcProps = m_deVirtualDir.Properties;
|
|
| // set the Path to the Virtual Directory
| string strPath = m_strIISPath + "\\" + m_strVirtualDir;
|
| // exception generated here
| pcProps[VDPROP_PATH].Value = strPath;
|
| etc etc
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top