Home All Groups Group Topic Archive Search About

Windows Service Authorization

Author
2 Oct 2006 3:37 PM
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

Author
3 Oct 2006 10:36 AM
james
Show quote Hide quote
"matisq" <mati***@tlen.pl> wrote in message
news:1159803472.252951.135240@m73g2000cwd.googlegroups.com...
> 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.