ServiceController.ExecuteCommand() throws Exception,...

  • Thread starter Thread starter Kerem Gümrükcü
  • Start date Start date
K

Kerem Gümrükcü

Hi,

i have a application that can open an user defined service
at will and can send a User Definded Control Code to it.
I know that the OS restricts/reserves the usage of all
Codes below 127 to the OS itself, so this might be the
reason why executin the Code below 128 either raises
and Invalid Argument Exception (underlying OS Exception)
or an Acess Denied Exception (also underlying OS Exceptions
detail message). But can i bypass this restriction with some
e.g. Token Modification/Environment Change/Context Switch to
whatever or a windows api call in that way, that i can call all codes
from 0 to 255? I want to use a single function call like the
ExecuteCommand(...),...

TIA,...

Regards

Kerem

--
 
Hi,

i have a application that can open an user defined service
at will and can send a User Definded Control Code to it.
I know that the OS restricts/reserves the usage of all
Codes below 127 to the OS itself, so this might be the
reason why executin the Code below 128 either raises
and Invalid Argument Exception (underlying OS Exception)
or an Acess Denied Exception (also underlying OS Exceptions
detail message). But can i bypass this restriction with some
e.g. Token Modification/Environment Change/Context Switch to
whatever or a windows api call in that way, that i can call all codes
from 0 to 255? I want to use a single function call like the
ExecuteCommand(...),...

What error are you getting?
are you sure you have permission?
I do not think that your problem is with the command, but in any case
use a bigger number, like in the 1000
 
Hi Ignacio,

i have suffcient rights and my application runs
with all priviliges enabled and under administrative
power and also under system account if i like to.
The point is that you cant send control codes
under 128 directly to a service and must use
your own control codes upper 127 but max 255
if you want to send your own codes to a service,
mainly your own service. So is the operating systems
restriction! But i was asking for a way to bypass this, if
it is possible.But i found out, that it is not,...!

Thanks for your answer,...

Regards

K.



--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Microsoft Live Space: http://kerem-g.spaces.live.com/
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."
Newsbeitrag
Hi,

i have a application that can open an user defined service
at will and can send a User Definded Control Code to it.
I know that the OS restricts/reserves the usage of all
Codes below 127 to the OS itself, so this might be the
reason why executin the Code below 128 either raises
and Invalid Argument Exception (underlying OS Exception)
or an Acess Denied Exception (also underlying OS Exceptions
detail message). But can i bypass this restriction with some
e.g. Token Modification/Environment Change/Context Switch to
whatever or a windows api call in that way, that i can call all codes
from 0 to 255? I want to use a single function call like the
ExecuteCommand(...),...

What error are you getting?
are you sure you have permission?
I do not think that your problem is with the command, but in any case
use a bigger number, like in the 1000
 
Kerem said:
Hi Ignacio,

i have suffcient rights and my application runs
with all priviliges enabled and under administrative
power and also under system account if i like to.
The point is that you cant send control codes
under 128 directly to a service and must use
your own control codes upper 127 but max 255
if you want to send your own codes to a service,
mainly your own service. So is the operating systems
restriction! But i was asking for a way to bypass this, if
it is possible.But i found out, that it is not,...!
I am not sure where you get the idea that the max argument is 255.
ExecuteCommand() in ServiceController takes an int argument as does
OnCustomCommand() in ServiceBase. You should be able to send any argument from
-2147483648 to 2147483647.

HTH,
-rick-
 
Hi Ricks,
I am not sure where you get the idea that the max argument is 255.
ExecuteCommand() in ServiceController takes an int argument as does
OnCustomCommand() in ServiceBase. You should be able to send any argument
from -2147483648 to 2147483647.

http://msdn.microsoft.com/en-us/library/ms682108(VS.85).aspx

See section "Control Code",...

Obviously the .NET Function calls this or the Ex Function, i didnt check it,
but the case is that it can raise a Win32Exception and it does in my case.
So the Parameter for ExecuteCommand does not rely on its DataType, but
rather on the value. But i see now, that the OS is restricting and reserving
Control Codes below 128 to its private usage and does not accept codes
from an externall application sending them,...

I was looking for some way of doing this to support the complete range of
control codes in my application, but this is AFAIK not possible and i cant
see any bypassing methdo,..and there is no need for anymore,...

Thanks for your reply,...


Regards

Kerem


--
 
Kerem said:
Hi Ricks,


http://msdn.microsoft.com/en-us/library/ms682108(VS.85).aspx

See section "Control Code",...

Obviously the .NET Function calls this or the Ex Function, i didnt check it,
but the case is that it can raise a Win32Exception and it does in my case.
So the Parameter for ExecuteCommand does not rely on its DataType, but
rather on the value. But i see now, that the OS is restricting and reserving
Control Codes below 128 to its private usage and does not accept codes
from an externall application sending them,...

I was looking for some way of doing this to support the complete range of
control codes in my application, but this is AFAIK not possible and i cant
see any bypassing methdo,..and there is no need for anymore,...

Sorry, my bad - the documented limits for the range are 128 - 256, even though
the argument is an integer and could contain much larger numbers. This will
cramp my style a bit too - I am implementing my first service right now and had
hoped to be able to use the higher-order bits to pass some limited information.

-rick-
 
Hi Rick,

you can bypass this by extending the servicecontroller
and implementing some IPC mechanism to share large
amounts of real data structures between any application
and even any operating system as far your ipc technique
allows this. I solved it with a three way implementation:
sockets, named pipes and shared memory in a single
service. The service can handle sockt connections from
any IPv4 and IPv6 Connections, uses a OutputDebugString
like memory mapped mechanism and also can handle
named pipe connections. This way i can send any data
to the service as a endpoint. You also can use any
communication method like WCF or newer things, it
depends on you,...


Regards

Kerem



--
 
Kerem said:
Hi Rick,

you can bypass this by extending the servicecontroller
and implementing some IPC mechanism to share large
amounts of real data structures between any application
and even any operating system as far your ipc technique
allows this. I solved it with a three way implementation:
sockets, named pipes and shared memory in a single
service. The service can handle sockt connections from
any IPv4 and IPv6 Connections, uses a OutputDebugString
like memory mapped mechanism and also can handle
named pipe connections. This way i can send any data
to the service as a endpoint. You also can use any
communication method like WCF or newer things, it
depends on you,...
Yes, I was thinking that if more data needed to be transferred (not an excessive
amount, just parameters and switch settings and like that) then the custom
command could be used to kick off a message dialog via remoting or some such
mechanism. Looked into it a bit this afternoon - kind of attractive simply
because I haven't done remoting before. As you say, there are a lot of ways . . .

Regards,
-rick-
 
Hi Rick,

i liked the Memmory Mappped approach if
it will run on the local machine. There will be
no Firewall to configure and it is really fast,
as long it is local and a point to point
communication and you wont serve to more
clients but just one,...

That maybe will give you an insight view:
http://www.codeproject.com/KB/threads/csthreadmsg.aspx

If you want to serve .NET only clients stay at .NET
only technologies. If you want to serve any type
of client, then stay at a mechanism that will be at
Operating System Level and can be "created"
with Windows API Exports, due to the fact that
neraly any modern language can use the windows
API today,...

Regards

Kerem


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top