Ask a questionAsk a question
 

General DiscussionBrowseDialog en DirectoryEntry

  • Friday, August 29, 2008 9:58 AMPhilip Wagenaar - Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I have created a MSI setup for a webapplication which works just fine on my Windows 2003 32 bits test server. One of our customers uses the 64 bits version and not everything seems to work as expected.

    We were able to reproduce the following two issues on two diffrent 64 bits systems both running Windows 2003 64 bits version.

    1) BrowseDialog with 'Create new folder' button enabled does not show the new folder through interface

    We have addded a custom GUI to our installer that lets the user select the target folder. We use the following code for this:
    private void Browse_Click(object sender, EventArgs e)  
            {  
                  
                m_sSelectedPath = "";  
                Thread thread = new Thread(new ThreadStart(BrowseDialog));  
                thread.SetApartmentState(ApartmentState.STA);  
                thread.Start();  
                thread.Join();  
                if (m_sSelectedPath != "") TargetDir.Text = m_sSelectedPath;  
            }  
     
            private void BrowseDialog()  
            {  
                using (FolderBrowserDialog dlg = new FolderBrowserDialog())  
                {  
                    dlg.SelectedPath = null;  
                    dlg.RootFolder = Environment.SpecialFolder.Desktop;  
                    dlg.ShowNewFolderButton = true;  
                    if (dlg.ShowDialog() == DialogResult.OK)  
                    {  
                        m_sSelectedPath = dlg.SelectedPath;  
                    }  
                }  
            }  
     
    When we click on the New folder button nothing seems to happen. However when we take a look using Windows Explorer we do see that the new folder was created. On my 32-bits test server we do see the new folder in browserdialog GUI and are able to to give it a name, as expected. So what is going on here?

    2) Network service is not given write permissions on folder when creating a new Virtual Directory using DirectoryEntry object.
    Let' start with the code:
    string sWebSite = (string)m_oHash[WebSiteList.SelectedItem.ToString()];  
                    DirectoryEntry oWebSite = new DirectoryEntry(sWebSite);  
                    if (VirtualDir.Text == "") SetProperties(oWebSite, TargetDir.Text, AppName.Text);  
                    else  
                    {  
                        if (DirectoryEntry.Exists(sWebSite + "/" + VirtualDir.Text))  
                        {  
                            DirectoryEntry oVirDir = new DirectoryEntry(sWebSite + "/" + VirtualDir.Text);  
                            oWebSite.Children.Remove(oVirDir);  
                            oWebSite.CommitChanges();  
                        }  
                        DirectoryEntry oNew = oWebSite.Children.Add(VirtualDir.Text, "IIsWebVirtualDir");  
                        oNew.Invoke("AppCreate", true);  
                        SetProperties(oNew, TargetDir.Text, AppName.Text);  
                        if (Directory.Exists(TargetDir.Text + "\\bin"))  
                        {  
                            DirectoryEntry oBin = oNew.Children.Add("bin", "IIsWebDirectory");  
                            oBin.Properties["AccessFlags"][0] = 0;  
                            oBin.Properties["EnableDirBrowsing"][0] = false;  
                            oBin.CommitChanges();  
                        }  
                    } 
    The method SetProperties sets the properies for the new virtual directory:
    private void SetProperties(DirectoryEntry oEntry, string sTargetDir, string sAppName)  
            {  
                oEntry.Properties["AppFriendlyName"].Value = sAppName;  
                oEntry.Properties["Path"].Value = sTargetDir;  
                oEntry.Properties["AppIsolated"].Value = m_nAppIsolated;  
                oEntry.Properties["AspAllowSessionState"].Value = m_bAllowSessionState;  
                oEntry.Properties["AspBufferingOn"].Value = m_bBufferingOn;  
                oEntry.Properties["AspEnableParentPaths"].Value = m_bEnableParentPaths;  
                oEntry.Properties["AspScriptErrorSentToBrowser"].Value = m_bScriptErrorSentToBrowser;  
                oEntry.Properties["AspScriptTimeout"].Value = m_nScriptTimeout;  
                oEntry.Properties["AccessExecute"][0] = m_bExecute;  
                oEntry.Properties["AccessRead"][0] = m_bRead;  
                oEntry.Properties["AccessScript"][0] = m_bScript;  
                oEntry.Properties["AccessSource"][0] = m_bSource;  
                oEntry.Properties["AccessWrite"][0] = m_bWrite;  
                oEntry.Properties["AuthAnonymous"][0] = m_bAuthAnonymous;  
                oEntry.Properties["AuthBasic"][0] = m_bAuthBasic;  
                oEntry.Properties["AuthNTLM"][0] = m_bAuthNTLM;  
                oEntry.Properties["ContentIndexed"].Value = m_bContentIndexed;  
                oEntry.Properties["EnableDefaultDoc"][0] = (m_sDefaultDoc!="");  
                oEntry.Properties["DefaultDoc"].Value = m_sDefaultDoc;  
                oEntry.Properties["DontLog"][0] = m_bDontLog;  
                oEntry.Properties["EnableDirBrowsing"][0] = m_bEnableBrowsing;  
                oEntry.CommitChanges();  
            } 
    These are the properties I have set:
      public static bool m_bExecute = Convert.ToBoolean(GetDeploySetting("PermissionExecute", "false"));  
            public static bool m_bRead = Convert.ToBoolean(GetDeploySetting("PermissionRead", "true"));  
            public static bool m_bScript = Convert.ToBoolean(GetDeploySetting("PermissionScript", "true"));  
            public static bool m_bSource = Convert.ToBoolean(GetDeploySetting("PermissionSource", "false"));  
            public static bool m_bWrite = Convert.ToBoolean(GetDeploySetting("PermissionWrite", "true")); 
    The default values are used, so m_bWrite has the value 'true'.

    All works fine again on 32 bits version of Windows 2003 server. The network service has write permissions on the folder and the Virtual Directory properties also shows that Write is enabled.
    However on the 64 bits version of Windows 2003 we see that Write is enabled when checking the Virtual Directory properties, but the Network Service does not have write permissions when I check the folder security tab.

    Again, whats going on here?

All Replies

  • Friday, August 29, 2008 10:43 AMnobugzMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    1) violates the COM requirements for an STA thread, it must pump a message loop.
    2) is off topic here, post to forums.iis.net

    Hans Passant.
  • Friday, August 29, 2008 11:29 AMPhilip Wagenaar - Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    1) Not sure what you mean. But it does work in my 32  bits Windows XP machine.
    2) I`ll post it there, thanks
  • Friday, August 29, 2008 11:38 AMnobugzMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Intentionally violating COM requirements buys you undefined behavior.  I always liked XP, you can do a lot of violatin' before it gives up on you.  A class act that was obviously hard to follow.  Stay out of trouble and display the dialog on your UI thread.
    Hans Passant.
  • Wednesday, September 03, 2008 11:30 AMPhilip Wagenaar - Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    If use do not use the thread the dialog is shown with only the buttons, the area where I normally would see the folders is just all grey/black.