Author Topic: Insert program file in Startup suite.  (Read 1685 times)

0 Members and 1 Guest are viewing this topic.

FELIX

  • Newt
  • Posts: 188
Insert program file in Startup suite.
« on: October 19, 2015, 09:12:43 PM »
Insert program file in Startup suite contents list via code


OK.

Keith Brown

  • Swamp Rat
  • Posts: 596
Re: Insert program file in Startup suite.
« Reply #1 on: October 20, 2015, 07:42:43 AM »
I believe that you cannot do this.  Hence the reason for the autoloader, registry entries, etc. 


You can however automate the the dialog programmatically and add a file to the startup menu that way.  The question however is why?  There are other ways to autoload a lisp, .net, arx file that would be better.


** Edited because it was a wrong answer **
« Last Edit: November 05, 2015, 10:54:11 AM by Keith Brown »
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

FELIX

  • Newt
  • Posts: 188
Re: Insert program file in Startup suite.
« Reply #2 on: October 20, 2015, 08:47:22 AM »
I think it might but by the Windows registry.

 What I need is to run a VLX to load a menu.
OK.

Keith Brown

  • Swamp Rat
  • Posts: 596
Re: Insert program file in Startup suite.
« Reply #3 on: October 20, 2015, 08:49:51 AM »
You should try this link then.


http://www.lee-mac.com/autoloading.html
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

neyton

  • Newt
  • Posts: 67
Re: Insert program file in Startup suite.
« Reply #4 on: November 04, 2015, 09:38:08 AM »
Try this.



Code: [Select]
(Setq reg      (strcat "HKEY_CURRENT_USER\\"  (vlax-product-key) "\\Profiles\\" (getvar "cprofile"))
       regstar  (strcat reg  "\\Dialogs\\Appload\\Startup\\"))

  (if (not (vl-registry-descendents regstar ""))
    (Setq regstar  (strcat reg "\\UserInterfaceSettings\\Appload\\History")
  local    "History")
    (setq local "Startup"))
 
  (setq start    (mapcar '(lambda (x)
    (setq x (strcase (vl-registry-read regstar x) t))
    (list (strcat (vl-filename-base x) (vl-filename-extension x))
  (vl-filename-directory x)))
(vl-remove "NumHistory" (vl-remove "NumStartup" (vl-registry-descendents regstar "")))))

(setq tbdir "c:\\teste"
      vlx "teste.vlx")

(if (not (assoc vlx start)) ;se não está na startup suite, carrega
          (progn
            (vl-registry-write regstar (strcat (itoa (length start)) local) (strcat tbdir "\\" vlx ))
            (vl-registry-write regstar (strcat "Num" local) (itoa (length start)))))

Note, must be necessary restart Autocad after load this code, to do effect
Visit my website: http://tbn2.blogspot.com

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Insert program file in Startup suite.
« Reply #5 on: November 04, 2015, 03:12:29 PM »
Try this.



Code: [Select]
(Setq reg      (strcat "HKEY_CURRENT_USER\\"  (vlax-product-key) "\\Profiles\\" (getvar "cprofile"))
       regstar  (strcat reg  "\\Dialogs\\Appload\\Startup\\"))

  (if (not (vl-registry-descendents regstar ""))
    (Setq regstar  (strcat reg "\\UserInterfaceSettings\\Appload\\History")
  local    "History")
    (setq local "Startup"))
 
  (setq start    (mapcar '(lambda (x)
    (setq x (strcase (vl-registry-read regstar x) t))
    (list (strcat (vl-filename-base x) (vl-filename-extension x))
  (vl-filename-directory x)))
(vl-remove "NumHistory" (vl-remove "NumStartup" (vl-registry-descendents regstar "")))))

(setq tbdir "c:\\teste"
      vlx "teste.vlx")

(if (not (assoc vlx start)) ;se não está na startup suite, carrega
          (progn
            (vl-registry-write regstar (strcat (itoa (length start)) local) (strcat tbdir "\\" vlx ))
            (vl-registry-write regstar (strcat "Num" local) (itoa (length start)))))

Note, must be necessary restart Autocad after load this code, to do effect

Can someone translate gibberish into C#? 
Revit 2019, AMEP 2019 64bit Win 10

Jeff H

  • Needs a day job
  • Posts: 6043
Re: Insert program file in Startup suite.
« Reply #6 on: November 04, 2015, 03:44:29 PM »
Try this.



Code: [Select]
(Setq reg      (strcat "HKEY_CURRENT_USER\\"  (vlax-product-key) "\\Profiles\\" (getvar "cprofile"))
       regstar  (strcat reg  "\\Dialogs\\Appload\\Startup\\"))

  (if (not (vl-registry-descendents regstar ""))
    (Setq regstar  (strcat reg "\\UserInterfaceSettings\\Appload\\History")
  local    "History")
    (setq local "Startup"))
 
  (setq start    (mapcar '(lambda (x)
    (setq x (strcase (vl-registry-read regstar x) t))
    (list (strcat (vl-filename-base x) (vl-filename-extension x))
  (vl-filename-directory x)))
(vl-remove "NumHistory" (vl-remove "NumStartup" (vl-registry-descendents regstar "")))))

(setq tbdir "c:\\teste"
      vlx "teste.vlx")

(if (not (assoc vlx start)) ;se não está na startup suite, carrega
          (progn
            (vl-registry-write regstar (strcat (itoa (length start)) local) (strcat tbdir "\\" vlx ))
            (vl-registry-write regstar (strcat "Num" local) (itoa (length start)))))

Note, must be necessary restart Autocad after load this code, to do effect

Can someone translate gibberish into C#?
:-D :-D
(gibberish)
(gibberish)
Write to registry

neyton

  • Newt
  • Posts: 67
Re: Insert program file in Startup suite.
« Reply #7 on: November 05, 2015, 07:16:23 AM »
You need to write in this registry key:

HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R20.1\ACAD-F000:409\Profiles\<<C3D_Metric>>\Dialogs\Appload\Startup

for 2013 or above, use:
HostApplicationServices.Current.UserRegistryProductRootKey

for 2012 or bellow, use:
Runtime.SystemObjects.DynamicLinker.ProductKey

To retrieve this string ( depends of autocad version ) :
"HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R20.1\ACAD-F000:409\"

"<<C3D_Metric>>" is the current autocad profile
Use:
Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("cprofile")

You need add:
1Startup = "c:\teste.vlx"
NumStartup = 1

If you add more than one item:
1Startup = "c:\teste1.vlx"
2Startup = "c:\teste2.vlx"
3Startup = "c:\teste3.vlx"
4Startup = "c:\teste4.vlx"
...
NStartup = "c:\testeN.vlx"
NumStartup = N

Where N is the number of items

Visit my website: http://tbn2.blogspot.com

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Insert program file in Startup suite.
« Reply #8 on: November 05, 2015, 10:51:06 AM »
neyton, thank you for the translation.  Since this was posted in the .NET forum I wanted to make sure there was a .NET answer.

If you do not need to verify that the file name already exist in the start up folder then:
Code - C#: [Select]
  1. private static void AddStartupApplication(string filename)
  2.         {
  3.             var config = Application.UserConfigurationManager.OpenCurrentProfile();
  4.             if (!config.ContainsSubsection("Dialogs\\Appload\\Startup"))
  5.                 return;
  6.  
  7.             var startup = config.OpenSubsection("Dialogs\\Appload\\Startup");
  8.             if (!startup.Contains("NumStartup"))
  9.                 return;
  10.  
  11.             var number = (int)startup.ReadProperty("NumStartup", 0) + 1;
  12.             startup.WriteProperty("NumStartup", number);
  13.             startup.WriteProperty($"{number}Startup", filename);
  14.         }

If you need to verify the existence of the files in the start up folder:
Code - C#: [Select]
  1. private static void AddStartupApplication(string filename)
  2.         {
  3.             var autocad = Registry.CurrentUser.OpenSubKey("Software\\Autodesk\\AutoCAD\\");
  4.             var curVersion = autocad?.GetValue("CurVer");
  5.             if (curVersion == null)
  6.                 return;
  7.  
  8.             var release = autocad.OpenSubKey(curVersion.ToString());
  9.             curVersion = release?.GetValue("CurVer");
  10.             if (curVersion == null)
  11.                 return;
  12.  
  13.             var version = release.OpenSubKey(curVersion.ToString());
  14.             var profiles = version?.OpenSubKey("Profiles");
  15.             if (profiles == null)
  16.                 return;
  17.  
  18.             var profileName = profiles.GetValue("");
  19.             var profile = profiles.OpenSubKey(profileName.ToString());
  20.             var startup = profile?.OpenSubKey("Dialogs\\Appload\\Startup");
  21.             if (startup == null)
  22.                 return;
  23.  
  24.             var exists = startup.GetValueNames()
  25.                 .Where(n => n != "NumStartup")
  26.                 .Select(n => (string)startup.GetValue(n))
  27.                 .Any(v => v == filename);
  28.             if (exists)
  29.                 return;
  30.  
  31.             var number = (int) startup.GetValue("NumStartup") + 1;
  32.             startup.SetValue("NumStartup", number);
  33.             startup.SetValue($"{number}Startup", filename);
  34.         }

The RegistryKey class is disposable so you could/probably should wrap all the keys in using statements.
Revit 2019, AMEP 2019 64bit Win 10

