Hi Everyone,
I playing around with the windows desktop at the moment, and this is what I'm doing...
1. Boot windows
2. End explorer.exe (with Task manager) - so the desktop is no more (gone)
3. Run my little IWB program to start up explorer.exe
4. The desktop comes back again - as I expect.
Now in the registry, explorer.exe is listed as the program to start for a user upon startup, I changed this to run my little IWB program, which in turn runs explorer.exe.
But it doesn't start the desktop, instead it opens the file explorer screen, i.e. it shows the disk drives / folders etc - as though you had clicked on the yellow folder icon in the task bar.
Is this because explorer.exe needs to start as a service (which it is), and if so, how do you run an exe as a service? has anyone made a program run as a service from IWB?
Thanks,
Andy.
:)
What I have found so far...
I created a little program to open a console and wait for a key to be pressed before exiting:
openconsole
print
print
print " Press any key..."
print
print
do:until inkey$ <> ""
closeconsole
end
Next, I found and changed this code, which adds my little program to the list of services:
$Include "Windows.inc"
DEF SERVICES_ACTIVE_DATABASE,MyService,XB,ErMes,Display AS String
DEF Error,TagId,nSize,Arguments AS Uint
CONST SERVICE_ERROR_NORMAL = 0x1
CONST SERVICE_DEMAND_START = 0x3
CONST SERVICE_WIN32_OWN_PROCESS = 0x10
const SC_MANAGER_CREATE_SERVICE = 0x2
nSize = 255
MyService ="AndyNservice"
Display ="AndysNewService"
SERVICES_ACTIVE_DATABASE = "ServicesActive"
XB = "C:\\RunOnce\\andyservice.exe"
DECLARE IMPORT, CreateService ALIAS CreateServiceA(hSCManager AS UINT,lpServiceName AS POINTER,lpDisplayName AS POINTER,dwDesiredAccess AS INT,dwServiceType AS INT,dwStartType AS INT,dwErrorControl AS INT,lpBinaryPathName AS POINTER,lpLoadOrderGroup AS POINTER,lpdwTagId AS POINTER,lpDependencies AS POINTER,lp AS POINTER,lpPassword AS POINTER),INT
DECLARE IMPORT, OpenSCManager ALIAS OpenSCManagerA(lpMachineName AS POINTER,lpDatabaseName AS POINTER,dwDesiredAccess AS INT),INT
OPENCONSOLE
hSCManager = OpenSCManager(0,SERVICES_ACTIVE_DATABASE,SC_MANAGER_CREATE_SERVICE)
IF hSCManager = 0 THEN
Error = _GetLastError ()
_FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,Error,0,ErMes,nSize,Arguments)
Print "Error by SCM:",ErMes
GOTO Exit
ENDIF
hCs=CreateService(hSCManager,MyService,Display,SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS,SERVICE_DEMAND_START,SERVICE_ERROR_NORMAL,XB,0,0,0,0,0)
IF hCs = 0 THEN
Error = _GetLastError ()
_FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,Error,0,ErMes,nSize,Arguments)
PRINT "Error by CreateService.:",ErMes
ENDIF
_CloseServiceHandle(hCs)
_CloseServiceHandle(hSCManager)
LABEL Exit
DO:UNTIL INKEY$<>""
I built both programs and ran this second one AS AN ADMINISTRATOR (otherwise you get access right error), this placed my little program in the list of services.
It was listed but was not running i.e. Stopped.
I noticed that an entry for my little program was placed in the registry under
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\AndyNservice.
The problem I have now is that when I try to start my program I get a message:
"The service did not respond to the start or control request in a timely fashion".
Note - if you try this, you can remove this service by deleting the above registry key, and rebooting.
? ? ? :o is all I can offer.
But I am watching; and I am interested.
Running a program as a service looks to be much more complicated than I first thought.
The program has to communicate with the services manager, which is why I'm getting the error message when I try to start my program, as my program does not.
I've also read that a service should not request any user or desktop interaction, such as opening a window. The reason for this is that a service starts when windows starts (that is before the user's desktop starts, and before the user has logged on).
You can of course run a program when a user logs on, this is easy to do as you only need to place one registry entry here:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run (for all users)
OR
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run (for the current user only)
Create a new string value callled say MyProgram in the Run registry folder
and give it a value, where the value is the full path to MyProgram
i.e. C:\MyFolder\MyProgram.exe
Your program will run the next time you start windows, and will keep doing so until you delete it out of the registry.
All program entries in these locations will appear in the start up list of programs.
Well, the attached code (txt file) is an example of a service to check memory status and was written in c++
I've started to try and convert it to IWB, but I need some help (my conversion so far, not finished) is the attached IWB file.
The code is using the windows header file, for us that's the windows.inc file and if you open the inc file you will see entries like:
TYPE SERVICE_STATUS
DEF dwServiceType AS INT
DEF dwCurrentState AS INT
DEF dwControlsAccepted AS INT
DEF dwWin32ExitCode AS INT
DEF dwServiceSpecificExitCode AS INT
DEF dwCheckPoint AS INT
DEF dwWaitHint AS INT
ENDTYPE
I've noticed some of the functions are in the windows.inc file, and some are in the winsvc.inc file.
So the coding is there, it's just a matter of translating it to IWB - so can anyone help?
Thanks,
Andy.
Inching my way forward, I've found several things:
I need to use advapi32 functions.
RegisterServiceCtrlHandlerA
StartServiceCtrlDispatcherA
SetServiceStatus
These declares can be found in the winsvc.inc file, but I thing I'm not translating them correctly yet.
Attached is what I've got now, I'm still getting errors, but getting closer - any help would be appreciated!
Andy.
Well I've got it to compile now, and it appears to run as a background process
(as "myserviceprog4.exe").
I have to use task manager to kill it, and it doesn't appear in the services list yet, so clearly there are things still to work on.
Help anyone?
Quote from: Andy on September 09, 2016, 06:54:20 AM
Help anyone?
Here is something for you to work on...
Remember to register program to service control manager:
sc create IWBrules binpath= c:\tmp\myserviceprog5.exe
and to remove it from service control manager:
sc delete IWBrules
When program is registered to service control manager, you can find the service from task managers list of services and issue start and stop commands for it.
Thanks for the help Jalih!
I was very close but you have helped me over the finishing line, thanks again for that!
I can now create, run and delete a service in IWB and I will post the code in the user offerings section.
Andy,
:)