Windows Service Authorization

M

matisq

Hello

I need to run this type of code in my windows Service:
///////////////////////////////////////////////////////////////////////////////
Protected Overrides Sub OnStart(ByVal args() As String)

If User= "Administrator" Then
'do code
Else
'do nothing
End If

End
/////////////////////////////////////////////////////////////////////////////////
Can I check who is logged in to the computer with help of service?

When I try to:
/////////////////////////////////////////////////////////////////////////////////
If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
or
If My.User.CurrentPrincipal.Identity.Name = "Administrator" Then
//////////////////////////////////////////////////////////////////////////////
It does't work (goes directly to 'Else)..

Best Regards
 
J

james

matisq said:
Hello

I need to run this type of code in my windows Service:
///////////////////////////////////////////////////////////////////////////////
Protected Overrides Sub OnStart(ByVal args() As String)

If User= "Administrator" Then
'do code
Else
'do nothing
End If

End
/////////////////////////////////////////////////////////////////////////////////
Can I check who is logged in to the computer with help of service?

When I try to:
/////////////////////////////////////////////////////////////////////////////////
If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
or
If My.User.CurrentPrincipal.Identity.Name = "Administrator" Then
//////////////////////////////////////////////////////////////////////////////
It does't work (goes directly to 'Else)..

Environment.UserName? Your service may need to be set to allow interaction
with the desktop though. Also, check what your service logs on as - it might
be "LocalSystem" or similar.
 

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

Top