检查 Solidworks 是否已安装?

发布于 2024-09-02 11:38:24 字数 133 浏览 7 评论 0原文

我有在 32 位和 64 位操作系统上运行的 ac# 应用程序。在我的应用程序中,如何以编程方式检查计算机上是否安装了 SolidWorks。如果我们可以通过读取注册表项来检查它,请提供路径对于 32 位和 64 位。请告诉我是否还有其他方法来检查它。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

百变从容 2024-09-09 11:38:24

您可以按如下方式使用 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;           
}

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;           
}
苦行僧 2024-09-09 11:38:24

如果安装了应用程序,是否需要启动 SolidWorks?如果是这样,我将使用以下命令启动所有独立(非插件)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

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
孤云独去闲 2024-09-09 11:38:24

这是针对初学者的......
我认为有很多方法可以检查是否安装了Solidworks,
但根据我的观点,当安装 Solidworks 时,它会在注册表中创建一些文件夹。

只需按照以下步骤进行检查即可...

打开运行
在其中输入regedit并按
输入
通过单击允许“用户访问控制”

转到 HKEY_LOCAL_MACHINE -> 软件

现在检查 Solidwork 文件夹条目是否可用
如果文件夹中找到已安装的solidworks,否则不会..!

希望这会有所帮助!

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 !

高冷爸爸 2024-09-09 11:38:24

我不确定 Solidworks 的 macOS 版本需要什么,但对于 Windows,这应该是检查 Solidworks 是否已安装的可靠方法。

我怀疑这适用于 2010 及更高版本的任何版本,因为 Solidworks API 帮助文档从那里开始。我已经在 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");
    }
}

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(
quot;SOFTWARE\\{keyname}")
            ?? Registry.CurrentUser.OpenSubKey(
quot;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");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文