rejetto forum

Run as a service + see GUI on logon [How-to]

cmatte · 5 · 4863

0 Members and 1 Guest are viewing this topic.

Offline cmatte

  • Occasional poster
  • *
    • Posts: 31
    • View Profile
    • ErMeglio WebSite
Hi,
I'm looking for a way to both launch HFS as a service cleanly and then see the HFS GUI on user logon.
I'm at the point in which I can run HFS as a service with the cool LeDuFe application.
HFS service is in fact reachable but I can't check the GUI (as expected) and I also have an annoying warning from Windows Vista (x86) saying an app isn't able to show a message in the current environment and proposes me to switch to an isolated environment in which I can see only the HFS main window. I can tell it to show the message later but it's annoying!
This is the Window I am speaking of:


I managed not to let it appear un-ticking the option "Let the application interact with the desktop" under Services.
Ok, let's say this is acceptable, how to show the HFS GUI on logon?
I thought about a batch file stopping the service and opening the HFS.exe executable, I've written this simple one:
Code: [Select]
@echo off
net stop HFS-Service
E:\HFS\hfs.exe
net start HFS-Service
with the last line I -hope- it just starts the service again when I close the session and/or HFS GUI.
This batch is run under another 3rd party application, Hidden Start, to hide the bad black console.

So, currently it correctly stops the service and opens the HFS gui BUT it doesn't seem to start the service again when I close the session. Instead it correctly starts the service if I close the HFS GUI.
Is there some sort of "Run as logoff" way to separate the two things or other similar advices to let it work?
« Last Edit: October 12, 2008, 12:06:37 PM by cmatte »


Offline MarkV

  • Tireless poster
  • ****
    • Posts: 764
    • View Profile
you have to change the .bat file:

Code: [Select]
@echo off
net stop HFS-Service
start /wait E:\HFS\hfs.exe
net start HFS-Service

One of the basic security changes in Vista is that users now run in a different context than services: users 1, services 0. See the 'Session ID' column of task manager.

The downside is that services are no longer able to interact with the desktop. HFS would need to be split into a service part and a GUI wrapper to get around that.

Is there some sort of "Run as logoff" way to separate the two things or other similar advices to let it work?
Maybe with the task scheduler? Schedule to start the service every 10 minutes or so. If already started the command will be ignored but if not it will be started.

You should not use the 'net' command, use the 'sc' command to interact with services.
« Last Edit: October 12, 2008, 01:36:22 PM by MarkV »
http://worldipv6launch.org - The world is different now.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
an app isn't able to show a message in the current environment and proposes me to switch to an isolated environment in which I can see only the HFS main window. I can tell it to show the message later but it's annoying!

what if you accept? wouldn't it be what you need?

Quote
I managed not to let it appear un-ticking the option "Let the application interact with the desktop" under Services.

what's the problem of using this feature?


Offline cmatte

  • Occasional poster
  • *
    • Posts: 31
    • View Profile
    • ErMeglio WebSite
@MarkV
Mmh just did the changes with no luck: it still doesn't start the service when I log off...I guess it's because that Hidden Start app is closed BEFORE the batch can finish its duties.
The scheduler could be a solution, not that clean but I guess it would work, I'll check out if it can constantly check for the presence of HFS.exe or the HFS-Service and start the latter if none is found.
@rejetto
Well, perhaps I didn't explain that good: if I accept yes, I can see the HFS GUI, but:
1)When I say environment, I mean ALL: I have to say goodbye to my desktop and apps I'm using just to see only HFS in a old-style scary desktop.When I'm in that environment I have to click "terminate now" on that win95 style window to return to my desktop again.Then I'd see the annoying message again because HFS is not reduced to icon/closed anyway and always tries to ""show a message"".Also, this way I can't constantly check what's on when I'm logged in: connections, downloads, uploads.All this isn't convenient at all :-\
2)If I don't need HFS I can close that window and forget about it, but only for "some" minutes, then it appears again.Instead if I have to check the GUI arbitrarily I can't, because I've to wait those minutes.The alternative is to toggle the desktop interaction as I said and that window doesn't show up ever again, I'll have no gui at all then.
Hope I've been clearer, if not I'll explain in Italian ok ;D

