meshcentral
Version:
Web based remote computer management server
1 lines • 2.48 kB
JavaScript
var SPI_GETDESKWALLPAPER=115,SPI_SETDESKWALLPAPER=20,SPI_GETMOUSETRAILS=94,SPI_SETMOUSETRAILS=93,GM=require("_GenericMarshal"),user32=GM.CreateNativeProxy("user32.dll");function sessionDispatch(e,t,r,s){var o=void 0,i=0==require("user-sessions").getProcessOwnerName(process.pid).tsid?1:0,e=(console.log("stype: "+i),1==i&&(o=null==e&&null!=require("MeshAgent")._tsid?(i=5,require("MeshAgent")._tsid):e),Buffer.from(getJSModule("win-deskutils")).toString("base64"),"try { addModule('win-deskutils', process.env['win_deskutils']);} catch (x) { } var x;try{x=require('win-deskutils').dispatch('"+t+"', '"+r+"', "+JSON.stringify(s)+");console.log(x);}catch(z){console.log(z);process.exit(1);}process.exit(0);"),t=require("child_process").execFile(process.execPath,[process.execPath.split("\\").pop(),"-b64exec",Buffer.from(e).toString("base64")],{type:i,uid:o,env:{win_deskutils:getJSModule("win-deskutils")}});if(t.stdout.str="",t.stdout.on("data",function(e){this.str+=e.toString()}),t.stderr.on("data",function(e){}),t.on("exit",function(e){this.exitCode=e}),t.waitExit(),0==t.exitCode)return t.stdout.str.trim();throw t.stdout.str.trim()}function background_get(e){if(null!=e||null===e)return sessionDispatch(e,"background","get",[]);e=GM.CreateVariable(1024);if(0==user32.SystemParametersInfoA(SPI_GETDESKWALLPAPER,e._size,e,0).Val)throw"Error occured trying to fetch wallpaper";return e.String}function background_set(e,t){if(null!=t||null===t)return sessionDispatch(t,"background","set",[e]);t=GM.CreateVariable(e);if(0==user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER,t._size,t,0).Val)throw"Error occured trying to set wallpaper"}function dispatch(e,t,r){try{return this[e][t].apply(this,r)}catch(e){throw console.log("ERROR: "+e),"Error occured trying to dispatch: "+t}}function mousetrails_set(e,t){if(null!=t||null===t)return sessionDispatch(t,"mouse","setTrails",[e]);if(0==user32.SystemParametersInfoA(SPI_SETMOUSETRAILS,e,0,0).Val)throw"Error occured trying to fetch wallpaper"}function mousetrails_get(e){if(null!=e||null===e)return sessionDispatch(e,"mouse","getTrails",[]);e=GM.CreateVariable(4);if(0==user32.SystemParametersInfoA(SPI_GETMOUSETRAILS,e._size,e,0).Val)throw"Error occured trying to fetch wallpaper";return e.toBuffer().readUInt32LE()}user32.CreateMethod("SystemParametersInfoA"),module.exports={background:{get:background_get,set:background_set}},module.exports.mouse={getTrails:mousetrails_get,setTrails:mousetrails_set},module.exports.dispatch=dispatch