Multiple Sublime instances using different windows credentials?

Try execute (Windows+R) and this command

runas /user:[the-other-user] C:\path\to\sublime_text

I'm not on windows, but it should work..

Update

Definitive working solution to OP was to make a copy of sublime_text.exe in the same directory, and run it with privileges.

Other proposed untested solutions

  • Make a second instalation of Sublime Text 3 in another directory
  • Make a parallel instalation of Sublime Text 2
  • According to Sublime Text Unofficial Documentation, there is a portable version of ST. This can be run with privileges. Source: http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/getting_started/install.html#how-to-install-the-portable-version-of-sublime-text

Technically, a way to achieve such an effect is to open a global accessible synchronization object such as a named pipe. The second process will detect an existing object and in some way tell the first process to open the file.

And that's exactly what Sublime Text does as well. You can observe this with Process Explorer (SysInternals):

  1. Run Process Explorer as administrator
  2. Run Sublime text
  3. Select Sublime text in the process list
  4. Press Ctrl+H to show the lower pane for handles
  5. Find a handle of type Mutant with "Sublime Text 2" in its name. It may look like \Sessions\1\BaseNamedObjects\4d3560c7bb75b0aede072672a3c001bb-Sublime Text 2
  6. Right click the Mutant
  7. Select "Close Handle"
  8. Start another instance of Sublime Text

Now you know how to start a new instance of Sublime Text. Of course you want to automate this process. The required sequence flow is now known to you:

  1. Find all processes of sublim_text.exe, e.g. using EnumProcesses (MSDN)
  2. Go through their list of handles, e.g. using NtQuerySystemInformation with SystemHandleInformation
  3. Close all Mutants with "Sublime Test 2" in the name, e.g. using CloseHandle (MSDN).

You'll need to close the handle for the new process as well, since the new process will create it again.

Handle (Sysinternals) is helpful to set up a script that achieves what you need. It can find a handle (line 1) and close a handle (line 2)

Handle -p sublime_text.exe -a Sublime | find "Mutant"
Handle -c <handle> -p <pid> -y

In the following complete script, adapt the username. Copy handles.exe into the same directory and run the batch file as administrator (since handles.exe needs admin rights:

@echo off
REM Just in case this is run multiple times from a command line 
set pid=    
set handle=
REM Make the working directory the directory of the batch file
cd /d %~dp0 
REM Find PID and Handle
for /f "tokens=3,6" %%i in ('handle -p sublime_text.exe -a Sublime -accepteula ^| find "Mutant"') do set pid=%%i & set handle=%%j   
if "%pid%"=="" goto sublime 
REM Close the handle
handle -c %handle:~0,-1% -p %pid% -y > nul  
:sublime
runas /user:Username sublime_text.exe   
if errorlevel 1 pause

Windows doesn't provide any way to directly do what Sublime Text is doing, which means there is no universal way to override this behavior. It will depend on how the program itself implements this behavior. Unfortunately, the fact that the second session is the Admin one makes it harder to use techniques that block communication across privilege levels, because the more privileged app needs to talk to the less-privileged, and that's almost always allowed.

First of all, you can probably turn off the merging of sessions automatically. The downside of this is that files you want to have open in the current window would open in a new one. So that's obviously an inferior option, but it exists.

If Sublime simply looks for another instance of itself by name, you could create two copies of the executable, append "Admin" on the name of one, and use the Compatibility tab to mark that one as always needing to run as Admin. Add it to your Start or Taskbar, and you have an admin-only editor easily launchable. Note that it won't update when the first one does, though. Using a symlink or hardlink would work if Sublime is checking the command line, but not if it's checking the image name (image name always resolves to the first canonical path).

A slightly extreme approach that might work is to use loopback remote desktop. This only works on Server SKUs of Windows because it requires having two interactive sessions active at once (which client versions of Windows prohibit) but Sublime might stop at the Session boundary even where it normally ignores the User boundary. Just remote to localhost with the domain admin creds, and then launch Sublime (or even set it up so it automatically launches Sublime, or maybe even so it just forwards that one app back to your desktop instead of fully drawing the other desktop). This approach would work for things like a named mutex or similar that is created in a user session (instead of globally).

It's probably not a file or registry key, since the only places an unprivileged instance of Sublime could create those are generally not where a privileged version would look for them. There are exceptions, though; for example, ProgramData is world-writable. If that is how Sublime is detecting the other instance of itself, I have no workable suggestion except to use a different editor; that's just a flat-out not-multi-user-compatible behavior.

If the approaches above don't work, your only option (short of always starting Sublime as Admin, or using another editor for Admin work) is to poke the developers and ask them to behave better in multi-user scenarios. Most Windows programs are at best unaware of the concept that multiple users might want to run the program at once, but a few are totally incompatible with it. The Sublime devs could, for example, check the credentials the already-existing instances are running under before merging sessions... but if the devs didn't think of that themselves, you might have to file a bug to get them to fix it.