Check Solidworks is installed?
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 f开发者_开发技巧or both 32-bit and 64-bit.Tell me if there are other ways also to check it.
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;
}
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
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 !
I am not sure what would be required for the macOS versions of Solidworks, but for Windows this should be a reliable way to check if Solidworks is installed.
I suspect this will work with any edition 2010 and beyond as the Solidworks API Help documentation starts there. I have tested with 2018 and beyond.
using Microsoft.Win32;
using System.Runtime.InteropServices;
/// <summary>
/// Checks that Solidworks has the minimum required version installed
/// </summary>
/// <param name="requiredVersion ">The minimum year of Solidworks required</param>
/// <exception cref="PlatformNotSupportedException"></exception>
public static bool CheckSolidworks(int requiredVersion = 2_021)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var keyname = "SolidWorks";
var registryKey = Registry.LocalMachine.OpenSubKey($"SOFTWARE\\{keyname}")
?? Registry.CurrentUser.OpenSubKey($"Software\\{keyname}");
if (registryKey == null)
return false;
var matches = registryKey.GetSubKeyNames()?.Where(x => x.StartsWith("SOLIDWORKS"));
if (matches == null)
return false;
int? installedVersion = null;
foreach (var match in matches)
if (int.TryParse(match[^4..], out int version) && (installedVersion == null || version > installedVersion))
installedVersion = version;
return installedVersion != null && installedVersion >= requiredVersion;
}
else
{
throw new PlatformNotSupportedException("Method only supported on Windows");
}
}
精彩评论