FELIX

  • Newt
  • Posts: 188
Re: Insert program file in Startup suite.
« Reply #9 on: November 06, 2015, 10:45:45 PM »
Very good! We are almost there. But the ideal is not a DLL for the User in addition to having to load the program to configure AutoCAD has also to reboot. The ideal is an executable EXE program that configures the AutoCAD without having to be running and restart. An installer / qu.e configurator also searches for all installed AutoCADs

I lay down a program I'm developing in VB.NET but as I have no skill in this language is missing modify the registry.

I ask you to guide me to complete it and also improve it.

Code: [Select]
Imports Microsoft.Win32
Partial Public Class ConfiguraCADForm
    Public Sub New()
        Me.InitializeComponent()
    End Sub
    Sub MainFormLoad(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        Dim VERKEY As String = ""
        Dim CURVER As String = ""
        Dim PROFILE As String = ""
        '
        Dim K_ACADUSER As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\\Autodesk\\AutoCAD")
        Dim VERKEYS As String() = K_ACADUSER.GetSubKeyNames()
        For Each VERKEY In VERKEYS
            MsgBox(VERKEY)
            Dim K_VERKEY As RegistryKey = K_ACADUSER.OpenSubKey(VERKEY)
            Dim CURVERS As String() = K_VERKEY.GetSubKeyNames()
            For Each CURVER In CURVERS
                MsgBox(VERKEY + "\" + CURVER)
                Dim K_PROFILES As RegistryKey = K_ACADUSER.OpenSubKey(VERKEY + "\" + CURVER + "\" + "Profiles")
                Dim PROFILES As String() = K_PROFILES.GetSubKeyNames()
                For Each PROFILE In PROFILES
                    MsgBox(VERKEY + "\" + CURVER + "\" + PROFILE)
                    Dim K_PROFILE As RegistryKey = K_PROFILES.OpenSubKey(PROFILE)
                    Dim K_STARTUP As RegistryKey = K_PROFILE.OpenSubKey("Dialogs\Appload\Startup", RegistryKeyPermissionCheck.ReadWriteSubTree)
                    Dim NUMBER As String = K_STARTUP.GetValue("NumStartup").ToString
                    MsgBox(NUMBER)
                    '...
                    '...ADD "C:\TEST.VLX" IF NOT EXIST
                    '...
                    K_STARTUP.Close()
                    K_PROFILE.Close()
                Next PROFILE
                K_PROFILES.Close()
            Next CURVER
            K_VERKEY.Close()
        Next VERKEY
        K_ACADUSER.Close()
        Me.Close()
    End Sub
End Class
OK.

FELIX

  • Newt
  • Posts: 188
Re: Insert program file in Startup suite.
« Reply #10 on: November 07, 2015, 04:46:00 PM »
Records in the registry and also the contents startup suite but does not execute.

Code: [Select]
Imports Microsoft.Win32
Public Class Form
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim K_ACADUSER As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\\Autodesk\\AutoCAD")
        Dim VERKEYS As String() = K_ACADUSER.GetSubKeyNames()
        For Each VERKEY In VERKEYS
            Dim K_VERKEY As RegistryKey = K_ACADUSER.OpenSubKey(VERKEY)
            Dim CURVERS As String() = K_VERKEY.GetSubKeyNames()
            For Each CURVER In CURVERS
                Dim K_PROFILES As RegistryKey = K_ACADUSER.OpenSubKey(VERKEY + "\" + CURVER + "\" + "Profiles")
                Dim PROFILES As String() = K_PROFILES.GetSubKeyNames()
                For Each PROFILE In PROFILES
                    MsgBox(VERKEY + "\" + CURVER + "\" + PROFILE)
                    Dim K_PROFILE As RegistryKey = K_PROFILES.OpenSubKey(PROFILE)
                    Dim K_STARTUP As RegistryKey = K_PROFILE.OpenSubKey("Dialogs\Appload\Startup", RegistryKeyPermissionCheck.ReadWriteSubTree)
                    Dim NUMBER As String = K_STARTUP.GetValue("NumStartup")
                    '...
                    K_STARTUP.SetValue("NumStartup", (CInt(NUMBER) + 1).ToString)
                    K_STARTUP.SetValue((CInt(NUMBER) + 1).ToString + "Startup", "C:\TESTE.LSP")
                    '...
                    K_STARTUP.Close()
                    K_PROFILE.Close()
                Next PROFILE
                K_PROFILES.Close()
            Next CURVER
            K_VERKEY.Close()
        Next VERKEY
        K_ACADUSER.Close()
        Me.Close()
    End Sub
End Class

TESTE.LSP
Code: [Select]
(ALERT "HELLO!")
OK.