Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9219091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:01:23+00:00 2026-06-18T03:01:23+00:00

I have written a custom action in C# to check for the drive existence

  • 0

I have written a custom action in C# to check for the drive existence like below, I got stuck in between.

 [CustomAction]
    public static ActionResult MySimpleAction(Session session)
    {        
        if (Directory.Exists("F:\\"))
        {
            return ActionResult.Success;
        }
        else
        {
            return ActionResult.Failure;
        }
    }

And in wxs file, I am running the custom action as like below.

 <Binary Id="myAction" SourceFile="MyCustomAction.CA.dll" />
 <CustomAction Id="myActionId"
                  BinaryKey="myAction"
                  DllEntry="MySimpleAction"
                  Execute="immediate"
                  Return="check" />

<InstallExecuteSequence>
  <Custom Action="myActionId" After="InstallInitialize"  >  </Custom> 
</InstallExecuteSequence>

If I run the msi in the target machine where I have F:\ drive then installation succeeds, if the target machine doesn’t have F:\ drive then Setup failed, I am getting error as “Setup wizard ended prematurely because of an error. Your system has not been modified.“

What I am trying to do here is, if F:\ drive is available in the target computer (My Custom action succeeds), I want to set my root drive as F:\, and I want to install the application in F:\MyApp\Bin

     <Property Id="ROOTDRIVE"><![CDATA[F:\]]></Property>
     <Directory Id="TARGETDIR" Name="SourceDir">
       <Directory Id="INSTALLFOLDERLOCATION" Name="MyApp">
        <Directory Id="INSTALLLOCATION" Name="Bin">

if F:\ drive is not available in the target computer (My Custom action fails), I want to set my root drive as C:\, and I want to install in C:\MyApp\Bin

     <Property Id="ROOTDRIVE"><![CDATA[C:\]]></Property>
      <Directory Id="TARGETDIR" Name="SourceDir">
       <Directory Id="INSTALLFOLDERLOCATION" Name="MyApp">
        <Directory Id="INSTALLLOCATION" Name="Bin">

How can I set the root drive property by using this custom action?
Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:01:24+00:00Added an answer on June 18, 2026 at 3:01 am

    I thank Christopher Painter and ChrisPatrick for helping me!!! the below code made the trick to work.

     [CustomAction]
        public static ActionResult MySimpleAction(Session session)
        {
            session.Log("DriveInfo Starts");
            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (DriveInfo d in drives)
            {
                if (d.Name.Contains("F") & d.IsReady == true & d.DriveType.ToString() == "Fixed")
                {                   
                  session["TARGETDIR"] = "F:\\";                   
                }
                else
                {
                    session["TARGETDIR"] = "C:\\";
                    session.Log("No F:\\ Drive Found!!!!");                    
                }
            }
            session.Log("DriveInfo Ends");
            return ActionResult.Success;
    

    And in the .wxs file,

      <Binary Id="myAction" SourceFile="MyCustomAction.CA.dll" />
    
       <Directory Id="TARGETDIR" Name="SourceDir">
       <Directory Id="INSTALLFOLDERLOCATION" Name="MyApp">
        <Directory Id="INSTALLLOCATION" Name="Bin">
    
         <CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
    
          <InstallUISequence>
          <Custom Action="myActionId" Before="CostFinalize" > NOT Installed </Custom>      
          </InstallUISequence>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl
I have a custom action dll, written in C++, which is invoked using a
I have a custom handler I've written that executes a custom action based on
I have a Visual Studio setup with a custom action written in C++. I
I have a Spring MVC web application with conroller like below : @Controller public
I have written a custom class to handle database queries to a remote and
I have written a custom class for overriding the seek method of QSlider. Basically
I have written a custom Django Model Field to store dateutil.relativedelta 's. The field
I have written a custom Windows Service that writes data to a custom Event
I have written a custom request handler in solr to meet my business requirements.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.