Jump to content

Showing "Application as service"


chachew
 Share

Recommended Posts

Ok so im trying to automate an app running as a service. I am using ServiceShell to make a standard app run as a windows service. That seems to be working fine because the service starts and i can see that its running by looking at task manager/Processes

The service says its running under the SYSTEM user. Naturally this is hidden from view so my real question is once my script runs and starts the app as a service is there a way to @sw_show the application.

Opt("TrayIconDebug", 1)  ; Puts debug in the tooltip
Run("C:\Atandra\T-HUB10\Turbo.THUB.UIProcessing.exe")
While 1
If Not WinExists("Login", "") Then
sleep(50)
Else
Do
  ControlClick("Login", "&Login", "[CLASSNN:WindowsForms10.BUTTON.app.0.3ce0bb81]")
  sleep(500)
Until Not WinExists("Login", "")
ExitLoop
EndIf
sleep(1000)
WEnd

This is the EXE that is being run as a service, ultimately i would like to have the last "Sleep(1000)" piece of code actually make the application visible to the user logged in, or can i not do this?

Link to comment
Share on other sites

  • Moderators

Hi, chachew. I have done something similar in the past, to create a tooltip utility that starts as a service. As it runs as System, in order to make it visible to the logged in user you need to check the option to interect with the desktop in the services console. I ended up using Microsoft's SRVANY.exe, which makes the creation of the service a bit easier.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I have had this issue before too.

I had to use a free app called srvany and have the service point to that. I then create a reg key:

RegWrite("HKLMSYSTEMCurrentControlSetServicesServiceNameParameters", "Application", "REG_SZ", "C:WindowsSystem32AppLocation.exe")

This then allows my script to run.

The srvany file can be found via this link:

http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

Hope that helps.

Link to comment
Share on other sites

@jazzyjeff Yea i have tried the Srvany.exe and the problem i was running into was that when the service tries to start, the "Interactive Services Detection" service kicks in and wants my to "View" the process and interact with it..

@JLogan I also tried this and that kind of produces the same issue as stated above with jazzyjeff. If i turn that off, service straight up fails. When ON i get the "View Details" message.

With this ServiceShell app i can sucessfully get the service created and it will start/stop normally without issues. I just need to figure out how to "Show" it. @JLogan, how were you able to show the gui via tooltip that you were referring too?

Link to comment
Share on other sites

  • Moderators

Hi, chachew. In my case, the utility sat in the system tray, just something the customer wanted so users could click on the image and be able to relay system information to their Helpdesk (I don't ask, I just do what they pay me to do). Below is the code. I just compiled this code, then wrapped it with SRVANY to make it start on login, once the system detects "explorer.exe" running, otherwise the service tried to start too soon and returned rubbish.

#NoTrayIcon
#include <GUIConstantsEx.au3>

Opt("TrayMenuMode", 3)
$strComputer = @ComputerName
Global $strNameOfUser
Global $strUserDomain
Global $_user
Global $_domain

;On Startup, wait until the Process "explorer.exe" exists in the Logged In User context.
ProcessWait("explorer.exe")

;Call the _WMI function to return the Logged In User's Name and Domain.
_WMI()

Func _WMI()

$objWMIService = ObjGet("winmgmts:" _
    & "{impersonationLevel=impersonate}!" _
    & $strComputer & "rootcimv2")

$colProcessList = $objWMIService.ExecQuery _
    ("Select * from Win32_Process")

For $objProcess in $colProcessList
  $colProperties = $objProcess.GetOwner( _
   $strNameOfUser,$strUserDomain)

  If $objProcess.Name = "explorer.exe" Then
   _test()
 
  EndIf

Next

EndFunc

;Called by _WMI function. This function actually create the System Tray icon, using data gathered by WMI call.
 
Func _test()

TrayCreateItem("Account: " & $strNameOfUser)
TrayCreateItem("Hostname: " & @ComputerName)
TrayCreateItem("Domain: " & $strUserDomain)
TrayCreateItem("Resolution: " & @DesktopWidth & "x" & @DesktopHeight)
TrayCreateItem("")

$aboutItem  = TrayCreateItem("About")

TraySetState()

TraySetToolTip("Helpdesk Utility")

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutItem
            Msgbox(64,"About","Helpdesk Tooltip Utility" & @CRLF & "Version 0.1b, September 2011")
  Case $msg = $GUI_EVENT_CLOSE
   Exit
    EndSelect
WEnd

EndFunc

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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