[英]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 for both 32-bit and 64-bit.Tell me if there are other ways also to check it.我有一个在 32 位和 64 位操作系统上运行的 c# 应用程序。在我的应用程序中,我如何以编程方式检查计算机上是否安装了solidworks。如果我们可以通过读取注册表项来检查它,然后提供我的路径适用于 32 位和 64 位。告诉我是否还有其他方法可以检查它。
You could use WMI as follows 您可以按如下方式使用WMI
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? 如果已安装,应用程序是否需要启动SolidWorks? If so, I start all my Stand-alone (non add-in) SolidWorks tools with
如果是这样,我将启动所有独立(非附加)SolidWorks工具
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. 我认为有很多方法可以检查是否安装了Solidworks,但根据我的观点,安装Solidworks时会在注册时创建一些文件夹。
Just follow this steps to check it... 只需按照以下步骤进行检查......
Open run
打开运行
Typeregedit in that and press
Enter
在其中键入regedit ,然后按
Enter键
Allow 'User access control' by clicking onYes
单击是允许“用户访问控制”
Go under HKEY_LOCAL_MACHINE ->SOFTWARE
转到HKEY_LOCAL_MACHINE - > SOFTWARE下
Now check there Is Solidwork
folder entry is available or not 现在检查是否有可用的
Solidwork
文件夹条目
If folder found solidworks installed otherwise not..! 如果文件夹找到solidworks安装,否则不.. ..!
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.我不确定 macOS 版本的 Solidworks 需要什么,但对于 Windows 这应该是检查是否安装了 Solidworks 的可靠方法。
I suspect this will work with any edition 2010 and beyond as the Solidworks API Help documentation starts there.我怀疑这将适用于任何版本 2010 及更高版本,因为 Solidworks API 帮助文档从那里开始。 I have tested with 2018 and beyond.
我已经在 2018 年及以后进行了测试。
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");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.