Jump to content

service script


Recommended Posts

im trying to run my script as a service and this is what i do, but it does not run as a service.

#include "ServiceControl.au3"
$servicename = "test.exe"
FileInstall("srvany.exe",@SystemDir & "srvany.exe",1)
_CreateService("", $servicename, "", @SystemDir & "srvany.exe", "LocalSystem", "", 0x110)
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\" & $servicename & "\Parameters", "Application", "REG_SZ", @ScriptFullPath)
Run("test.exe")

ServiceControl.au3 is in my include folder.

srvany.exe is on my desktop.

test.exe is on my dektop.

this script is run from my desktop.

i open the task manager and test.exe is still running under my user name and does not say "service".

what am i doing wrong?

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

Hi,

I did it this way:

#include "ServiceControl.au3"
#include "Misc.au3"
;#NoTrayIcon ; Kann man natürlich auch noch wegmachen :-)

If _Singleton("MegaService", 1) = 0 Then
    MsgBox(64, "Warning", "An occurence of test is already running", 3)
    Exit
EndIf

Global $pathSrvAny = "c:\Downloads\AutoIt-Skripte\Entwicklung\ForumTests\srvany.exe"
Global $servicename = "MegaService"
If Not _ServiceExists (@ComputerName, $servicename) And @Compiled Then
    _CreateService ("", $servicename, "Mega Skript", $pathSrvAny, "LocalSystem", "", 0x110)
    RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\" & $servicename & "\Parameters", "Application", "REG_SZ", @ScriptFullPath)
EndIf

While 1
    Sleep(500)
    theFunc()
WEnd

Func theFunc()
    If @HOUR = 16 And @MIN = 24 And @SEC = 00 Then ; hier mal die Zeit anpassen :-)
        ToolTip("Skript gestartet" & " Service An(1)Aus(0) :" & _ServiceExists (@ComputerName, $servicename), 0, 0)
        Beep(500, 5000)
    Else
        ToolTip("Skript inaktiv" & " Service An(1)Aus(0) :" & _ServiceExists (@ComputerName, $servicename), 0, 0)
    EndIf
EndFunc   ;==>theFunc

Edit: You are also missing a \ here @SystemDir & "srvany.exe" , right?

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

I did it this way:

#include "ServiceControl.au3"
#include "Misc.au3"
;#NoTrayIcon ; Kann man natürlich auch noch wegmachen :-)

If _Singleton("MegaService", 1) = 0 Then
    MsgBox(64, "Warning", "An occurence of test is already running", 3)
    Exit
EndIf

Global $pathSrvAny = "c:\Downloads\AutoIt-Skripte\Entwicklung\ForumTests\srvany.exe"
Global $servicename = "MegaService"
If Not _ServiceExists (@ComputerName, $servicename) And @Compiled Then
    _CreateService ("", $servicename, "Mega Skript", $pathSrvAny, "LocalSystem", "", 0x110)
    RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\" & $servicename & "\Parameters", "Application", "REG_SZ", @ScriptFullPath)
EndIf

While 1
    Sleep(500)
    theFunc()
WEnd

Func theFunc()
    If @HOUR = 16 And @MIN = 24 And @SEC = 00 Then ; hier mal die Zeit anpassen :-)
        ToolTip("Skript gestartet" & " Service An(1)Aus(0) :" & _ServiceExists (@ComputerName, $servicename), 0, 0)
        Beep(500, 5000)
    Else
        ToolTip("Skript inaktiv" & " Service An(1)Aus(0) :" & _ServiceExists (@ComputerName, $servicename), 0, 0)
    EndIf
EndFunc   ;==>theFunc

Edit: You are also missing a \ here @SystemDir & "srvany.exe" , right?

So long,

Mega

i am missing that "\" in the code that posted because i did it the proper way first, but i started to mess around with it to get it to work and i must have accidentally erased that. this is just what i cut and pasted after i messed with it.

however the fileinstall function does not matter in this script becaue i have already put the file there manually.

i added that and i also tried your code and this isnt working for me.

can someone give me an example where it will take a file... and run it as a service from the script?

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

i tried using it but i could not get it to work.

then i read your instructions now it works. heh

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

one last thing.

i have adjusted the script... so that it will run a service without a gui.

#include <Process.au3>
Global $strComputer = "."
Const $OWN_PROCESS = 16;16 is own process
Const $INTERACTIVE = true;True changes the $Own_Process to 272 is interact with desktop
Const $NORMAL_ERROR_CONTROL = 1

