Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-04-27
3
Medium Priority
?
1,842 Views
Last Modified: 2012-05-05
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!
0
Comment
Question by:i-mate05
3 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 16560208

Hi,

It's an attribute called AccessFlags you need to alter. It has a number of values available. Please forgive any basic mistakes in the code, I never learnt anything but VbScript. There are a number of constants that go with it to build up to the value you end up writing:

Const MD_ACCESS_EXECUTE = 4
Const MD_ACCESS_SOURCE = 16
Const MD_ACCESS_READ = 1
Const MD_ACCESS_WRITE = 2
Const MD_ACCESS_SCRIPT = 512
Const MD_ACCESS_NO_REMOTE_EXECUTE = 8192
Const MD_ACCESS_NO_REMOTE_READ = 4096
Const MD_ACCESS_NO_REMOTE_WRITE = 1024
Const MD_ACCESS_NO_REMOTE_SCRIPT = 16384

The most likely setting here is going to be Read and Script:

virtualDir.Properties["accessFlags"][0] = MD_ACCESS_READ + MD_ACCESS_SCRIPT

In VbScipt it would be:

Set objVirtualDirectory = GetObject("IIS://Server/W3SVC/<SiteID>/ROOT")

objVirtualDirectory.Put "accessFlags", MD_ACCESS_READ + MD_ACCESS_SCRIPT
objVirtualDirectory.SetInfo

HTH

Chris
0
 

Author Comment

by:i-mate05
ID: 16565315
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!
0
 
LVL 1

Expert Comment

by:kstorey
ID: 20174795
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();
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is an ISAPI filter?   •      It's an assembly (.dll file) that can add or change the way IIS works.   •      They can be enabled globally for your web server or on a site-by-site basis.   When the IIS server receives a request, enabling the ISAPI fi…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question