@all
About LeDuFe utility, do I need to set its GUI at startup to see the tray icon? If yes, can I open it directly in tray?
--edit--
[SOLVED]: Just made a shortcut to it, put in Startup folder, and in properties I've set to start minimized, this did the trick!
--end edit--

I'll be back when I've checked the scheduler, thanks for now ;)
« Last Edit: October 12, 2008, 06:16:43 PM by cmatte »


Offline cmatte

  • Occasional poster
  • *
    • Posts: 31
    • View Profile
    • ErMeglio WebSite
Hi,
the scheduler seemed too complex for me :-\
I really couldn't find what to insert when it asked for IDs, I could take the ID corresponding with the service-stop but I noticed an Event ID of a service-stop is a generic one of that type, the same for all service-stops, so it was not that helpful!
Instead I decided to start the development of a ALWAYS-ON batch which checks for the hfs presence and starts the service if needed.
I'm not that good at writing in batch, so please give me some advices...
The problem I'm having is -only- about the logs: it simply doesn't log a successful service start and I really don't understand why...could be just that here it's TOOOO late to be still fresh ;D
Here it is my code, if you can give it a watch...I think it could be useful for many people and also ready to further developments (user login detection to decide if open the service or the normal exe and read of the log file position from hfs.ini for example):
Code: [Select]
@echo off
echo Copyright by ErMeglio!!! Feel free to use for private purposes only xD. Visit http://ermeglio.co.cc
:START
for /f "tokens=1,2,3 delims=/" %%i in ('echo %date%') do (
set day=%%i
set month=%%j
set year=%%k
)
REM ---user-defined variables---
set servicename=HFS-Service
set logA="D:\HFS logs\%year%\%month%\%day%-"
set logB="Always-OnLog.log"
set logS="ServiceStartLog.log"
set wait=15
REM ---end of user-defined variables---

echo [INFO]Check if HFS is running
tasklist | find "hfs.exe" | find /v /i "find"
if not .%errorlevel%.==.0. goto NOHFS

:SLEEP
echo [INFO]HFS is running: wait %wait% seconds and check again
ping 127.0.0.1 -n %wait% -w 1000 > nul
goto START

:NOHFS
echo [NOHFS]HFS isn't running: trying to start %servicename%
echo %date% %time% - There is a problem: HFS isn't running.Trying to start the service and check again in %wait% seconds. >> %logA%%logB% 2>>&1
net start %servicename% > nul > %logA%%logS% 2>>&1
if not .%errorlevel%.==.0. goto ERROR

:OK
echo [OK]The service %servicename% started correctly.Will continue checking.
echo %date %time% - The service %servicename% started correctly.Will continue checking in %wait% seconds. >> %logA%%logB% 2>>&1
del %logA%%logS%
goto START

:ERROR
echo [ERROR]It seems %servicename% didn't start normally.Please see logs.The check process will continue checking and trying to fix this in %wait% seconds.
echo %date% %time% - It seems %servicename% coulnd't start normally for some reasons, net-start log follows: >> %logA%%logB% 2>>&1
type %logA%%logS% >> %logA%%logB% 2>>&1
del %logA%%logS%
echo %date% %time% - The check process will continue checking and trying to fix this in %wait% seconds. >> %logA%%logB% 2>>&1
goto SLEEP
:END
Well, every log seems to be written correctly, except the one under the :OK, can someone find the bug in it?

Anyway when it's all done my idea is to do a scheduled start of this as soon as a user disconnects from its session. This should be enough. Instead when a user logs on I'm using the previous batch and it works. Theoretically this batch could be run also after logon because it checks for the hfs.exe presence, which includes the normal GUI! If I discover how to check when a user is logged on I'll integrate the ability to open up the GUI if it's the case.

Thanks for listening at a crazy one like me  8)