Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB code to tell if SolidWorks is installed on a computer 1

Status
Not open for further replies.

RawheadRex

Mechanical
Feb 9, 2001
236
Hey Folks,

Just a real quick one here. I'm just finishing off an app for a customer and realized that I forgot to do one bit of checking at startup. That being - is SW actually installed (a pre-requisite)?

Anyhow I am just wondering if anyone has a couple lines of code to share w/ me (and the rest of the board) that accomplishes this. I suppose I could just run a search for "sldworks.exe" on the drive(s) but that just seems a bit inelegant. Better than just letting the app crash but I'm hoping there's something that's a step up from that.

SW2007, VB.Net 2005

Thanks,


Chris Gervais
Application Engineer
CSWP, CSWST
 
Replies continue below

Recommended for you

One way would be to check the registry. Some ideas:
[ul][li]Check to see if certain SW DLL's are registered[/li]
[li]Check if ANY SolidWorks keys are in registry[/li]
[li]Check registry to find where main SW executable is, then verify that the file exists[/li][/ul]

Otherwise, try starting SW, then see if you object containing the SW app is "Nothing" or not.

I have some VB6 registry tools available on my website. Since you are working in VB.NET, I don't know if they will be much use.

[bat]I could be the world's greatest underachiever, if I could just learn to apply myself.[bat]
-SolidWorks API VB programming help
 
Assuming you're ok with actually starting SolidWorks...
Code:
    On Error Resume Next

    'If SolidWorks is Currently Open Object will get initialized.
    Set swApp = getObject(, "SldWorks.Application")

    'If SolidWorks not open then error occured
    If (Err.Number <> 0) Then
        Err.Clear

        'If SolidWorks is installed on machine it will start.
        Set swApp = CreateObject("SldWorks.Application")

        'If SolidWorks not installed on machine then error occured
        If (Err.Number <> 0) Then
            Err.Clear
            MsgBox "SolidWorks not installed on this machine. Routine ending.", vbCritical, "Missing SolidWorks Application"
        End If
    End If
    On Error GoTo 0

Enjoy,
Ken
 
Thank you Ken! That's exactly what I was after. Star for you.

Best regards,


Chris Gervais
Application Engineer
CSWP, CSWST
 
You probably figured it out, but just in case anyone else references this...I forgot to add the End statement in the row after the Msgbox telling you that the routine was going to end.

Enjoy,
Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor