Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Starting up NinjaTrader Desktop 8.1 without typing username and password every time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #91
    Upgrading the OS and Ninjatrader is always a big, tiresome task. My infrastructure finally feels solid though now, so it's one less thing to worry about. Ok here it is. Let me know if it works for you.

    You'll need to download the attachment and then remove the .txt from the end of the file name. It wouldn't let me attach a .exe file here.


    Code:
    using System;
    using System.Diagnostics;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Threading;
    
    namespace NTLogin
    {
        public class Program
        {
            private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
            private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;
    
            [DllImport("user32.dll")]
            static extern bool SetCursorPos(int x, int y);
    
            [DllImport("user32.dll")]
            static extern bool SetForegroundWindow(IntPtr hWnd);
    
            [DllImport("user32.dll")]
            private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, uint dwExtraInf);
    
            [DllImport("user32.dll", SetLastError = true)]
            [return: MarshalAs(UnmanagedType.Bool)]
            static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
    
            [StructLayout(LayoutKind.Sequential)]
            private struct RECT
            {
                public int Left;
                public int Top;
                public int Right;
                public int Bottom;
            }
    
            private static void ButtonClick(int x, int y)
            {
                SetCursorPos(x, y);
                mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
            }
    
            [STAThread]
            static void Main(string[] args)
            {
                Process ninjaProc = null;
                bool foundNinja = false;
                string passwd;
                string ninjaExe = @"C:\Program Files\NinjaTrader 8\bin\NinjaTrader.exe";
    
                // Expect exactly 1 argument (password)
                if (args.Length != 1)
                {
                    return; // Silently exit if arguments are wrong
                }
    
                passwd = args[0]; // Set password from the single argument
    
                if (string.IsNullOrEmpty(passwd))
                {
                    return; // Silently exit if password is missing
                }
    
                RECT rctNTPosition = new RECT();
                Process.Start(@ninjaExe);
    
                while (!foundNinja)
                {
                    Process[] processlist = Process.GetProcessesByName("NinjaTrader");
                    if (processlist.Length > 0)
                    {
                        ninjaProc = processlist[0];
                        foundNinja = true;
                    }
                    System.Threading.Thread.Sleep(100);
                }
    
                int maxRetries = 60;
                int retryCount = 0;
                bool windowReady = false;
                while (!windowReady && retryCount < maxRetries)
                {
                    if (ninjaProc.MainWindowHandle != IntPtr.Zero && GetWindowRect(ninjaProc.MainWindowHandle, ref rctNTPosition))
                    {
                        if (rctNTPosition.Right > rctNTPosition.Left && rctNTPosition.Bottom > rctNTPosition.Top)
                        {
                            windowReady = true;
                        }
                    }
                    if (!windowReady)
                    {
                        System.Threading.Thread.Sleep(500);
                        retryCount++;
                    }
                }
    
                if (!windowReady)
                {
                    return; // Silently exit if window isn’t ready
                }
    
                SetForegroundWindow(ninjaProc.MainWindowHandle);
                GetWindowRect(ninjaProc.MainWindowHandle, ref rctNTPosition);
                ButtonClick(rctNTPosition.Left + 30, rctNTPosition.Top + 210);
    
                Clipboard.SetText(passwd);
                SendKeys.SendWait("^v");
                SendKeys.SendWait("{ENTER}");
            }
        }
    }​
    Attached Files

    Comment


      #92
      I just leave mine logged in on a server

      Comment


        #93
        Originally posted by Tickdataman View Post
        I just leave mine logged in on a server
        Hi do you see any lag on cursor movements or kb inputs?

        thanks

        Comment


          #94
          Originally posted by Tickdataman View Post
          I just leave mine logged in on a server
          Useful for the someone who only trades, but developers may
          have to exit/restart NinjaTrader dozens of times during the day,
          and each restart mandates the username/password signon
          dialog -- which quickly becomes tiresome.

          Also, if NT8 (or Windows) ever crashes, you'll be restarting
          NT8 in a hurry, and that username/password dialog will most
          likely just get in your way and slow you down.

          I agree, best to leave NT8 always running and always logged
          in -- but it's even better to have a 'Remember me' checkbox
          option to automatically bypass the signon process.

          It's a no brainer, but NT mgmt is too scared to allow it.

          Bummer.

          Comment


            #95
            Do new versions allow facial or fingerprint login?

            Comment


              #96
              #devatechnologies
              Pleased to report that it works for me - like an absolute charm. Thank you SO MUCH for doing this.
              Kind regards,
              Bruce

              Comment


                #97
                Originally posted by brucerobinson View Post
                Pleased to report that it works for me - like an absolute charm. Thank you SO MUCH for doing this.
                I concur, I downloaded it, removed the .txt extension,
                and it works perfectly! Many Thanks!



                Comment


                  #98
                  Originally posted by NinjaTrader_Ray View Post
                  Let me clarify the thinking behind the change which was not driven by security concerns. In order to be able to offer an integrated experience for our customers to be able to use the NinjaTrader Desktop, Web, Mobile and Account Management (which is now available to all NinjaTrader Brokerage customers) features efficiently, it was necessary for us to collapse into a single user management (logon) approach. Account security is just a benefit of this. That all said, we hear what you are saying and as mentioned in an earlier post, will make some improvements to the Desktop logon experience with our next release, which will come out sooner than later.
                  More than two years later and still annoying. That you do not provide a solution, is telling. I assume the next progressive/incremental step will be 2FA.
                  Last edited by Mark--; 05-06-2025, 07:45 AM.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  666 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  377 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  110 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  575 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  580 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X