1

I have a c# application. I need to copy my database file from the CD to a destination folder and then use it for login and other purposes. For this I have written an installer class as follows.

public partial class Installer1 : Installer
{
    public Installer1()
    {
        InitializeComponent();
        Copy_our_Files();
    }

    private void Copy_our_Files()
    {  
        System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
        var d = "";

        foreach (System.IO.DriveInfo drive in drives)
        {
            if (drive.DriveType == System.IO.DriveType.CDRom)
            {
                d = drive.Name;
                break;
            }
        }

        string addre = @"C:\Windows\\System32";
        System.IO.File.Copy(d + @"Database5.accdb", addre + "\\Database5.accdb");
    }
}  

But during installation of my application the database file is not copied to the location mentioned which is c:\Windwos\System32 folder.

5
  • Do you get any errors? There are also a number of assumptions/issues this code makes/has... Commented Oct 2, 2013 at 14:33
  • the error i am getting is 'unable to create an instance of project1.installer1 installer type-Exception has been thrown by the target of an invocation--this device is not ready' Commented Oct 2, 2013 at 14:40
  • Does it end up in C:\Windows\SysWow64 instead? Why are you putting anything in the system directories anyway? Commented Oct 2, 2013 at 14:40
  • The reason am doing so is...i need to install the aplication on any remote computer. So it may be 64 bit or 32 bit...i need a folder which is always present in any computer which is system32 Commented Oct 2, 2013 at 14:41
  • Before trying to copy why not see if you can create a file in a more friendly zone like the C: drive and work backwards from there. Commented Oct 2, 2013 at 15:03

2 Answers 2

4

You need to do this in your installer. You said you are installing your application file. That instance of whatever installer software you are using has to copy that database file. Copying an additional file should be trivial to implement in your installation software.

Your current hack is very flaky and will fail in many real world scenarios:

  • What if I don't have a CD ROM drive? It's impossible to install from USB stick or my colleagues computers CR ROM drive.

  • What if I have more than one CD ROM drive?

  • What if I don't have my Windows installed in C:\Windows ?

  • What if I don't have write persissions to my System32 directory ? Why would you even want to write there?

Conclusion: Your problem has already been solved by installer software. You are already "installing" so I assume you are already using an installer software. Let it do what it was build for and don't try to imitate it on your own.

Sign up to request clarification or add additional context in comments.

Comments

0

Whats possibly happening is its failing but installers arent overtly clear about why theyve failed.

Check the eventlog for exceptions. Failing this you will need to assert your way to uncovering the answer.

Use the EventLog object to write out the progress etc is d + @"Database5.accdb" a valid path.

I would also recommend using one of the overrides etc or one thats appropriate to your needs. I cant say at what point the installer is after InitializeComponent.

protected override void OnCommitted(IDictionary savedState)
{     
      //Your code
      base.OnCommitted(savedState)
}

2 Comments

the error i am getting is 'unable to create an instance of project1.installer1 installer type-Exception has been thrown by the target of an invocation--this device is not ready'
Check to see whether you can diagnose the issue in steps. Check to see whether it enters Copy_our_Files. Check to see whether target and source exist. The exception sounds like CD rom isnt available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.