I’m trying to unload add-ins from SOLIDWORKS upon startup.
My user domain has some security policy that do not allow for registry keys edits.
I have tried looking for a magic command line argument would launch SOLIDWORKS without add-ins and that search did not go anywhere. Anyone is welcome to share this one if they know it…
It seems that the only path forward is to :
- Find all the CLSIDs from the AddInsStartUp node in the registry under CurrentUser\Software\SOLIDWORKS
- Launch SOLIDWORKS using the /r /b arguments.
- Wait for SOLIDWORKS to finish loading add-ins.
- Inspect which add-ins are loaded using SldWorks::GetAddInObject == null
- Find the dll path of the loaded add-ins in the registry using InprocServer32
- Unload add-ins using SldWorks::UnloadAddIn.
The add-ins seem to load one at a time. That’s one problem of two.
The second issue is if one add-in has a UI that blocks the main thread, the whole application stops for user input and can’t inspect what has not loaded yet.
I try to blindly unloaded all the CLSIDs but that circle back to the point if the UI is blocked then the add-ins I’m unloading will finish loading until the user input is completed.
I wonder if there is a smart to go around this via a event handler?
This code loads a SW window with no add-ins active. I was playing around with how to open a specific version of SW but both methods open an instance without add-ins. I’m not 100% sure why, but maybe this will help.
My issue with this approach is that the add-ins aren’t shown in the Tools → Add-Ins menu anymore. There are usually twice this number of add-ins to select.
static void Main()
private static void StartSW()
var progId = "SldWorks.Application.26";
var progType = System.Type.GetTypeFromProgID(progId);
var app = System.Activator.CreateInstance(progType) as SolidWorks.Interop.sldworks.ISldWorks;
app.Visible = true;
app = null;
private static void StartSW2()
SldWorks swApp = new SldWorks();
swApp.Visible = true;
swApp = null;
Thanks for the reply. My issue is that I can’t use the activator to launch since it is not reliable. I’m using System.Diagnostics.Process.Start
You mention that you cannot edit the registry, does this apply to the Current User Registry? As this is basically designed to be writable even in non-administrative user? Or are you creating a new app domain and thus do not have access to the registry? The way I solved this in xCAD is to disable add-ins from the registry before starting and restore after: xcad/SwApplicationFactory.cs at c70d6f945802644ec0d869022765886d948420e5 · xarial/xcad · GitHub
As this is only a modified Current User Registry you do not have to have elevated permissions to run this code.
I don’t think they have permissions because whenever they restarted SOLIDWORKS, the checkbox would be checked again.
Do you have experience with the RegistryPermissionAttribute?