Archive: Using System.dll to call Win32 APIs


Using System.dll to call Win32 APIs
I was looking for a simple installer package the other day, and found this one. It seems to be very straight forward to use. My only problem though so far is the following:

I have written a program to be run as a service and would like to install this service using NSIS scripting. The commands should be as follows:

System::Call 'advapi32::OpenSCManagerA(t, t, l) l(Null, Null, 2).r0'
System::Call 'advapi32::CreateServiceA(l, t, t, l, l, l, l, t, t, t, t, t, t) l(r0, "ServiceName", "Service Description", 983551, 16, 2, 1, "ServiceLocation.exe", Null, Null, Null, "LocalSystem", Null).r1'

The first calls returns a handle from the Service Control Managage Database and passes that handle into the first variable in the next call which creates the service. The first call seeems to be working correctly, but the second does not, and I think it is because the handle being returned from the first call is getting changed into a string variable which needs to remain a long to be passed into the second call.

I know that I could create my own extension dll to do this or I could do the install in my program, but if I could get this to work it would be very simply and elegant.

If anyone could help, I would greatly appreciate it.

-tim


Usually services can install themself, I think that's the easiest solution.


1. t "Null" will pass pointer to "Null" string to API (not the 0x0 :)
2. dword / int32 etc -> use i, not the l parameter type (l stands for long, or int64).

Try this code, please (I've checked only the correctness of functions specification, not values):

System::Call 'advapi32::OpenSCManagerA(i 0, i 0, i 2) i .r0'
System::Call 'advapi32::CreateServiceA(i r0, t "ServiceName", t "Service Description", i 983551, i 16, i 2, i 1, t "ServiceLocation.exe", i 0, i 0, i 0, t "LocalSystem", i 0) i .r1'


Thank you brainsucker, that worked exactly as I wanted it to.

-tim


NT Service Functions
If anyone is interested I have now built a couple of functions using the System plugin that do the following:

Install a service
Start a service
UnInstall a service

-tim


Create a page for them at The Archive, I sure it will be found useful.