Click here to Skip to main content
15,920,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,
I am having a little trouble with this code I am trying to make.
I am trying to have like (if admin then do this) thing
only I would like to use usernames and not the administrator profile type.

The usernames are (sysadmin, administrator, backup.)

Here is the code:
VB
If (LCase(Environment.UserName)) = (CStr("sysadmin") Or CStr("administrator") Or CStr("backup")) Then
    MessageBox.Show("You are an administrator")
Else
    MessageBox.Show("You are not an authorised user!")
End If


the error I am getting is:
Conversion from string "sysadmin" to type 'Double' is not valid.

I think I need to try to convert my username "sysadmin" to string or somthing.

Can any one show me the right way of doing this.


thanks
Posted

1 solution

Hi, use below code

VB
If (LCase(Environment.UserName) = "sysadmin" Or LCase(Environment.UserName) = CStr("administrator") Or  LCase(Environment.UserName) = "backup") Then
            MessageBox.Show("You are an administrator")
        Else
            MessageBox.Show("You are not an authorised user!")
        End If
 
Share this answer
 
Comments
Member 8327439 15-Mar-12 2:36am    
thank you for that, I thought it would like that but did not know how to do it.

thanks again.
Sarvesh Kumar Gupta 15-Mar-12 13:35pm    
if it solve your problem then vote it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900