473,378 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Starting servive but how to set proper priviledges

Hello,

I'm trying to start a monitor Windows server in my standalone Window PC.
I use code like following:

handle = ServiceWin32.OpenServiceA(SCManagerHandle, "MonitorServive",

ServiceWin32.ACCESS_TYPE.SERVICE_ALL_ACCESS);

if (handle < 1) // If not Succeeded, throw Exception. {

throw new Exception("Can't open the Service for modification.");

}

But i Get allways Exception that is in if clause. Handle is allways 0.

How should I set more priviledges? Admin privoíledges are ok because I run
PC in

standalone.

Cheers,


Jan 24 '06 #1
2 1539
Benny,

Well, it seems that the user account that you are running this for
doesn't have the appropriate privledges.

However, to be sure, you should declare your call to OpenService like
so:

[DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName,
[MarshalAs(UnmanagedType.U4)] dwDesiredAccess);

There is no need to be aware of the specific charset version on your
machine. The interop infrastructure will take care of that for you.

Additionally, you can get more information from the error code that is
returned, by making the call like this (assuming you have the declaration
above):

// Get the service handle.
IntPtr serviceHandle = ServiceWin32.OpenService(SCManagerHandle,
"MonitorServive", ServiceWin32.ACCESS_TYPE.SERVICE_ALL_ACCESS);

// Check the handle. < 1 is not a correct check.
if (serviceHandle == IntPtr.Zero)
{
// Throw an exception that will cull the information from GetLastError.
throw new System.ComponentModel.Win32Exception();
}

That will give you more details about the error.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Benny W" <bw@yahoo.com> wrote in message
news:dr**********@nyytiset.pp.htv.fi...
Hello,

I'm trying to start a monitor Windows server in my standalone Window PC.
I use code like following:

handle = ServiceWin32.OpenServiceA(SCManagerHandle, "MonitorServive",
ServiceWin32.ACCESS_TYPE.SERVICE_ALL_ACCESS);

if (handle < 1) // If not Succeeded, throw Exception. {

throw new Exception("Can't open the Service for modification.");

}

But i Get allways Exception that is in if clause. Handle is allways 0.

How should I set more priviledges? Admin privoíledges are ok because I run
PC in

standalone.

Cheers,


Jan 24 '06 #2
Thanks for your information!

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:et**************@TK2MSFTNGP11.phx.gbl...
Benny,

Well, it seems that the user account that you are running this for
doesn't have the appropriate privledges.

However, to be sure, you should declare your call to OpenService like
so:

[DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName,
[MarshalAs(UnmanagedType.U4)] dwDesiredAccess);

There is no need to be aware of the specific charset version on your
machine. The interop infrastructure will take care of that for you.

Additionally, you can get more information from the error code that is
returned, by making the call like this (assuming you have the declaration
above):

// Get the service handle.
IntPtr serviceHandle = ServiceWin32.OpenService(SCManagerHandle,
"MonitorServive", ServiceWin32.ACCESS_TYPE.SERVICE_ALL_ACCESS);

// Check the handle. < 1 is not a correct check.
if (serviceHandle == IntPtr.Zero)
{
// Throw an exception that will cull the information from GetLastError.
throw new System.ComponentModel.Win32Exception();
}

That will give you more details about the error.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Benny W" <bw@yahoo.com> wrote in message
news:dr**********@nyytiset.pp.htv.fi...
Hello,

I'm trying to start a monitor Windows server in my standalone Window PC.
I use code like following:

handle = ServiceWin32.OpenServiceA(SCManagerHandle, "MonitorServive",
ServiceWin32.ACCESS_TYPE.SERVICE_ALL_ACCESS);

if (handle < 1) // If not Succeeded, throw Exception. {

throw new Exception("Can't open the Service for modification.");

}

But i Get allways Exception that is in if clause. Handle is allways 0.

How should I set more priviledges? Admin privoíledges are ok because I
run PC in

standalone.

Cheers,



Jan 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: J.Beaulieu | last post by:
Hi I'll have probably to use sql server soon but prior to that I have a question concerning priviledges and security. Is it possible for someone to do like in access, ie creating a db/table...
33
by: Jim Cobban | last post by:
I cannot get Netscape 4.79 to properly display the ordered list in the following fragment. <P>Get a specific portion of the date. Depending upon the value of index: <ol start=0> <li>complete...
24
by: tom pester | last post by:
Hi All, I am learning php an I am amazed how easy a PHP noob like me can acheive so much in little time. I am planning to take part in the community and noticed these 3 newsgroups : ...
4
by: Kristof Despiere | last post by:
Suppose you have one domain, filled with a couple of users. What needs to be done now is I need to start a windows application from a webform by pressing a button on the webform (for example). ...
1
by: M. Simioni | last post by:
Hi, hi followed these KB: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q271071 http://support.microsoft.com/default.aspx?scid=kb;en-us;Q317012 ASP.NET applications run without...
1
by: deathbydisco | last post by:
I've created a simple website with a login screen that requires an email address and a password. It uses the email ID and password to authenticate against active directory (just to see if the user...
12
by: Prabu Subroto | last post by:
Dear my friends... I am using postgres 7.4 and SuSE 9.1. I want to use auto_increment as on MySQL. I look up the documentation on www.postgres.com and I found "serial" . But I don't know...
34
by: Umesh | last post by:
I want to extract a string abc*xyz from a text file. * indicates arbitrary no. of characters. I'm only able to do it when the string has definite no. of characters or the string length is...
7
by: Mr.SpOOn | last post by:
Hi, I'm writing a method to create musical chords. This method must follow a specific set of syntax rules. At least, this is my idea, but maybe there's a better way. Anyway, in the code I have...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.