Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Installing a C# application programmatically …

Installing a C# application programmatically …

Scheduled Pinned Locked Moved C#
csharpvisual-studiohelptutoriallearning
15 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Xaverian

    Thanks - But I don't understand what you just said ... :sigh:

    N Offline
    N Offline
    Nader Elshehabi
    wrote on last edited by
    #4

    Well, to install anything you program got two choices: 1- Make a deployment project -from the new projects window-, there you can specify what to install from your screensaver project, and to check/install DotNet framework. 2- Write the code to copy your files yourself. If you choose this hard way -that's what I thought of when you said programatically-, you need to call the DotNet installer. Something like this:

    Process.Start("Setup.exe", "/q");

    This way the DotNet framework setup will try to install itself without showing any screens. Of course if you want to copy your exe file to the hard desk you can simply use

    File.Copy("MyOldPath.exe", "MyNewPath.exe", true);

    Sure the second way is much harder, but some people got reasons to use it. If you just want to install your project and the DotNet framework -if needed-, follow these steps: 1- File => New => Project 2- Other Project types => Setup and Deployment => Setup Project 3- Right click on the setup project's name => Properties 4- Prerequisite button => Check ".Net Framework 2.0" and "Microsoft installer 3.1" from the list and check on "Download prerequisites from the same location as my application" radiobutton. 5- Right click on the setup project's name again => Add => Project output => Choose your screensaver project and click OK. I hope it was clear this time.

    Regards:rose:

    X 2 Replies Last reply
    0
    • N Nader Elshehabi

      Well, to install anything you program got two choices: 1- Make a deployment project -from the new projects window-, there you can specify what to install from your screensaver project, and to check/install DotNet framework. 2- Write the code to copy your files yourself. If you choose this hard way -that's what I thought of when you said programatically-, you need to call the DotNet installer. Something like this:

      Process.Start("Setup.exe", "/q");

      This way the DotNet framework setup will try to install itself without showing any screens. Of course if you want to copy your exe file to the hard desk you can simply use

      File.Copy("MyOldPath.exe", "MyNewPath.exe", true);

      Sure the second way is much harder, but some people got reasons to use it. If you just want to install your project and the DotNet framework -if needed-, follow these steps: 1- File => New => Project 2- Other Project types => Setup and Deployment => Setup Project 3- Right click on the setup project's name => Properties 4- Prerequisite button => Check ".Net Framework 2.0" and "Microsoft installer 3.1" from the list and check on "Download prerequisites from the same location as my application" radiobutton. 5- Right click on the setup project's name again => Add => Project output => Choose your screensaver project and click OK. I hope it was clear this time.

      Regards:rose:

      X Offline
      X Offline
      Xaverian
      wrote on last edited by
      #5

      I followed your instructions all the way to #5 ... [QUOTE]Right click on the setup project's name again => Add => Project output => Choose your screensaver project and click OK[/QUOTE], when I get to this point, there are two empty dropdown boxes with no way to navigate to my project so I can add it as project output. I was also trying to use the "ClickOnce" deployment method as I have space on a server here at school to use, thought that might be easy for them to use to install and run the app, however when trying to use that method the "ClickOnce" won't grab the .scr and install it as a screen saver only in the Start > Programs > etc. etc. and you have to manually click on it to run. Doh! Any method is fine to use as long as I make it simple for them ... another question that pops up then, if using the method you described with making a new "Setup Project", when this installs, will it install it directly as a screen saver? and how would it do that, or do I have to provide more code somewhere to make it perform that action? I hope this was all clear ... Xaverain

      N 1 Reply Last reply
      0
      • X Xaverian

        I followed your instructions all the way to #5 ... [QUOTE]Right click on the setup project's name again => Add => Project output => Choose your screensaver project and click OK[/QUOTE], when I get to this point, there are two empty dropdown boxes with no way to navigate to my project so I can add it as project output. I was also trying to use the "ClickOnce" deployment method as I have space on a server here at school to use, thought that might be easy for them to use to install and run the app, however when trying to use that method the "ClickOnce" won't grab the .scr and install it as a screen saver only in the Start > Programs > etc. etc. and you have to manually click on it to run. Doh! Any method is fine to use as long as I make it simple for them ... another question that pops up then, if using the method you described with making a new "Setup Project", when this installs, will it install it directly as a screen saver? and how would it do that, or do I have to provide more code somewhere to make it perform that action? I hope this was all clear ... Xaverain

        N Offline
        N Offline
        Nader Elshehabi
        wrote on last edited by
        #6

        The last step didn't work because you crated the new project in a new solution:doh:. In the new project dialog you should have chosen "Add to solution" in the ComboBox to the bottom of the dialog box. About installing your Screensaver, follow these steps in your new setup project -in a new solution like you did-: 1- Open "My Computer" => Go to your Screensaver's output folder => Copy the exe to your new setup project's folder and rename it to "MyFile.scr" instead of "MyFile.exe" 2- Back to Visual Studio => Right click on the setup project's name => View => File system 3- Right click on "File system on target machine" => Special Folder => Windows folder. 4- Right click on the new folder => Add => File => Browse to your scr file. 5- Do the prerequisite as mentioned before. This should do it, but you got to read more about setup and deployment. I always suggest searching the articles. I hope it works for you this time.

        Regards:rose:

        1 Reply Last reply
        0
        • N Nader Elshehabi

          Well, to install anything you program got two choices: 1- Make a deployment project -from the new projects window-, there you can specify what to install from your screensaver project, and to check/install DotNet framework. 2- Write the code to copy your files yourself. If you choose this hard way -that's what I thought of when you said programatically-, you need to call the DotNet installer. Something like this:

          Process.Start("Setup.exe", "/q");

          This way the DotNet framework setup will try to install itself without showing any screens. Of course if you want to copy your exe file to the hard desk you can simply use

          File.Copy("MyOldPath.exe", "MyNewPath.exe", true);

          Sure the second way is much harder, but some people got reasons to use it. If you just want to install your project and the DotNet framework -if needed-, follow these steps: 1- File => New => Project 2- Other Project types => Setup and Deployment => Setup Project 3- Right click on the setup project's name => Properties 4- Prerequisite button => Check ".Net Framework 2.0" and "Microsoft installer 3.1" from the list and check on "Download prerequisites from the same location as my application" radiobutton. 5- Right click on the setup project's name again => Add => Project output => Choose your screensaver project and click OK. I hope it was clear this time.

          Regards:rose:

          X Offline
          X Offline
          Xaverian
          wrote on last edited by
          #7

          If I use the "Download prerequisites from the same location as my application" and place everything on a CD for them, where do I place the prerequisites or how do I include them with the setup project?

          N 1 Reply Last reply
          0
          • X Xaverian

            If I use the "Download prerequisites from the same location as my application" and place everything on a CD for them, where do I place the prerequisites or how do I include them with the setup project?

            N Offline
            N Offline
            Nader Elshehabi
            wrote on last edited by
            #8

            First: Did you follow the second set of instrucstions successfully? Second: The entire output of your setup project is placed in a folder named debug or release -accodring to your configuration-. In that folder you should see subfolders containing each of your prerequisites. Just copy all the contents of the debug/release folder to your CD, and on the user's machine tell them to click on the Setup.exe file. PS. Of course you should test it on your machine first, Don't you think? Also don't forget to uninstall the screensaver from your machine after the test.

            Regards:rose:

            X 1 Reply Last reply
            0
            • N Nader Elshehabi

              First: Did you follow the second set of instrucstions successfully? Second: The entire output of your setup project is placed in a folder named debug or release -accodring to your configuration-. In that folder you should see subfolders containing each of your prerequisites. Just copy all the contents of the debug/release folder to your CD, and on the user's machine tell them to click on the Setup.exe file. PS. Of course you should test it on your machine first, Don't you think? Also don't forget to uninstall the screensaver from your machine after the test.

              Regards:rose:

              X Offline
              X Offline
              Xaverian
              wrote on last edited by
              #9

              I did follow the instructions, and I found everything in the DeBug folder as you suggested ... that is slick! I tested it and uninstalled it ... that worked too, BUT ... How do I make the screen saver being installed the default screen saver without making my relatives right click on the desktop, select properties, then screen saver, etc ... Isn't there a way to do that for them? On a side note, I am going to do some additional reading on creating "Setup Projects" after all this. Do you know of any good books, with examples? Perhaps an article on deploying the Screen Saver kit should be written for CodeProject, for both the CD option and using the ClickOnce stuff too. Anyways, thanks for the help thusfar, I appreciate it, just one more step to go! I await your answer :)

              N 1 Reply Last reply
              0
              • X Xaverian

                I did follow the instructions, and I found everything in the DeBug folder as you suggested ... that is slick! I tested it and uninstalled it ... that worked too, BUT ... How do I make the screen saver being installed the default screen saver without making my relatives right click on the desktop, select properties, then screen saver, etc ... Isn't there a way to do that for them? On a side note, I am going to do some additional reading on creating "Setup Projects" after all this. Do you know of any good books, with examples? Perhaps an article on deploying the Screen Saver kit should be written for CodeProject, for both the CD option and using the ClickOnce stuff too. Anyways, thanks for the help thusfar, I appreciate it, just one more step to go! I await your answer :)

                N Offline
                N Offline
                Nader Elshehabi
                wrote on last edited by
                #10

                Alright. I'm going with you to the end. There is a registry key in windows that you got to change. The key is "HKEY_CURRENT_USER\Control Panel\Desktop". Inside it there is a value called "SCRNSAVE.EXE". If this value doesn't exist you should create it, if it does you should give it the value "C:\windows\MyFile.scr". To do that while you install your program you have to do a custom action that is done while installing the software. 1- Create the setup project in the same solution as your screen saver solution 2- Add the primary output of your screensaver project to the windows folder you create in the file system panel 3- Right click on the setup project's name => view => custom actions 4- Add a new custom action and choose the primary output of your screensaver project 5- In the screensaver project add a new item => installer class 6- In the Installer1.cs overide the Install() method. 7- In that method alter the above mentioned registry key 8- Don't hardcode the text "C:\windows" as the path. Rather use

                Directory.GetParent(Environment.SpecialFolder.System);

                Maybe they installed windows in another partition than C. PS. I've discovered a much easier way to install your screensaver. Just give your relatives the scr file and tell them to Right click on it => Install. This will directly install it and set it as the default screen saver. Also tell them not to delete the scr file BTW, as it's not copied to the windows directory.

                Regards:rose:

                X 2 Replies Last reply
                0
                • N Nader Elshehabi

                  Alright. I'm going with you to the end. There is a registry key in windows that you got to change. The key is "HKEY_CURRENT_USER\Control Panel\Desktop". Inside it there is a value called "SCRNSAVE.EXE". If this value doesn't exist you should create it, if it does you should give it the value "C:\windows\MyFile.scr". To do that while you install your program you have to do a custom action that is done while installing the software. 1- Create the setup project in the same solution as your screen saver solution 2- Add the primary output of your screensaver project to the windows folder you create in the file system panel 3- Right click on the setup project's name => view => custom actions 4- Add a new custom action and choose the primary output of your screensaver project 5- In the screensaver project add a new item => installer class 6- In the Installer1.cs overide the Install() method. 7- In that method alter the above mentioned registry key 8- Don't hardcode the text "C:\windows" as the path. Rather use

                  Directory.GetParent(Environment.SpecialFolder.System);

                  Maybe they installed windows in another partition than C. PS. I've discovered a much easier way to install your screensaver. Just give your relatives the scr file and tell them to Right click on it => Install. This will directly install it and set it as the default screen saver. Also tell them not to delete the scr file BTW, as it's not copied to the windows directory.

                  Regards:rose:

                  X Offline
                  X Offline
                  Xaverian
                  wrote on last edited by
                  #11

                  I got as far as Step #4 When I view the custom actions, there are four folders there; Install, Commit, Rollback, and Uninstall as well as the top node "Custom Actions". Right clicking on anyone of those items brings up a box and I have four additional folders to choose from, I have to select one of the folders in order to enable the "add output" button ... Question, which folder do I select in the pop-up box, and wich node while viewing the custom actions do I select or do I select the top node "Custom Actions"? I think I going to create an article for others after all this ... LOL

                  N 1 Reply Last reply
                  0
                  • X Xaverian

                    I got as far as Step #4 When I view the custom actions, there are four folders there; Install, Commit, Rollback, and Uninstall as well as the top node "Custom Actions". Right clicking on anyone of those items brings up a box and I have four additional folders to choose from, I have to select one of the folders in order to enable the "add output" button ... Question, which folder do I select in the pop-up box, and wich node while viewing the custom actions do I select or do I select the top node "Custom Actions"? I think I going to create an article for others after all this ... LOL

                    N Offline
                    N Offline
                    Nader Elshehabi
                    wrote on last edited by
                    #12

                    Actually you should right click on any node => Add custom action. Then follow the rest of the steps.

                    Regards:rose:

                    1 Reply Last reply
                    0
                    • N Nader Elshehabi

                      Alright. I'm going with you to the end. There is a registry key in windows that you got to change. The key is "HKEY_CURRENT_USER\Control Panel\Desktop". Inside it there is a value called "SCRNSAVE.EXE". If this value doesn't exist you should create it, if it does you should give it the value "C:\windows\MyFile.scr". To do that while you install your program you have to do a custom action that is done while installing the software. 1- Create the setup project in the same solution as your screen saver solution 2- Add the primary output of your screensaver project to the windows folder you create in the file system panel 3- Right click on the setup project's name => view => custom actions 4- Add a new custom action and choose the primary output of your screensaver project 5- In the screensaver project add a new item => installer class 6- In the Installer1.cs overide the Install() method. 7- In that method alter the above mentioned registry key 8- Don't hardcode the text "C:\windows" as the path. Rather use

                      Directory.GetParent(Environment.SpecialFolder.System);

                      Maybe they installed windows in another partition than C. PS. I've discovered a much easier way to install your screensaver. Just give your relatives the scr file and tell them to Right click on it => Install. This will directly install it and set it as the default screen saver. Also tell them not to delete the scr file BTW, as it's not copied to the windows directory.

                      Regards:rose:

                      X Offline
                      X Offline
                      Xaverian
                      wrote on last edited by
                      #13

                      Ive created the Install() file and I must have missed something, here is my code ...

                      namespace ScreenSaver1
                      {
                      [RunInstaller(true)]
                      class Installer1 : Installer
                      {
                      const string _screenSaverValue = "SCRNSAVE.EXE";

                          public Installer1()
                          {
                              //Default constructor
                          }
                          
                          //override the Install method ...
                          public override void Install(System.Collections.IDictionary stateSaver) 
                          {
                              base.Install(stateSaver);
                             
                              RegistryKey theRootKey = Registry.CurrentUser;
                              RegistryKey theControlPanel = theRootKey.OpenSubKey("Control Panel");
                              RegistryKey theDeskTopKey = theControlPanel.OpenSubKey("Desktop");
                      
                              if (theDeskTopKey.GetValue(\_screenSaverValue) == null)
                              {
                                  //Add some values
                                  string valName = \_screenSaverValue;
                                  object testValue = Directory.GetParent(Environment.SpecialFolder.System.ToString()) + "ScreenSaver1.scr";
                                  RegistryValueKind valKind = RegistryValueKind.String;
                      
                                  theRootKey.SetValue(valName, testValue, valKind);
                              }
                              
                          }
                      
                      }
                      

                      }

                      Everything else works fine, just not setting the registry value ...

                      N 1 Reply Last reply
                      0
                      • X Xaverian

                        Ive created the Install() file and I must have missed something, here is my code ...

                        namespace ScreenSaver1
                        {
                        [RunInstaller(true)]
                        class Installer1 : Installer
                        {
                        const string _screenSaverValue = "SCRNSAVE.EXE";

                            public Installer1()
                            {
                                //Default constructor
                            }
                            
                            //override the Install method ...
                            public override void Install(System.Collections.IDictionary stateSaver) 
                            {
                                base.Install(stateSaver);
                               
                                RegistryKey theRootKey = Registry.CurrentUser;
                                RegistryKey theControlPanel = theRootKey.OpenSubKey("Control Panel");
                                RegistryKey theDeskTopKey = theControlPanel.OpenSubKey("Desktop");
                        
                                if (theDeskTopKey.GetValue(\_screenSaverValue) == null)
                                {
                                    //Add some values
                                    string valName = \_screenSaverValue;
                                    object testValue = Directory.GetParent(Environment.SpecialFolder.System.ToString()) + "ScreenSaver1.scr";
                                    RegistryValueKind valKind = RegistryValueKind.String;
                        
                                    theRootKey.SetValue(valName, testValue, valKind);
                                }
                                
                            }
                        
                        }
                        

                        }

                        Everything else works fine, just not setting the registry value ...

                        N Offline
                        N Offline
                        Nader Elshehabi
                        wrote on last edited by
                        #14

                        It's one simple mistake -you can post it in the subtle bugs forum BTW:)-. You've written

                        theRootKey.SetValue(valName, testValue, valKind);

                        ... while it should have been

                        theDeskTopKey.SetValue(valName, testValue, valKind);

                        as the value is under the "HKEY_CURRENT_USER\Control Panel\Desktop" key not the "Current User" root key. I hope it works. PS. the line

                        if (theDeskTopKey.GetValue(_screenSaverValue) == null)

                        tests only if the user doesn't have any screen saver chosen. If they have another screen saver chosen this value will not be null. Rather it will be the path to the other screen saver. You should always SetValue() even if it wasn't null.

                        Regards:rose:

                        X 1 Reply Last reply
                        0
                        • N Nader Elshehabi

                          It's one simple mistake -you can post it in the subtle bugs forum BTW:)-. You've written

                          theRootKey.SetValue(valName, testValue, valKind);

                          ... while it should have been

                          theDeskTopKey.SetValue(valName, testValue, valKind);

                          as the value is under the "HKEY_CURRENT_USER\Control Panel\Desktop" key not the "Current User" root key. I hope it works. PS. the line

                          if (theDeskTopKey.GetValue(_screenSaverValue) == null)

                          tests only if the user doesn't have any screen saver chosen. If they have another screen saver chosen this value will not be null. Rather it will be the path to the other screen saver. You should always SetValue() even if it wasn't null.

                          Regards:rose:

                          X Offline
                          X Offline
                          Xaverian
                          wrote on last edited by
                          #15

                          I've made the changes and still I have nothing ... it won't create the value within the Key ... everything else works though. To bad I can't just send you the entire project to look at ... Thanks for all your help, you've definately went further to help me than I ever anticipated. I really appreciate your help! I've learned several things from this, thus far ... :) Xaverian

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups