Jump to content
Sign in to follow this  
arcker

_Service_UDF v4 : Build your own service with autoit code

Recommended Posts

I got problems when I created a service with "$SERVICE_INTERACTIVE_PROCESS" type. Some installers were blocked. The installation GUIs would not come up to the screen until I stopped the service. This happened in Windows XP. It was tested fine in Windows 7. I also did tests on the two examples provided in this thread. One was the "AServiceMenu.au3" and the other one was "ServiceExample.au3" (with an updated InstallService() function. See code below). Both of the test services, when started, blocked the installers (One is a Toshiba laptop driver installer and another one is an installer in "PC Study Bible 3.1" CD). Does anybody know what is going on here and how to fix that?

Func InstallService()
    logPrint("InstallService(): Installing service, please wait")
    _Service_Create($sServiceName, "Autoit Service Test", BitOR($SERVICE_INTERACTIVE_PROCESS, $SERVICE_WIN32_OWN_PROCESS), $SERVICE_DEMAND_START, $SERVICE_ERROR_IGNORE,'"' & @ScriptFullPath & '"')
    If @error Then
        logPrint("InstallService(): Problem installing service, Error number is " & @error & @CRLF & " message : " & _WinAPI_GetLastErrorMessage())
    Else
        logPrint("InstallService(): Installation of service successful")
    EndIf
    Exit
EndFunc   ;==>InstallService

Share this post


Link to post
Share on other sites

The installations that are blocked uses Windows Installer ( msiexec.exe ? )

For me no problem so far since i don't use interactive processes. And my script is used to launch installations.

Maybe tour service is waiting something ? A callback need a response ? I don't know.


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

Hey there,

i've got a question: Is it possible to receive the SERVICE_CONTROL_PRESHUTDOWN status? The Function _Service_Ctrl only receive SERVICE_CONTROL_STOP and when I use the command _Service_Enum I can see, that the Autoit Test is just not able to accept preshutdown command (SERVICE_ACCEPT_PRESHUTDOWN)

Any Idea how I can see when the user just want to shutdown the PC?

Greetz

Spider


www.AutoIt.de - Moderator of the German AutoIt Forum

 

Share this post


Link to post
Share on other sites

What's your OS ?

From kb HandlerEx Callback:

SERVICE_CONTROL_PRESHUTDOWN
0x0000000F Notifies a service that the system will be shutting down. Services that need additional time to perform cleanup tasks beyond the tight time restriction at system shutdown can use this notification. The service control manager sends this notification to applications that have registered for it before sending a SERVICE_CONTROL_SHUTDOWN notification to applications that have registered for that notification. 

A service that handles this notification blocks system shutdown until the service stops or the preshutdown time-out interval specified through SERVICE_PRESHUTDOWN_INFO expires. Because this affects the user experience, services should use this feature only if it is absolutely necessary to avoid data loss or significant recovery time at the next system start.

[b][color="#ff0000"]Windows Server 2003 and Windows XP/2000:  This value is not supported.[/color][/b]

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

My small contribution:

just yesterday I was need give quick solution as service. I could do it with C#, but decide to use autoit - works as charm.

job every 20 seconds check if in status.txt flag is 1 then it run external program, if external program already run or flag is 0 continue to next check

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=beta
#AutoIt3Wrapper_Icon=favicon.ico
#AutoIt3Wrapper_Outfile=..\..\..\..\Desktop\RunSync2service.exe
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Description=RunSync
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=© Greg
#AutoIt3Wrapper_Res_Field=RunSync|1.0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include "Services.au3"

Global $val
Local $status
Global $Paused
Global $sServiceName = "psync"
Global $MainLog = @ScriptDir & "\services_test.log"


Opt("TrayIconHide", 1) ;- hide tray

_Service_init($sServiceName)

Func _Svc_Main()
    ;logPrint("main start")
    While 1
        Sleep(20000)
        ConsoleWrite("1")
        If ProcessExists("s3syncconsole.exe") Then ContinueLoop

        ;logPrint("read status")
        $status = ReadStatus()


        If $status = 0 Then
            ContinueLoop
        Else Then ;sync new/updated
            ;logPrint("update status")
            UpdateStatus()
            ;logPrint("start sync")
            $val = RunWait("c:\s3sync\s3syncconsole.exe 0")
            ;logPrint("finish sync")
        EndIf
    WEnd
EndFunc   ;==>_Svc_Main

Func logPrint($text, $nolog = 0)
    If $nolog Then
        MsgBox(0, "MyService", $text, 1)
    Else
        If Not FileExists($MainLog) Then FileWriteLine($MainLog, "Log created: " & @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC)
        FileWriteLine($MainLog, @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC & " [" & @AutoItPID & "] >> " & $text)
    EndIf
    Return 0
EndFunc   ;==>logPrint


Func ReadStatus()
    $file = FileOpen("c:\inetpub\wwwroot\sn2\status.txt", 0)
    If $file = -1 Then
        Exit
    EndIf
    Local $command = FileReadLine($file)
    FileClose($file)

    Return $command
EndFunc   ;==>ReadStatus

Func UpdateStatus()
    $file = FileOpen("c:\inetpub\wwwroot\sn2\status.txt", 2)
    If $file = -1 Then
        Exit
    EndIf
    FileWriteLine($file, "0")
    FileClose($file)
EndFunc   ;==>UpdateStatus

Share this post


Link to post
Share on other sites

By chance has anyone had luck with gui interaction? I'm trying to run the Cisco AnyConnect client on boot. And at one point it has a gui popup to accept the certificate. the rest is all command line interaction. :unsure:

Share this post


Link to post
Share on other sites

Windows services cannot have a GUI.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

By chance has anyone had luck with gui interaction? I'm trying to run the Cisco AnyConnect client on boot. And at one point it has a gui popup to accept the certificate. the rest is all command line interaction. :unsure:

I found out how to add the certificate so that this prompt no longer occurs. Issue is, it's still not running properly. I have a line between each command to write to a textfile. Each line is being written, but the vpn is not coming up.

$list = ProcessList("vpncli.exe")
for $i = 1 to $list[0][0]
    Process Close( $list[1][1] )
Next

ShellExecute("vpncli.exe", "connect xxx.xx.x.xx ", "C:\Program Files\Cisco\Cisco AnyConnect VPN Client\","open")
sleep(3000)
$activate_status = WinActivate("C:\Program Files\Cisco\Cisco AnyConnect VPN Client\vpncli.exe")
send("username{enter}")

sleep(2000)
$activate_status = WinActivate("C:\Program Files\Cisco\Cisco AnyConnect VPN Client\vpncli.exe")
send("password{enter}")

Im wondering the vpncli still does something that isnt service friendly. When you run it, you get a sub prompt like:

VPN>

Theres then a small command set to connect,disconnect or look at information.

Edited by SmOke_N

Share this post


Link to post
Share on other sites

I tried the ServiceExample.au3 and it compiles fine with an older version of Autoit, but with then I tried it on Version 1.79 and got these errors below.

Has anyone else ran into this?

D:\My Documents\Autoit\Service\TestSrv.au3(32,57) : WARNING: $service_stop_event: possibly used before declaration.

logPrint("main_init. Stop event=" & $service_stop_event)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\My Documents\Autoit\Service\TestSrv.au3(51,29) : WARNING: $gServiceStateRunning: possibly used before declaration.

While $gServiceStateRunning

~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\My Documents\Autoit\Service\TestSrv.au3(32,57) : ERROR: $service_stop_event: undeclared global variable.

logPrint("main_init. Stop event=" & $service_stop_event)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\My Documents\Autoit\Service\TestSrv.au3(29,28) : ERROR: _Service_init(): undefined function.

_Service_init($sServiceName)

~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\My Documents\Autoit\Service\TestSrv.au3(50,82) : ERROR: _WinAPI_WaitForSingleObject(): undefined function.

logPrint("main loop. evnt=" & _WinAPI_WaitForSingleObject($service_stop_event, 0)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\My Documents\Autoit\Service\TestSrv.au3(87,19) : ERROR: _Service_Cleanup(): undefined function.

_Service_Cleanup()

~~~~~~~~~~~~~~~~~^

D:\My Documents\Autoit\Service\TestSrv.au3(105,140) : ERROR: _WinAPI_GetLastErrorMessage(): undefined function.

logPrint("InstallService(): Problem installing service, Error number is " & @error & @CRLF & " message : " & _WinAPI_GetLastErrorMessage()

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\My Documents\Autoit\Service\TestSrv.au3 - 5 error(s), 2 warning(s)

Share this post


Link to post
Share on other sites

I found out how to add the certificate so that this prompt no longer occurs. Issue is, it's still not running properly. I have a line between each command to write to a textfile. Each line is being written, but the vpn is not coming up.

$list = ProcessList("vpncli.exe")
for $i = 1 to $list[0][0]
    Process Close( $list[1][1] )
Next

ShellExecute("vpncli.exe", "connect xxx.xx.x.xx ", "C:\Program Files\Cisco\Cisco AnyConnect VPN Client\","open")
sleep(3000)
$activate_status = WinActivate("C:\Program Files\Cisco\Cisco AnyConnect VPN Client\vpncli.exe")
send("username{enter}")

sleep(2000)
$activate_status = WinActivate("C:\Program Files\Cisco\Cisco AnyConnect VPN Client\vpncli.exe")
send("password{enter}")

Im wondering the vpncli still does something that isnt service friendly. When you run it, you get a sub prompt like:

VPN>

Theres then a small command set to connect,disconnect or look at information.

I use vpncli too, but no in a service.

But why do you use interactive answers ???? vpncli has a lot of paramaters that you can pass

run "vpncli /?" to see them.

Moreover, you don't have to use ShellExecute, try using run instead


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

why i can't add my code to "ServiceExample.au3"

#NoTrayIcon #AutoIt3Wrapper_UseUpx=n  Global $MainLog = @ScriptDir & "\services_test.log" Global $sServiceName = "AutoitTestService"  #include "Services.au3" #include <Timers.au3> ; i used it for timers func  logPrint("script started") If $cmdline[0] > 0 Then     Switch $cmdline[1]      Case "install", "-i", "/i"          InstallService()        Case "remove", "-u", "/u", "uninstall"          RemoveService()         Case Else           ConsoleWrite(" - - - Help - - - " & @CRLF)          ConsoleWrite("params : " & @CRLF)           ConsoleWrite(" -i : install service" & @CRLF)           ConsoleWrite(" -u : remove service" & @CRLF)            ConsoleWrite(" - - - - - - - - " & @CRLF)           Exit            ;start service.     EndSwitch EndIf _Service_init($sServiceName) MsgBox(0,"",$sServiceName)  Func main_init()   logPrint("main_init. Stop event=" & $service_stop_event) EndFunc   ;==>main_init  Func _Svc_Main()  main_init()     logPrint("main start")  logPrint("main loop. evnt=" & _WinAPI_WaitForSingleObject($service_stop_event, 0))  While $gServiceStateRunning ;~  While _WinAPI_WaitForSingleObject($service_stop_event, 0)       Sleep(1000)     WEnd    logPrint("main outer. evnt=" & _WinAPI_WaitForSingleObject($service_stop_event, 0))     _Service_Cleanup()  logPrint("main stopped.") EndFunc   ;==>main  Func logPrint($text, $nolog = 0)  If $nolog Then      MsgBox(0, "MyService", $text, 1)    Else        If Not FileExists($MainLog) Then FileWriteLine($MainLog, "Log created: " & @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC)        FileWriteLine($MainLog, @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC & " [" & @AutoItPID & "] >> " & $text)     EndIf   Return 0 EndFunc   ;==>logPrint  Func InstallService()  logPrint("InstallService(): Installing service, please wait")   _Service_Create($sServiceName, "Autoit Service Test", $SERVICE_WIN32_OWN_PROCESS, $SERVICE_DEMAND_START, $SERVICE_ERROR_IGNORE,'"' & @ScriptFullPath & '"')     If @error Then      logPrint("InstallService(): Problem installing service, Error number is " & @error & @CRLF & " message : " & _WinAPI_GetLastErrorMessage())     Else        logPrint("InstallService(): Installation of service successful")    EndIf   Exit EndFunc   ;==>InstallService  Func RemoveService()     _Service_Stop($sServiceName)    _Service_Delete($sServiceName)  If Not @error Then logPrint("RemoveService(): service removed successfully" & @CRLF)    Exit EndFunc   ;==>RemoveService  #cs   ...from MSDN:   The ServiceMain function should perform the following tasks:    Initialize all global variables.    Call the RegisterServiceCtrlHandler function immediately to register a Handler function to handle control requests for the service. The return value of RegisterServiceCtrlHandler is a service status handle that will be used in calls to notify the SCM of the service status.   Perform initialization. If the execution time of the initialization code is expected to be very short (less than one second), initialization can be performed directly in ServiceMain.  If the initialization time is expected to be longer than one second, call the SetServiceStatus function, specifying the SERVICE_START_PENDING service state and a wait hint in the SERVICE_STATUS structure.    If your service's initialization code performs tasks that are expected to take longer than the initial wait hint value, your code must call the SetServiceStatus function periodically (possibly with a revised wait hint) to indicate that progress is being made. Be sure to call SetServiceStatus only if the initialization is making progress. Otherwise, the Service Control Manager can wait for your service to enter the SERVICE_RUNNING state assuming that your service is making progress and block other services from starting. Do not call SetServiceStatus from a separate thread unless you are sure the thread performing the initialization is truly making progress.    When initialization is complete, call SetServiceStatus to set the service state to SERVICE_RUNNING.     Perform the service tasks, or, if there are no pending tasks, return control to the caller. Any change in the service state warrants a call to SetServiceStatus to report new status information.   If an error occurs while the service is initializing or running, the service should call SetServiceStatus to set the service state to SERVICE_STOP_PENDING if cleanup will be lengthy. After cleanup is complete, call SetServiceStatus to set the service state to SERVICE_STOPPED from the last thread to terminate. Be sure to set the dwServiceSpecificExitCode and dwWin32ExitCode members of the SERVICE_STATUS structure to identify the error. #ce

Share this post


Link to post
Share on other sites

why i can't add my code to "ServiceExample.au3"

#NoTrayIcon
#AutoIt3Wrapper_UseUpx=n

Global $MainLog = @ScriptDir & "\services_test.log"
Global $sServiceName = "AutoitTestService"

#include "Services.au3"
#include <Timers.au3> ; i used it for timers func

logPrint("script started")
If $cmdline[0] > 0 Then
    Switch $cmdline[1]
        Case "install", "-i", "/i"
            InstallService()
        Case "remove", "-u", "/u", "uninstall"
            RemoveService()
        Case Else
            ConsoleWrite(" - - - Help - - - " & @CRLF)
            ConsoleWrite("params : " & @CRLF)
            ConsoleWrite(" -i : install service" & @CRLF)
            ConsoleWrite(" -u : remove service" & @CRLF)
            ConsoleWrite(" - - - - - - - - " & @CRLF)
            Exit
            ;start service.
    EndSwitch
EndIf
_Service_init($sServiceName)
MsgBox(0,"",$sServiceName)

Func main_init()
    logPrint("main_init. Stop event=" & $service_stop_event)
EndFunc   ;==>main_init

Func _Svc_Main()
    main_init()
    logPrint("main start")
    logPrint("main loop. evnt=" & _WinAPI_WaitForSingleObject($service_stop_event, 0))
    While $gServiceStateRunning
;~  While _WinAPI_WaitForSingleObject($service_stop_event, 0)
        Sleep(1000)
    WEnd
    logPrint("main outer. evnt=" & _WinAPI_WaitForSingleObject($service_stop_event, 0))
    _Service_Cleanup()
    logPrint("main stopped.")
EndFunc   ;==>main

Func logPrint($text, $nolog = 0)
    If $nolog Then
        MsgBox(0, "MyService", $text, 1)
    Else
        If Not FileExists($MainLog) Then FileWriteLine($MainLog, "Log created: " & @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC)
        FileWriteLine($MainLog, @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC & " [" & @AutoItPID & "] >> " & $text)
    EndIf
    Return 0
EndFunc   ;==>logPrint

Func InstallService()
    logPrint("InstallService(): Installing service, please wait")
    _Service_Create($sServiceName, "Autoit Service Test", $SERVICE_WIN32_OWN_PROCESS, $SERVICE_DEMAND_START, $SERVICE_ERROR_IGNORE,'"' & @ScriptFullPath & '"')
    If @error Then
        logPrint("InstallService(): Problem installing service, Error number is " & @error & @CRLF & " message : " & _WinAPI_GetLastErrorMessage())
    Else
        logPrint("InstallService(): Installation of service successful")
    EndIf
    Exit
EndFunc   ;==>InstallService

Func RemoveService()
    _Service_Stop($sServiceName)
    _Service_Delete($sServiceName)
    If Not @error Then logPrint("RemoveService(): service removed successfully" & @CRLF)
    Exit
EndFunc   ;==>RemoveService

#cs
    ...from MSDN:
    The ServiceMain function should perform the following tasks:

    Initialize all global variables.
    Call the RegisterServiceCtrlHandler function immediately to register a Handler function to handle control requests for the service. The return value of RegisterServiceCtrlHandler is a service status handle that will be used in calls to notify the SCM of the service status.
    Perform initialization. If the execution time of the initialization code is expected to be very short (less than one second), initialization can be performed directly in ServiceMain.
    If the initialization time is expected to be longer than one second, call the SetServiceStatus function, specifying the SERVICE_START_PENDING service state and a wait hint in the SERVICE_STATUS structure.

    If your service's initialization code performs tasks that are expected to take longer than the initial wait hint value, your code must call the SetServiceStatus function periodically (possibly with a revised wait hint) to indicate that progress is being made. Be sure to call SetServiceStatus only if the initialization is making progress. Otherwise, the Service Control Manager can wait for your service to enter the SERVICE_RUNNING state assuming that your service is making progress and block other services from starting. Do not call SetServiceStatus from a separate thread unless you are sure the thread performing the initialization is truly making progress.

    When initialization is complete, call SetServiceStatus to set the service state to SERVICE_RUNNING.
    Perform the service tasks, or, if there are no pending tasks, return control to the caller. Any change in the service state warrants a call to SetServiceStatus to report new status information.
    If an error occurs while the service is initializing or running, the service should call SetServiceStatus to set the service state to SERVICE_STOP_PENDING if cleanup will be lengthy. After cleanup is complete, call SetServiceStatus to set the service state to SERVICE_STOPPED from the last thread to terminate. Be sure to set the dwServiceSpecificExitCode and dwWin32ExitCode members of the SERVICE_STATUS structure to identify the error.
#ce
Edited by jakalspop

Share this post


Link to post
Share on other sites

I've modified the default _Blank_v2.au3 like this

#include "Services.au3"
#include <Misc.au3>

#NoTrayIcon
#RequireAdmin
#AutoIt3Wrapper_Change2CUI=y

If Not @Compiled Then Exit
If Not _Singleton(@ScriptName) Then
    If $cmdline[0] > 0 Then
        If $cmdline[1] = "stop" or StringRight($cmdline[1],1) = "s" Then

        Else
            ConsoleWrite("Process is running.")
            Exit
        EndIf
    Else
        ConsoleWrite("Process is running.")
        Exit
    EndIf
EndIf

$sServiceName = "MyService"
$sServiceDisplayName = "MyService"

If $cmdline[0] > 0 Then
    Switch $cmdline[1]
        Case "install", "-i", "/i"
            InstallService()
        Case "remove", "-u", "/u", "uninstall"
            RemoveService()
        Case "run", "-r", "/r", "start"
            _SelfRun($sServiceName,"start")
        Case "stop", "-s", "/s"
            _SelfRun($sServiceName,"stop")
        Case Else
            ConsoleWrite(" - - - Help - - - " & @crlf)
            ConsoleWrite(" Service Example Params : " & @crlf)
            ConsoleWrite("  -i : Installs service" & @crlf)
            ConsoleWrite("  -u : Removes service" & @crlf)
            ConsoleWrite("  -r : Runs the service" & @crlf)
            ConsoleWrite("  -s : Stops the service" & @crlf)
            ConsoleWrite(" - - - - - - - - " & @crlf)
            Exit
            ;start service.
    EndSwitch
    _Service_Init($sServiceName)
Else
    If Not _Service_Exists($sServiceName) Then
        If Msgbox(20,"Service Not Installed.","Would you like to install this service?" & @CRLF & $sServiceName) = 6 Then
            If InstallService() Then
                If Msgbox(4,$sServiceName,"Service Installed Successfully." & @CRLF & "Do you wish to start the process?") = 6 Then _SelfRun($sServiceName,"start")
                EndIf
            Else
                Exit
        EndIf
    Else
        _Service_Init($sServiceName)
    EndIf
EndIf

Func Main()
    While 1
        ;Service Code Loop
        sleep(10)
    WEnd
EndFunc   ;==>main

Func InstallService()
    ConsoleWrite("Installing Service, Please Wait" & @CRLF)
    _Service_Create($sServiceName,$sServiceDisplayName,$SERVICE_WIN32_OWN_PROCESS,$SERVICE_DEMAND_START, $SERVICE_ERROR_SEVERE, '"' & @ScriptFullPath & '"')
    If @error Then
        ConsoleWrite("Problem Installing Service, Error number is " & @error & @CRLF & " message  : " & _WinAPI_GetLastErrorMessage())
        Return 0
    Else
        ConsoleWrite("Installation of Service Successful")
    EndIf
    Return 1
    Exit
EndFunc   ;==>InstallService

Func RemoveService()
    _Service_Stop($sServiceName)
    _Service_Delete($sServiceName)
    if not @error then ConsoleWrite("Service Removed Successfully" & @crlf)
    Exit
EndFunc   ;==>RemoveService

Func _SelfRun($servicename,$action)
    $sCmdFile = 'sc ' & $action & ' "' & $servicename & '"'
    Run($sCmdFile, @TempDir, @SW_HIDE)
    Exit
EndFunc

The behavior of the code is as follows

  • When I install the service by clicking on the messagebox, it installs successfully
  • But, if I hit "YES" on the second messagebox to agree to start the service or even start the service from services.msc, it starts with an ERROR sound (the default XP notification sound indication that something has gone wrong), but nothing is displayed on-screen.
  • If I try to stop the service, it takes a minute, shows a progress bar & then displays this error message: "Could not stop the MyService service on local computer. Error 1053: The service did not respond to the start or control request in a timely fashion."
I've tried both by compiling as a CONSOLE & NON-CONSOLE application. the results were the same. Can anybody please point out the error?

[size="2"][font="arial, verdana, tahoma, sans-serif"]ProtectData - A Data Protection software for floppies[/font][/size] [size="2"][hr][/size][size="2"]Sessionchange - A Windows service capable of tracking session change events[/size][size="2"][b][/b][/size]

Share this post


Link to post
Share on other sites

I use vpncli too, but no in a service.

But why do you use interactive answers ???? vpncli has a lot of paramaters that you can pass

run "vpncli /?" to see them.

Moreover, you don't have to use ShellExecute, try using run instead

Are you using the Cisco VPN Client? Because yes that was the case. But with the Cisco Anyconnect (old one doesnt work on win 2k8) all you get with /? is: connect, disconnect, hosts, stats, state, help, version, exit.

I have switched ShellExecute to run a bit back now.

Share this post


Link to post
Share on other sites

Are you using the Cisco VPN Client? Because yes that was the case. But with the Cisco Anyconnect (old one doesnt work on win 2k8) all you get with /? is: connect, disconnect, hosts, stats, state, help, version, exit.

I have switched ShellExecute to run a bit back now.

Yes i was talking about cisco vpn client.

What about run "vpncli connect /? "


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

Yes i was talking about cisco vpn client.

What about run "vpncli connect /? "

It interprets /? as a hostname haha. You can run vpncli. then type: help connect. It just says usage: connect [host]

Share this post


Link to post
Share on other sites

@arcker

I'm using your UDF to build a service & here is code snippet

Func _Svc_Main()
    .
    .
    .
    <Do something>
    .
    .
    .
    Sleep(2000)
    _SelfRun($sServiceName,"stop")
    WEnd
    _Service_Cleanup()
EndFunc

In spite of inserting _SelfRun($sServiceName,"stop") , the service still runs where as I want the service to terminate itself after the job is done. Can you please tell me where am I making the mistake?

Edited by HolmesShelock

[size="2"][font="arial, verdana, tahoma, sans-serif"]ProtectData - A Data Protection software for floppies[/font][/size] [size="2"][hr][/size][size="2"]Sessionchange - A Windows service capable of tracking session change events[/size][size="2"][b][/b][/size]

Share this post


Link to post
Share on other sites

Hi,

I am using yours example for an NT Service and it works fine, but sometimes when the computer is starting up and logging on I'll get the message Error: Variable used without being declared. It is very random and not consistent.

In the _Svc_Main() section I have justed added very basic stuff.

Any help is appreciated.

I haved added this section, which shouldn't cause a problem:

Func _ReduceMemory($i_PID = -1)
    
    If $i_PID <> -1 Then
        Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Else
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    EndIf
    
    Return $ai_Return[0]
EndFunc;==> _ReduceMemory()

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By SgtHugoStiglitz
      HI people,
                        I got a questions, I maintain code in autoIT and every time I compile a new version or modification, Scite generate 2 folders. One folder is finish by released and the other is tentative. I try to make some google search, but never find answer would satisfied myself. The dev who was maintain it before were using AutoIt3Wrapper_GUI, and I don't know if it's related. I look both folder, but they seem pretty identical, but I would like to know what it's the difference between those to folder. Anyone have a clue?
    • By Rhidlor
      I don't have any experience compiling AutoIt scripts or know of any best practices regarding said scripts so I was wondering, what are some of the options for passing data to complied scripts? Here's an example of what I mean by "option": Writing data to a text file, then running a script which reads the data from that text file.
      Thanks!
      I apologize if this topic is a little lackluster
    • By Skeletor
      Hey All,
      Yes, this is an odd request. 
      But is there a way to bulk up the size of the compiled program? 
      I know many want to reduce it's size, but I want to increase it.
      What methods do you suggest?
    • By dimm
      Is it possible to compile script without any icon resources included?
      When I make exe it uses default system icon of current OS even if I compile as console application.
      On other versions of Windows it looks a little strange

       
      Update:
      It seems that the only way is remove icons from exe after compilation using resource editors like ResHacker.

       
      another bad solution:
      Using corrupted 35 bytes icon file. Windows can't load it and shows default system icon.
      #pragma compile(Icon, broken.ico) broken.ico
    • By Dreamfire
      Hi,
      Since today, exe's are being flagged as having a trojan by Windows Defender (Fuery.B!cl)
      Version:  3.3.14.3 - SciTE Version 3.7.3



       

×
×
  • Create New...