$srvany = @DesktopDir & "\srvany.exe"
$script = @DesktopDir & "\test.exe"
$objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
    $objService = $objWMIService.Get("Win32_BaseService")
    $errReturn = $objService.Create("_Au3@Service" ,"_Au3@Service" , $SrvAny, $OWN_PROCESS, $NORMAL_ERROR_CONTROL, _
    "Manual", $INTERACTIVE, "LocalSystem", ""  )
    RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@service\Parameters", "AppDirectory", "REG_SZ", @WorkingDir)
        RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@service\Parameters", "Application", "REG_SZ", $Script)
_RunDos("Net start _au3@service")
ProcessClose("srvany.exe")oÝ÷ Ûrv¬²»Ú'±yÊ')îzÚ+º|!zx­²z-çyׯzvµêâ{­+®øzÇ+l®ö§ÉÊ'¶)îzËh®éârZ,zÊïj|Å觵«$©ÚêÚÙ²±êïǬr¸©¶+'¢×}ç-(IèÂ+lgyç^+º|!W­ë®øz++ºyâ!zx­¯+hrZ,zÊïj|ÅëâjÇ+g¢ØbZ¦§²'¯z{kçZ²Ö§u©hë®*mÂ+aë-¶¬x­jëh×6ProcessClose("srvany.exe")

how can i end this process? it is not needed and it actually intrferes with my script.

if i end the script, srvany.exe continues to run.

then when i attempt to run the service script again, if i have not manually ended srvany.exe then it does nothing.

any help?

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

srvany is a service not a "program". You have to stop it with something like

net stop my au3 service
Link to comment
Share on other sites

srvany is a service not a "program". You have to stop it with something like

net stop my au3 service
uhm... wont that stop both srvany.exe AND test.exe??

is there a way to make these seperate services? or what.

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

:shocked: didn't you want your script to run as an service? But you want to remove the service part? Thats easy,... don't run it as a service..:(
Link to comment
Share on other sites

:shocked: didn't you want your script to run as an service? But you want to remove the service part? Thats easy,... don't run it as a service..:(

ehm, uh.

the script will run as a service....

i go into task manager.

i close srvany.exe

the script is still running as a service.

yes i would like the script to run as a service, but i dont need srvany.exe running as a service after its use has been completed.

if this is not possible i will merely add the stopservice code to the beginning of the script to prevent this issue.. however thats undesirable....

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

ehm, uh.

the script will run as a service....

i go into task manager.

i close srvany.exe

the script is still running as a service.

No it is not. Because you have killed the service part of your script so it will not act as a service any more. It runs as a regular program under another user profile SYSTEM or what it is called these days.
Link to comment
Share on other sites

No it is not. Because you have killed the service part of your script so it will not act as a service any more. It runs as a regular program under another user profile SYSTEM or what it is called these days.

interesting.

is there a way to run a script (not as a service) under another user profile?

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

  • Developers

interesting.

is there a way to run a script (not as a service) under another user profile?

What do you exactly want to do with this ? Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

What do you exactly want to do with this ?

well.. i just want my file to run under the SYSTEM username. i could care less if its a service.

reasons?

i dont want people on my computer closing the script i have running.

it runs at all times and if it closes i lose data.

if its not on my username they will be less likely to close it.

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

:( You have been around long enough to know this shit by now @t0ddie. I know you don't find this comment very helpful. but hey please come on!!!! There is a really handy search link in the upper right corner of my page. Is it missing in yours? :shocked:
Link to comment
Share on other sites

:( You have been around long enough to know this shit by now @t0ddie. I know you don't find this comment very helpful. but hey please come on!!!! There is a really handy search link in the upper right corner of my page. Is it missing in yours? :shocked:

i did a search and it came up with runasset() func but appearantly its broken?

otherwise i would not have posted.

thanks uten. while i did not find that very helpful, i also did not find it offending or negative.

perhaps you were unaware that runasset() is broken?

i have not tried runasset yet as i am heading out to go to work... but after reading the posts in my search there was no fix yet so... :P

nice usage of the word "shit" btw

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

  • Developers

i did a search and it came up with runasset() func but appearantly its broken?

otherwise i would not have posted.

thanks uten. while i did not find that very helpful, i also did not find it offending or negative.

perhaps you were unaware that runasset() is broken?

i have not tried runasset yet as i am heading out to go to work... but after reading the posts in my search there was no fix yet so... :shocked:

nice usage of the word "shit" btw

How did you come to the conclusion that RunAsSet() is broken.

.. and if you conclude that, why not report your "real" problem in stead of trying to make a Mickey-mouse solution?

Now, don't go run of and post a Bug-report, but post the "real" problem you have here....

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

....Or at least add a link to the topic claiming RunAsSet is broken. Every time I have experienced problems with RunAsSet it has been due to my own ignorance of how it works.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...