6

I have a c# application that runs on both 32-bit and 64-bit OS.In my app, how can I programatically check that solidworks is installed or not on computer.If we can check it by reading registry key ,then provide me path for both 32-bit and 64-bit.Tell me if there are other ways also to check it.

user369182
  • 1,807
  • 4
  • 15
  • 16

3 Answers3

5

You could use WMI as follows

private static bool IsInstalled(string ProductName)
{

    bool rv = false;
    ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
    ManagementObjectCollection Products = searcher.Get();
    if (Products.Count != 0)
    {
        foreach (ManagementObject product in Products)
        {
            if (product.Properties["Name"].Value.ToString() == ProductName)
            {
                rv = true;
            }
        }
    }
    return rv;           
}
Charles Gargent
  • 1,767
  • 2
  • 13
  • 19
  • 1
    I would throw 'using' statements around the ManagementObjectSearcher and ManagementObjectCollection to make sure they are disposed of properly. – SwDevMan81 May 24 '10 at 11:42
  • You can break the `foreach` loop when product is founded by replacing `rv = true` by `return true` (`rv` declaration becomes unnecessary) – alex Feb 27 '16 at 15:36
2

Does the application need to start SolidWorks if it's installed? If so, I start all my Stand-alone (non add-in) SolidWorks tools with

Public swApp As SldWorks.SldWorks

Function GetSolidWorks(ForceLaunch As Boolean) As Boolean
    If Not swApp Is Nothing Then
        SetSolidWorksVisibility()
        Return True
    Else
        Try
            swApp = GetObject(, "SldWorks.Application")
            If swApp Is Nothing Then Return False

            SetSolidWorksVisibility()
            Return True
        Catch ex As Exception
            If Not ForceLaunch Then Return False

            swApp = CreateObject("SldWorks.Application")
            If swApp Is Nothing Then Return False

            SetSolidWorksVisibility()

            'simple timer to wait for solidworks to repond
            System.Threading.Thread.Sleep(5000)

            Return True
        End Try
    End If
End Function

Private Sub SetSolidWorksVisibility()
    If Not swApp.Visible Then swApp.Visible = True
    If Not swApp.FrameState = SwConst.swWindowState_e.swWindowMaximized Then swApp.FrameState = SwConst.swWindowState_e.swWindowMaximized
End Sub
Jeremy
  • 385
  • 1
  • 11
0



This is for beginers....
I think there are many ways to check Whether Solidworks is installed or not , but according to my perspective when Solidworks is installed it creates some folders in registery.

Just follow this steps to check it...

Open run
Type regedit in that and press Enter
Allow 'User access control' by clicking on Yes
Go under HKEY_LOCAL_MACHINE -> SOFTWARE

Now check there Is Solidwork folder entry is available or not
If folder found solidworks installed otherwise not..!

hope this will help !

StepUp
  • 27,357
  • 12
  • 66
  • 120
Yogesh Gat
  • 21
  • 2