17 Replies Latest reply on Mar 21, 2013 12:47 PM by Oleg Bezyaev

    A "correct" way to detect if SolidWorks is installed...

    Nathan Webers

      Is there a "correct" way to detect (through code) if SolidWorks is installed?

       

      Thanks in advance.

       

      -Nate

        • Re: A "correct" way to detect if SolidWorks is installed...
          Paul Marsman

          you can check to see if the SLDWORKS.exe file exists

          • Re: A "correct" way to detect if SolidWorks is installed...
            Ivana Kolin

            last installed version

             

             Set swApp =  CreateObject("SldWorks.Application")

             or if sw already running

             Set swApp = GetObject(, "SldWorks.Application")   

             

            sw2010

             

             Set swApp =  CreateObject("SldWorks.Application.18")

             or if sw already running

             Set swApp = GetObject(, "SldWorks.Application.18")   

             

            sw2011  = “SldWorks.Application.19” etc.

             

            if swApp is nothing then solidworks is not installed

            • Re: A "correct" way to detect if SolidWorks is installed...
              Frank Lindeman

              Hello Nathan,

               

              The way I recommend is to use the Microsoft Installer Automation API to query the installer's database for the products installed on the machine.
              This would be the programmatic equivalent of looking at “Add/Remove Programs” (Windows XP) or “Programs & Features” (Windows Vista/7/8).

               

              Using the Installer Automation API is less susceptible to files or registry keys that still float around long after a product has been uninstalled.
              And it works for all applications, toolkits, and Windows libraries.

               

              Attached is a VB6 application that illustrates how this can be done.
              When you run "CollectInstalledProducts.exe" it will create a file "InstalledProducts.txt" in the same folder.
              On my machine, which has a few SolidWorks versions installed side-by-side, the file will contain entries like this:

               

              SolidWorks 2010 SP05 [62/96]
                product code     = {AF2066F6-7C57-46A1-A306-077EBBFC7B2B}
                version          = 18.150
                version string   = 18.150.128
                install location = E:\Program Files\SolidWorks 2010SP5\SolidWorks\
                package code     = {6223A986-5E3D-43AB-A529-7551E53704DD}
                product id       = SolidWorks
                publisher        = SolidWorks
                package name     = SolidWorks.msi
                local package    = C:\WINDOWS\Installer\e5caca.msi
                upgrade code     = {D0220929-AF18-11D3-AEA4-00C04F79FCDD}
                platform         = Intel
                product version  = 18.150.128
                title            = SolidWorks 2010 SP5.0
                product icon     = C:\WINDOWS\Installer\{AF2066F6-7C57-46A1-A306-077EBBFC7B2B}\i386_SldWorks.exe
                #patches         = 0

               

              SolidWorks 2012 SP05 [26/96]
                product code     = {FE706200-62BF-4D25-8B34-DC31189DE902}
                version          = 20.150
                version string   = 20.150.80
                install location = C:\Program Files\SolidWorks Corp\SolidWorks 2012SP5\SolidWorks\
                package code     = {74CB1D33-A808-4025-A851-955F382CAD79}
                product id       = SolidWorks
                publisher        = SolidWorks
                package name     = solidworks.msi
                local package    = C:\WINDOWS\Installer\53fe458c.msi
                upgrade code     = {D0220929-AF18-11D3-AEA4-00C04F79FCDD}
                platform         = Intel
                product version  = 20.150.80
                title            = SolidWorks 2012 SP05
                product icon     = C:\WINDOWS\Installer\{FE706200-62BF-4D25-8B34-DC31189DE902}\i386_SldWorks.exe
                #patches         = 0

               

               

              The above examples are for the 32-bit version of SolidWorks 3D CAD. This “family” of SolidWorks versions can be identified by an “UpgradeCode” of {D0220929-AF18-11D3-AEA4-00C04F79FCDD}.
              The 64-bit “family” can be identified by the “UpgradeCode” {08C6EE6B-2F4A-49AF-B1FB-4F60C5C317AF}, like so (taken from a 64-machine):

               

              SolidWorks 2012 x64 Edition SP05 [97/174]
                product code     = {4C66F076-D3AB-49C8-85D4-BAA6D82FCAE2}
                version          = 20.150
                version string   = 20.150.80
                install location = K:\Program Files\SolidWorks Corp\SW2012SP5\SolidWorks\
                package code     = {756D67DF-47B2-4C48-9DB3-F937A6506951}
                product id       = SolidWorks
                publisher        = SolidWorks
                package name     = solidworks.msi
                local package    = C:\Windows\Installer\1078963f.msi
                upgrade code     = {08C6EE6B-2F4A-49AF-B1FB-4F60C5C317AF}
                platform         = AMD64
                product version  = 20.150.80
                title            = SolidWorks 2012 x64 Edition SP05
                product icon     = C:\Windows\Installer\{4C66F076-D3AB-49C8-85D4-BAA6D82FCAE2}\i386_SldWorks.exe
                #patches         = 0

               

               

              For more details on the MSI Automation interface see:

               

                About the Automation Interface (Windows)
                http://msdn.microsoft.com/en-gb/library/windows/desktop/aa367439(v=vs.85).aspx

               

               

              I hope this helps.

               

              Regards,

               

                Frank

               

               

              SolidWorks API, Partner Technical Manager
              Cambridge, UK

                • Re: A "correct" way to detect if SolidWorks is installed...
                  Nathan Webers

                  Mr. Lindman,

                   

                  Will any version of SolidWorks using the upgrade codes ({D0220929-AF18-11D3-AEA4-00C04F79FCDD} and {08C6EE6B-2F4A-49AF-B1FB-4F60C5C317AF}) detect an addin made with the SolidWorks 2012 API, without any additional per-version configuration needed?

                   

                  Thanks,
                  Nate

                    • Re: A "correct" way to detect if SolidWorks is installed...
                      Frank Lindeman

                      Hello Nate,

                       

                      Any SolidWorks 32-bit or 64-bit version will look for registered add-ins in:

                       

                                      HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks\Addins

                       

                      and:

                       

                                      HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks\SolidWorks [VERSION]\Addins

                       

                       

                      On a 64-bit machine any SolidWorks 32-bit version will look for registered add-ins in:

                       

                                      HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SolidWorks\Addins

                       

                                      HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SolidWorks\SolidWorks [VERSION]\AddIns

                       

                      I.e. the 32-bit view on the 64-bit registry.

                       

                       

                      In general loading an add-in developed against a different version of SolidWorks will work.

                      But there are things to bear in mind:

                       

                      • if the add-in is loaded by an older version and you make use of API methods not available in that version, the result may be a catastrophic.
                      • when using C++ as a programming language, Microsoft Foundations Classes (MFC) for the add-in’s User Interface, and linking dynamically against the MFC run-time dlls, you MUST use the exact same VC++ compiler version as SolidWorks. If not, the result may be catastrophic.
                      • users may load your add-in into a SolidWorks version you have not tested with. If things do not work as advertised for whatever reason, it may lead to frustration for the user.

                       

                       

                      If you want to play it safe, there is nothing stopping you to register the same add-in with multiple versions of SolidWorks.

                       

                      Regards,

                       

                        Frank

                       

                      SolidWorks API, Partner Technical Manager
                      Cambridge, UK

                    • Re: A "correct" way to detect if SolidWorks is installed...
                      Nathan Webers

                      Based on Mr. Lindeman's posts, we were able to successfully detect if a SolidWorks installation exists based on the information he provided.  I have marked this thread question as "Answered".

                       

                      -Nate

                    • Re: A "correct" way to detect if SolidWorks is installed...
                      Roland Schwarz

                      Why go to so much trouble?  Who is running your app that doesn't have SW?

                       

                      Usually I just have the code get the SW application object or SWDM, and if there is an error, exit the program.  Let IT worry about bad installs.