1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-15 07:43:50 +00:00

1. Added process.pid on windows

2. Added user-sessions.consoleUid() on windows
3. updated message-box to dispatch to consoleUid when necessary on Windows
This commit is contained in:
Bryan Roe
2019-05-17 14:23:51 -07:00
parent 26d86ce449
commit 1fc476d31e
4 changed files with 41 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1047,8 +1047,11 @@ void ILibDuktape_ScriptContainer_Process_Init(duk_context *ctx, char **argList)
#ifdef _POSIX
duk_push_int(ctx, (duk_int_t)getpid());
ILibDuktape_CreateReadonlyProperty(ctx, "pid");
#else
duk_push_int(ctx, (duk_int_t)GetCurrentProcessId());
#endif
ILibDuktape_CreateReadonlyProperty(ctx, "pid");
emitter = ILibDuktape_EventEmitter_Create(ctx);
ILibDuktape_EventEmitter_CreateEventEx(emitter, "exit");

View File

@@ -74,12 +74,33 @@ function messageBox()
this._ObjectID = 'message-box';
this.create = function create(title, caption, timeout)
{
var GM = require('_GenericMarshal');
var kernel32 = GM.CreateNativeProxy('kernel32.dll');
kernel32.CreateMethod('ProcessIdToSessionId');
var psid = GM.CreateVariable(4);
if (kernel32.ProcessIdToSessionId(process.pid, psid).Val == 0)
{
ret._rej('Internal Error');
return (ret);
}
if (timeout == null) { timeout = 10; }
var ret = new promise(function (res, rej) { this._res = res; this._rej = rej; });
var options = { executionTimeout: timeout };
try
{
options.sessionId = require('user-sessions').consoleUid();
if (options.sessionId == psid.toBuffer().readUInt32LE()) { delete options.sessionId; }
}
catch(ee)
{
ret._rej('No logged on users');
return (ret);
}
ret._title = title;
ret._caption = caption;
ret._container = require('ScriptContainer').Create(timeout, ContainerPermissions.DEFAULT);
ret._container = require('ScriptContainer').Create(options);
ret._container.promise = ret;
ret._container.on('data', function (j)
{

View File

@@ -90,6 +90,7 @@ function UserSessions()
this._marshal = require('_GenericMarshal');
this._kernel32 = this._marshal.CreateNativeProxy('Kernel32.dll');
this._kernel32.CreateMethod('GetLastError');
this._kernel32.CreateMethod('WTSGetActiveConsoleSessionId')
try
{
@@ -202,7 +203,12 @@ function UserSessions()
this._wts.WTSFreeMemory(buffer.Deref());
return (retVal);
};
this.consoleUid = function consoleUid()
{
var id = this._kernel32.WTSGetActiveConsoleSessionId().Val;
if(id==0xFFFFFFFF) {throw('Nobody logged in');}
return (id);
};
this.Current = function Current(cb)
{
var retVal = {};