×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VB code to tell if SolidWorks is installed on a computer

VB code to tell if SolidWorks is installed on a computer

VB code to tell if SolidWorks is installed on a computer

(OP)
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

RE: VB code to tell if SolidWorks is installed on a computer

One way would be to check the registry.  Some ideas:
  • Check to see if certain SW DLL's are registered
  • Check if ANY SolidWorks keys are in registry
  • Check registry to find where main SW executable is, then verify that the file exists
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.

batI could be the world's greatest underachiever, if I could just learn to apply myself.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: VB code to tell if SolidWorks is installed on a computer

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

RE: VB code to tell if SolidWorks is installed on a computer

(OP)
Thank you Ken!  That's exactly what I was after.  Star for you.

Best regards,

Chris Gervais
Application Engineer
CSWP, CSWST

RE: VB code to tell if SolidWorks is installed on a computer

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources