Page 1 of 1

launch second instance with "open elevated process"

Posted: Fri Dec 02, 2016 8:44 am
by Ledigimate
Dear experts,

I'm experiencing two issues on Windows. My LiveCode app needs to launch a second instance of itself with elevated privileges.

I use the following code to launch the second instance:

Code: Select all

on openStack
   if $1 is empty then
      put $0 && "-slave" into tSlave
      open elevated process tSlave
   end if
end openStack
The first issue is that the second instance starts but doesn't show its user interface.

The second issue is that the following code doesn't work in the second instance. It executes but no file is created or modified. It works in the first instance but not in the second instance.

Code: Select all

   put "testfile.bin" into tTestFile
   open file tTestFile for binary write
   write "test" to file tTestFile
   close file tTestFile
Any idea why that is?

Re: launch second instance with "open elevated process"

Posted: Mon Dec 05, 2016 2:36 pm
by Ledigimate
I have resolved the second issue, and it wasn't LiveCode's fault. The second instance receives data from the first instance, specifying the name of the file to create. This data had a linefeed character at the end which, if not removed, caused the "open file" statement to fail with the result "can't open that file". I just removed the linefeed character and then it worked as expected.

The first issue is persistent, though.

Re: launch second instance with "open elevated process"

Posted: Mon Dec 05, 2016 5:43 pm
by AxWald
Hi,

just tried with same results.
I'd try to change name for one somehow - two identical instances smell like danger.
Other thing, the slave will try to open another slave (via openstack msg), and so on - maybe it's this?

Hope I could help, maybe I'll give it a try if I find a piece of spare time. What's this good for, anyways? Care to explain?

Have fun!

Re: launch second instance with "open elevated process"

Posted: Tue Dec 06, 2016 7:35 am
by Ledigimate
The application always checks the $1 command line argument and if it is "-slave" then it doesn't launch a second instance.

I can understand why two instances of the same application smell like danger, but I've made sure the second instance knows when it was launched in slave mode. There are some well-known applications that launch multiple instances of themselves without a problem, like Google Chrome. As long as each instance knows when it's the master or a slave process and can keep proper tabs on each, it shouldn't be a problem.

I need the application to perform blocking operations requiring elevated privileges without making the user interface appear non-responsive, and in LiveCode this master-slave approach is the closest we can get to actual multithreading.

EDIT: I've just discovered that on Windows XP the user interface for the second instance does appear. I'm suspecting it might have something to do with the Desktop Window Manager which Windows XP doesn't have... but it's still a bug in my opinion.