Windows Service Authorization

  • Thread starter Thread starter matisq
  • Start date Start date
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
 
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.
 
Back
Top