Link to home
Start Free TrialLog in
Avatar of i-mate05
i-mate05

asked on

Programmatically setting the "execute permissions" for a virtual directory to "Scripts Only"

I was wondering if anyone knew the property that you can set to make a virtual directory's execute permissions set to scripts only. I am trying to automatically create multiple virtual directories within a custom installation process.

I'm using System.DirectoryServices:

// Code chunk
            DirectoryEntries virtualEntries = rootIIS.Children;

            // now add each virtual
            DirectoryEntry virtualDir = null;

            try
            {
                virtualDir = rootIIS.Children.Find(appName, "IIsWebVirtualDir");
            }
            catch { /* do nothing  */ }

            if (virtualDir == null)
                virtualDir = rootIIS.Children.Add(appName, "IIsWebVirtualDir");
           
            virtualDir.CommitChanges();

            virtualDir.Properties["AppRoot"][0] = "/LM/W3SVC/1/ROOT/" + appName;
            virtualDir.Invoke("AppCreate2", new object[] { "2" });
            virtualDir.CommitChanges();
            virtualDir.Properties["Path"][0] = path;
            virtualDir.Properties["EnableDefaultDoc"][0] = true;
            virtualDir.Properties["DefaultDoc"][0] = defaultDocName;
            virtualDir.Properties["AppFriendlyName"][0] = appName;
            virtualDir.Properties["AccessRead"][0] = true;
            virtualDir.Properties["AccessExecute"][0] = false;
            virtualDir.Properties["AccessScript"][0] = true;
            virtualDir.Properties["EnableDirBrowsing"][0] = false;
            virtualDir.Properties["AuthAnonymous"][0] = true;
            virtualDir.Properties["AuthBasic"][0] = false;
            virtualDir.Properties["AuthNTLM"][0] = false;
            virtualDir.Properties["EnableDefaultDoc"][0] = true;
            virtualDir.Properties["DefaultDoc"][0] = defaultDocName;
// End Code Chunk

Is it a property available to me within the Properties of a Virtual Directory(Directory Entry) object? The virtual directories are all created perfectly, but the execute permissions are not being properly set to scripts only. Any ideas?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of i-mate05
i-mate05

ASKER

Thanks for the informative response, I can successfully set the execute permissions to scripts only when applying this through VBScript, however I still cannot apply this setting through .NET's System.DirectoryServices... I'll post another thread on this issue. Thanks for the help!
This definately can be achieved using system.directoryservices.directoryentry
It looks as though you're committing the setitngs prior to the script access being set (you definately use  virtualDir.Properties["AccessScript"][0] = true;)
Try this instead:
           virtualDir.Properties["AppRoot"][0] = "/LM/W3SVC/1/ROOT/" + appName;
            virtualDir.Properties["Path"][0] = path;
            virtualDir.Properties["EnableDefaultDoc"][0] = true;
            virtualDir.Properties["DefaultDoc"][0] = defaultDocName;
            virtualDir.Properties["AppFriendlyName"][0] = appName;
            virtualDir.Properties["AccessRead"][0] = true;
            virtualDir.Properties["AccessExecute"][0] = false;
            virtualDir.Properties["AccessScript"][0] = true;
            virtualDir.Properties["EnableDirBrowsing"][0] = false;
            virtualDir.Properties["AuthAnonymous"][0] = true;
            virtualDir.Properties["AuthBasic"][0] = false;
            virtualDir.Properties["AuthNTLM"][0] = false;
            virtualDir.Properties["EnableDefaultDoc"][0] = true;
            virtualDir.Properties["DefaultDoc"][0] = defaultDocName;
            virtualDir.Invoke("AppCreate2", new object[] { "2" });
            virtualDir.CommitChanges();