| 1 |
|
| 2 |
|
| 3 |
x18servicesV0.1.zip |
| 4 |
------------------- |
| 5 |
|
| 6 |
Version 0.0, first alpha, 10th June 2002 by Ximon Eighteen. |
| 7 |
Version 0.1, added GetServiceNameFromDisplayName(), 5th June 2003 by Ximon Eighteen. |
| 8 |
|
| 9 |
|
| 10 |
What The Hell Is This? |
| 11 |
---------------------- |
| 12 |
|
| 13 |
If you've ever had to make an installation program that had to start, stop, |
| 14 |
remove or otherwise manipulate a Windows NT Service then you'll find this |
| 15 |
useful. It's a collection of functions that can be used from an NSIS script |
| 16 |
(Nullsoft Installation System, http://www.nullsoft.com/free/nsis) to manipulate |
| 17 |
Windows NT (and hopefully 2000 and XP) Services. |
| 18 |
|
| 19 |
If you don't know what I'm talking about then you don't need this, simple. |
| 20 |
|
| 21 |
Most of the code is based on information found in the Microsoft Knowledge Base |
| 22 |
and the MSDN Platform SDK documentation. |
| 23 |
|
| 24 |
I haven't released anything in quite a long time so if I've forgotten something |
| 25 |
or have generally fouled up somewhere then for gods sake tell me. |
| 26 |
|
| 27 |
Feel free to send comments/suggestions/bug fixes/hate mail/biscuits to |
| 28 |
[email protected]. |
| 29 |
|
| 30 |
As long as you don't violate any nullsoft agreement that might be binding on |
| 31 |
an extension DLL for their NSIS product as far as I'm concerned you can do |
| 32 |
absolutely anything with this code, claim as your own if you like although |
| 33 |
that would be a bit low. |
| 34 |
|
| 35 |
I'll answer any questions that I can, but I'm not responsible if this fouls |
| 36 |
up your system, use this at your own risk. If something does go wrong I'll do |
| 37 |
what I can to help, but I think this is highly unlikely ;-) |
| 38 |
|
| 39 |
--- |
| 40 |
|
| 41 |
Ximon Eighteen aka Sunjammer |
| 42 |
|
| 43 |
|
| 44 |
Distribution : |
| 45 |
-------------- |
| 46 |
|
| 47 |
- exdll.c |
| 48 |
- isadministrator.c |
| 49 |
- logonasservice.c |
| 50 |
- nsisapi.h |
| 51 |
- queryservice.c |
| 52 |
- readme.txt |
| 53 |
- sendservicecommand.c |
| 54 |
- winerror.h |
| 55 |
- winerror.c |
| 56 |
- Visual C++ 6.0 project file (.dsp) [ release & debug configurations ] |
| 57 |
- Services.nsi [ example ] |
| 58 |
- FindService.nsi [ example ] |
| 59 |
|
| 60 |
The code is based on the exdll project that shipped with 0.98 of the NSIS |
| 61 |
distro. Building the project should result in a .dll file that you can then |
| 62 |
use with the CallInstDLL NSIS scripting command. |
| 63 |
|
| 64 |
|
| 65 |
Known Bugs/Issues : |
| 66 |
------------------- |
| 67 |
|
| 68 |
- I don't think the SendServiceCommand should really support a delete |
| 69 |
option, perhaps it should be a separate function? |
| 70 |
- No other known issues. |
| 71 |
|
| 72 |
|
| 73 |
Function Level Docs : [ extracted from the source ] |
| 74 |
--------------------- |
| 75 |
|
| 76 |
GetServiceNameFromDisplayName: |
| 77 |
DESC: Find the internal service name of all services whose display name (as |
| 78 |
DESC: seen in the Services Control Panel) contains the given name or name |
| 79 |
DESC: fragment (case insensitive match). |
| 80 |
ARGS: Push the display name or display name fragment onto the stack |
| 81 |
RETN: One or more values on the stack. |
| 82 |
RETN: The first will be the count of matches found. |
| 83 |
RETN: The second will be the reason for finding no matches, OR the first match. |
| 84 |
RETN: The third and so on will be the remaining matches upto the count. |
| 85 |
USGE: See the FindServices.nsi example. |
| 86 |
|
| 87 |
IsProcessUserAdministrator: |
| 88 |
DESC: Find out if the user (the owner of the current process) is a member of |
| 89 |
DESC: the administrators group on the local computer (not on the domain!). |
| 90 |
ARGS: Push the service name onto the stack. |
| 91 |
RETN: Pop the result string from the stack. |
| 92 |
RETN: The result will be 'Yes' or 'No' if there were no problems, otherwise |
| 93 |
RETN: the reason for the failure will be in the result string. |
| 94 |
USGE: Use it like this :- |
| 95 |
USGE: |
| 96 |
USGE: services::IsProcessUserAdministrator |
| 97 |
USGE: Pop $0 |
| 98 |
USGE: ; $0 now contains either 'Yes', 'No' or an error description |
| 99 |
|
| 100 |
HasLogonAsAService: |
| 101 |
DESC: Find out if the current user (the owner of the process) has the LSA |
| 102 |
DESC: (Local Security Authority) policy right 'SeServiceLogonRight'. |
| 103 |
RETN: Pop the result string from the stack. |
| 104 |
RETN: The result will be 'Yes' or 'No' if there were no problems, otherwise |
| 105 |
RETN: the reason for the failure will be in the result string. |
| 106 |
USGE: Use it like this :- |
| 107 |
USGE: |
| 108 |
USGE: services::HasLogonAsAService '3B2\Ximon_Eighteen' |
| 109 |
USGE: Pop $0 |
| 110 |
USGE: ; $0 now contains either 'Yes', 'No' or an error description |
| 111 |
|
| 112 |
GrantLogonAsAService: |
| 113 |
DESC: Grant the current user (the owner of the process) the LSA |
| 114 |
DESC: (Local Security Authority) policy right 'SeServiceLogonRight'. |
| 115 |
RETN: Pop the result string from the stack. |
| 116 |
RETN: The result will be 'Ok' if there were no problems, otherwise |
| 117 |
RETN: the reason for the failure will be in the result string. |
| 118 |
USGE: Use it like this :- |
| 119 |
USGE: |
| 120 |
USGE: services::GrantLogonAsAService '3B2\Ximon_Eighteen' |
| 121 |
USGE: Pop $0 |
| 122 |
USGE: ; $0 now contains either 'Yes', 'No' or an error description |
| 123 |
|
| 124 |
RemoveLogonAsAService: |
| 125 |
DESC: Deny the current user (the owner of the process) the LSA |
| 126 |
DESC: (Local Security Authority) policy right 'SeServiceLogonRight'. |
| 127 |
RETN: Pop the result string from the stack. |
| 128 |
RETN: The result will be 'Ok' if there were no problems, otherwise |
| 129 |
RETN: the reason for the failure will be in the result string. |
| 130 |
USGE: Use it like this :- |
| 131 |
USGE: |
| 132 |
USGE: services::RemoveLogonAsAService '3B2\Ximon_Eighteen' |
| 133 |
USGE: Pop $0 |
| 134 |
USGE: ; $0 now contains either 'Yes', 'No' or an error description |
| 135 |
|
| 136 |
IsServiceInstalled: |
| 137 |
DESC: Find out if the named service is installed. |
| 138 |
ARGS: Push the service name onto the stack. |
| 139 |
RETN: Pop the result string from the stack. |
| 140 |
RETN: The result will be 'Yes' or 'No' if there were no problems, otherwise |
| 141 |
RETN: the reason for the failure will be in the result string. |
| 142 |
USGE: Use it like this :- |
| 143 |
USGE: |
| 144 |
USGE: services::IsServiceInstalled 'MyServiceName' |
| 145 |
USGE: Pop $0 |
| 146 |
USGE: ; $0 now contains either 'Yes', 'No' or an error description |
| 147 |
|
| 148 |
IsServiceRunning |
| 149 |
DESC: Find out if the named service is installed and running. |
| 150 |
ARGS: Push the service name onto the stack. |
| 151 |
RETN: Pop the result string from the stack. |
| 152 |
RETN: The result will be 'Yes' or 'No' if there were no problems, otherwise |
| 153 |
RETN: the reason for the failure will be in the result string. |
| 154 |
USGE: Use it like this :- |
| 155 |
USGE: |
| 156 |
USGE: services::IsServiceRunning 'MyServiceName' |
| 157 |
USGE: Pop $0 |
| 158 |
USGE: ; $0 now contains either 'Yes', 'No' or an error description |
| 159 |
|
| 160 |
SendServiceCommand: |
| 161 |
DESC: Send a command (Start, Stop, Pause, Continue or Delete) to the Service |
| 162 |
DESC: Control Manager (SCM) for a given service. |
| 163 |
ARGS: Push service command string onto the stack |
| 164 |
ARGS: Push service name string onto the stack |
| 165 |
RETN: Pop the result string from the stack. |
| 166 |
RETN: The result will be 'Ok' if there were no problems, or the reason for |
| 167 |
RETN: failure otherwise. |
| 168 |
USGE: Use it like this :- |
| 169 |
USGE: |
| 170 |
USGE: services::SendServiceCommand 'start' 'MyServiceName' |
| 171 |
USGE: Pop $0 |
| 172 |
USGE: StrCmp $0 'Ok' success 0 |
| 173 |
USGE: MessageBox MB_OK|MB_ICONSTOP 'Failed to send service command: Reason: $0' 0 0 |
| 174 |
USGE: Abort |
| 175 |
USGE: success: |