Luigi Posted November 6, 2014 Share Posted November 6, 2014 Hi forum! I use nssm.exe to run a compiled script as Windows Service, it's work fine! Very easy. But, I have a doubt: How launch a application (for example, another AutoIt script) on current user session from this Windows Service? Thanks for any help Br, Detefon Visit my repository Link to comment Share on other sites More sharing options...
Luigi Posted November 6, 2014 Author Share Posted November 6, 2014 I have this scripts to try: gui_teste.exe #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=gui_teste.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseUpx=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Global $hGui = GUICreate("teste", 800, 600, -1, -1, Default, Default) GUISetState(@SW_SHOW, $hGui) While Sleep(50) And (GUIGetMsg() <> -3) WEnd monitor.exe expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=monitor.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_Res_Fileversion=0.0.0.22 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #AutoIt3Wrapper_Res_Language=1046 #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Process.au3> #include <Debug.au3> ;~ #include <MessageHandler.au3> Global $iCount = 0 Global $iTimer = TimerInit() Global $hTCP = TCPStartup() Global $iIP = "127.0.0.1" Global $iPort = 4333 Global $user = "your_user_name" ; type here the username to launche remote aplication OnAutoItExitRegister("before_exit") _DebugSetup(@ScriptName, True, 4, "monitor.log", True) Global $iMAIN_SOCKET = TCPListen($iIP, $iPort, 3) Global $sReceived = 0 While True $iSocket = TCPAccept($iMAIN_SOCKET) If Not @error Then $sReceived = TCPRecv($iSocket, 512) If Not @error And $sReceived Then _receive($sReceived) EndIf TCPCloseSocket($iSocket) WEnd Func _exit() Exit EndFunc ;==>_exit Func _receive($input = 0) Local $TRY Local $APP = "gui_teste.exe" If $input Then Switch $input Case "run_01" $TRY = ShellExecute($APP, "", @ScriptDir) _DebugOut("run_01[ " & $TRY & " ]") Case "run_02" $TRY = Run($APP, @ScriptDir, @SW_SHOW, 0x10000) _DebugOut("run_02[ " & $TRY & " ]") Case "run_03" $TRY = _RunDos($APP) _DebugOut("run_03[ " & $TRY & " ]") Case "run_04" $TRY = RunAs($user, @ComputerName, Default, 0, $APP, @ScriptDir) _DebugOut("run_04[ " & $TRY & " ]") Case "run_05" $TRY = RunAs($user, @ComputerName, Default, 1, $APP, @ScriptDir) _DebugOut("run_05[ " & $TRY & " ]") Case "run_06" $TRY = RunAs($user, @ComputerName, Default, 2, $APP, @ScriptDir) _DebugOut("run_06[ " & $TRY & " ]") Case "run_07" $TRY = RunAs($user, @ComputerName, Default, 4, $APP, @ScriptDir) _DebugOut("run_07[ " & $TRY & " ]") Case "run_08" $APP = 'runas /user:' & @ComputerName & '\' & $user & ' "gui_teste.exe"' $TRY = _RunDos($APP) _DebugOut("run_08[ " & $TRY & " ]") Case Else _DebugOut("$input[ " & $input & " ]") EndSwitch EndIf EndFunc ;==>_receive Func before_exit() If $iMAIN_SOCKET Then TCPCloseSocket($iMAIN_SOCKET) If $hTCP Then TCPShutdown() _DebugOut("exit") EndFunc ;==>before_exit sender.exe expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=sender.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_Res_Fileversion=0.0.0.1 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #AutoIt3Wrapper_Res_Language=1046 #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Debug.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Global $hTcp = TCPStartup() OnAutoItExitRegister("OnAutoItExit") Local $sIPAddress = "127.0.0.1" ; This IP Address only works for testing on your own computer. Local $iPort = 4333 ; Port used for the connection. Local $var = @MDAY & "/" & @MON & "/" & @YDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC $var = "run_01" MyTCP_Client($sIPAddress, 4333, $var) Func MyTCP_Client($sIPAddress, $iPort, $data) Local $iSocket = TCPConnect($sIPAddress, $iPort) Local $iError = 0 If @error Then ; The server is probably offline/port is not opened on the server. $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not connect, Error code: " & $iError) Return False EndIf TCPSend($iSocket, $data) If @error Then $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not send the data, Error code: " & $iError) Return False EndIf TCPCloseSocket($iSocket) EndFunc ;==>MyTCP_Client Func OnAutoItExit() TCPShutdown() ; Close the TCP service. EndFunc ;==>OnAutoItExit download nssm.exe in the same directory, and type: nssm install service_test press CTRL+ALT+DEL, go services, locate service_test and run run sender and change $var's content to run_01 to run_8 to execute gui_teste.exe... run_01 and run_02 can start gui_teste.exe in isolation 0 but, none work fine... Visit my repository Link to comment Share on other sites More sharing options...
Solution jdelaney Posted November 6, 2014 Solution Share Posted November 6, 2014 (edited) paexec, or create, and then run, a scheduled task to run as the logged in user. I also like having a tcpip listener...I'll add it to the startup folder of the user(s)...then the service tells the listener what to do. We do a similar thing to run regression suites. Edited November 6, 2014 by jdelaney Luigi 1 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
jguinch Posted November 6, 2014 Share Posted November 6, 2014 _Security__CreateProcessWithToken() could work. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Luigi Posted November 6, 2014 Author Share Posted November 6, 2014 (edited) @jdelaney, I try with PSEXEC.EXE, but not succes until now, I will try @jguinch, I stay very hopeful whe I read your reply, about _Security__CreateProcessWithToken(), but it run on Windows Isolation 0... 8( Thanks for your reply, I will try more. Br, Detefon Edited November 6, 2014 by Detefon Visit my repository Link to comment Share on other sites More sharing options...
Luigi Posted November 11, 2014 Author Share Posted November 11, 2014 Maybe I should change the question: Can a service (the administrator account) to launch / start an application on the local user account?I believe it's possible, but I'm not finding good options.Maybe I'm not looking in the right keywords ...If anyone knows other options, please share the name of the feature, function or method. Br, Detefon Visit my repository Link to comment Share on other sites More sharing options...
jdelaney Posted November 11, 2014 Share Posted November 11, 2014 (edited) Yes, but not directly (that I know of)...like I already said, paexec, or a scheduled task with the proper options. Edited November 11, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Luigi Posted November 11, 2014 Author Share Posted November 11, 2014 @jdelaney, I am study paexec now... 8D Visit my repository Link to comment Share on other sites More sharing options...
Luigi Posted November 12, 2014 Author Share Posted November 12, 2014 (edited) @jdelaney, thanks for your help, schtask is a better option for me. It's free and i know how is advanced is this feature. You help-me, thank you! Edited November 12, 2014 by Detefon Visit my repository Link to comment Share on other sites More sharing options...
jdelaney Posted November 12, 2014 Share Posted November 12, 2014 PAExec is free, as well....it does everything psexec does, and a bit more. PSExec was bought out by microsoft (I believe) IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now