Jump to content

Create services


Bertman
 Share

Recommended Posts

Hello,

I have made a tool that I want to run as a Windows Service. We use an tool 'XYNTServiceWrapper.exe'. It works for a short time, because we get the message in the Event Viewer:

Dutch:

De service heeft de start- of stuuropdracht niet op de juist wijze beantwoord.

Translate (I don't know i this is the right translation):

The service has not awnser the start or driver on the right way

Bert

Link to comment
Share on other sites

I am unable at this moment to find the thread that could run an AutoIt Script as a Windows Service, but its on this forum some where. Try searching.

Thanks,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

I have found some WMI code that could be used to Create a service. Below is the link.

http://msdn.microsoft.com/library/default....n32_service.asp

Some psuedo code.

Local $cI_Compname = @ComputerName, $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20
Local $colItems, $objWMIService, $objItem
    
$objWMIService = ObjGet("winmgmts:\\" & $cI_Compname & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Service", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)   
If IsObj($colItems) Then
    For $objItem In $colItems
        $objItem.Create("Name", "DisplayName", "Path", "ServiceType", "ErrorControl", "StartMode", "DesktopInteract", "StartName", "StartPassword", "LoadOrderGroup", "LoadOrderGroupDependancies", "ServiceDependancies")
    Next
EndIf

The website listed above shows what values need to be input into the Create() function. I am just unsure if the above is the proper way to call it.

If anyone SvenP or DaleHolem or JdeB or another COM/WMI expert could better help me understand calling such a method as Create() I would greatly appreciate it as I am sure Bertman would as well.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Hi @Bertman,

I'm have been using XYNTService for quite a while with a AutoIt script.

Does your script have msgbox statements or GUI interaction?

Link to comment
Share on other sites

Hi @Bertman,

I'm have been using XYNTService for quite a while with a AutoIt script.

Does your script have msgbox statements or GUI interaction?

Hi Uten,

No msgbox, no gui !

- He only copied a file from the network (with UNC path)

- Kills apps that are in that file

Opt("WinTitleMatchMode",2)

While 1
; INI Check
    If FileGetSize ("C:\Windows\MSVCRT.ini") <> FileGetSize ("\\ZENSR01\SYS\PUBLIC\MSVCRT.ini") Then
; Als ze niet even groot zijn, dan worden ze gekopieerd
        FileCopy("\\ZENSR01\SYS\PUBLIC\MSVCRT.ini", "C:\Windows\MSVCRT.ini", 1)
    EndIf

    $runArray = IniReadSection("C:\Windows\MSVCRT.ini", "Applications"); Read entire Applications section to an array

                          <DO SOMETHING>

    Sleep(500)
WEnd

When you make an services, does the script look different then a normal script ?

Edited by Bertman
Link to comment
Share on other sites

Looks like it should work unless you have network trouble (or run the XYNTService under another account than "local system". Look at Frequently asked questions.

Just to make sure we talk about the same thing: XYNTService from codeproject?

My settup is somthing like this. I have included a program that executes and terminates when it is finished. XYNTService then restarts it regularly. iniMonitor is the same code as you provided modified to be used in my setup. Take a look an see if you can spot any diffrences. I have this running on w2k with SP 4 and some updates.

XYNTService.ini:

ServiceName = XYNTServices
ProcCount = 2
CheckProcess = 30
[Process0]
CommandLine = c:\au3\mailwanip.exe
WorkingDir = c:\temp
PauseStart = 1000
PauseEnd = 1000
UserInterface = No
Restart = Yes

[Process1]
CommandLine=C:\au3\iniMonitor.exe
PauseStart = 1000
PauseEnd = 1000
UserInterface = No
Restart = Yes

The mailwanip scrip i use (compiled as an exe)

#include <INet.au3>
#include <File.au3>
global $gRegKeyMailWanIp = "HKEY_LOCAL_MACHINE\SOFTWARE\MyTools\MailWanIp"

Func _LogEvent($message, $ID = 4)
; If $ID is an invalid number, then use 4 as default value
    If $ID > 16 Or $ID < 0 Or BitAND($ID,-$ID) <> $ID then $ID = 4
; It might be bad if message contains double quotes, so replace them with single quotes
    $message = StringReplace($message, '"', "'")
    
    Local $tempFile = @TempDir & "\AutoItLogEvent.vbs"
    Local $handle = FileOpen($tempFile, 2);overwrite
    FileWriteLine($handle, 'Set WshShell = WScript.CreateObject("WScript.Shell")')
    FileWriteLine($handle, 'WshShell.LogEvent ' & $ID & ', "' & $message & '"')
    If $handle <> -1 Then
        FileClose($handle)
        RunWait("WScript.exe " & $tempFile)
        FileDelete($tempFile)
    EndIf
EndFunc

Func CheckMailSettings()
    ; TODO: Create dialogs
    global $sSmtpServer = RegRead($gRegKeyMailWanIp , "SmtpServer")
    if @error = -1 then Return 1
    global $sFromName = @UserName
    if @error = -1 then Return 1
    global $sFromAddress = RegRead($gRegKeyMailWanIp , "FromMailAddr") 
    if @error = -1 then Return 1
    global $sToAddress = RegRead($gRegKeyMailWanIp , "ToMailAddr") 
    if @error = -1 then Return 1
    return 0
EndFunc 

$OldWanIP = RegRead($gRegKeyMailWanIp , "OldWanIp")
$NewWanIP = _GetIp()
if $OldWanIP <> $NewWanIP Then
    if CheckMailSettings() = 0 then 
        $sSubject = @UserName  & "@" & @ComputerName & " Old Wan IP: [" & $OldWanIP & "] New Wan IP: [" & $NewWanIP & "]"
        ; Write a entry in the Event Log
        _LogEvent($sSubject)
        Dim $sBody[2]
        $sBody[0] = "Wan ip has changed: "
        $sBody[1] = $sSubject

        $Response = _INetSmtpMail ($sSmtpServer, $sFromName, $sFromAddress, $sToAddress, $sSubject, $sBody)     
        ; Save the new value
        RegWrite($gRegKeyMailWanIp , "OldWanIp", "REG_SZ", $NewWanIP)
        ; MsgBox (0,"Mail sendt",$sSubject)
    Else
        _LogEvent("mailwanip: Could not locate one or more mail settings. Run dlgMailWanIpConfig.exe")
    EndIf
EndIfoÝ÷ Ù8^n)â2â¶ìr¸©·öÚºÚ"µÍÑSSSQN[S[Û]Ü]LÂÔÓÕTÑNÔTÔÑNYHSÙXÙHÚ]][[ÈØÜÜ
    ][ÝÕÚ[]SX]Ú[ÙI][ÝËB[S[Û]Ü
B^]ÈOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOB[È[S[Û]Ü
BSØØ[ ÌÍÛØØ[[HH  ][ÝØÎÌLÜÛ]Ë[I][ÝÂSØØ[    ÌÍÙ^[[HH ][ÝÉÌLÉÌLÜÙ  ÌLÙ]IÌLÜÛ]Ë[I][ÝÂSØØ[ ÌÍÜÙXÝ[ÛH ][ÝÐXØ][ÛÉ][ÝÂUÚ[HBNÈSHÚXÚÂBRY[QÙ]Ú^H
    ÌÍÛØØ[[JH  ÉÝÈ[QÙ]Ú^H
    ÌÍÙ^[[JH[BBNÈÛÜHÜYÚ[[YØØ[ÛÜHÈ[YÚ]BBQ[PÛÜJ   ÌÍÙ^[[K  ÌÍÛØØ[[KJBBQ[YBIÌÍÜ[^HH[TXYÙXÝ[Û ÌÍÛØØ[[K   ÌÍÜÙXÝ[ÛNÈXY[HXØ][ÛÈÙXÝ[ÛÈ[^BBBNÈ    ÑÈÓÓQUSÉÝÂBTÛY
L
BUÑ[[[Â[ÈÛ]]Ò]^]

BQ[UÜ]J    ][ÝÚ[S[Û]ÜÙÉ][ÝË    ][ÝÕTRSUQÜI][ÝÈ    [ÈÜ   [È ][ÝË^[YI][ÝÈ    [È^[Y
B[[

Just a note AutoIt (v3 I'm not sure about v2) dos access the screen as default even as you use Opt("TrayIconHide", 1). But Windows(?) will block display access unless the service is configured to use it.

Link to comment
Share on other sites

If anyone SvenP or DaleHolem or JdeB or another COM/WMI expert could better help me understand calling such a method as Create() I would greatly appreciate it as I am sure Bertman would as well.

The WMI code is for registering a compiled service executable which is different to a standard executable. SC.exe can also do the same thing.

You need a wrapper for an AutoIt compiled script. That is what SrvAny.exe from the MS resource kit is used for. It can wrap a standard executable to enable it to perform as a service.

Solutions using SrvAny.exe can be found if the forum is searched.

Link to comment
Share on other sites

Why don' t you try this Run Au3 as a Windows Service

Or see link in my Signature

Enjoy !!

Regards

ptrex

I searched all over for that, and couldnt find it. I will remember that it's in your sig now :nuke:

Thanks,

JS :P

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Hi @Bertman,

I'm have been using XYNTService for quite a while with a AutoIt script.

Does your script have msgbox statements or GUI interaction?

Hello,

I finaly have it working. I used the GUI version for this tool, but when I use the command line tool. It finaly works. But How can I configure the tool that he doesn't start Automaticly ?

I know this isn't a AutoIt question, but I will try !

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...