![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3
![]() |
User Currently Logged in....
Ok, yet another dumb question. I know i can pull what user is logged in by using a WMI pull. But how would I go about it with a System.Class.method? I've been searching the forums but can't find anything that helps.
I am trying to build an app that makes certian buttons active based on who's logged in. Any help is appreciated. TIA
__________________
_Marshall_ "America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt." |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
Module Module1
Sub Main()
Dim cUser As String
cUser = GetUserName()
Console.WriteLine("Current User: " + cUser)
End Sub
Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
ByRef nSize As Integer) As Integer
Public Function GetUserName() As String
Dim iReturn As Integer
Dim userName As String
userName = New String(CChar(" "), 50)
iReturn = GetUserName(userName, 50)
GetUserName = userName.Substring(0, userName.IndexOf(Chr(0)))
End Function
End ModuleOr even easier... Console.WriteLine("Current User: " + Environment.UserName)
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3
![]() |
Well damn, that sounds good to me. I can always count on you IR.
![]()
__________________
_Marshall_ "America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt." |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
Glad I could help...
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#5 | |
|
Programmer
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3
![]() |
Quote:
Thank you a thousand times over.
__________________
_Marshall_ "America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt." |
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
Cool man, glad its working for you. Just a suggestion... have a list of acceptable users in a config file with the portions of the program they have access to... then enable/disable buttons based off of those entries... that way it would be more flexible. But, may not matter much as I'm not entirely sure what you are up to our how widespread its use will be.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#7 | |
|
Programmer
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3
![]() |
Quote:
If usrName Like "BUT_%" Then
Me.uiButRestButton3.Visible = True
Me.uiConRestButton.Visible = False
Me.uiNafRestButton.Visible = False
Me.uiSGPRestButton.Visible = False
Me.uiSSRestButton.Visible = False
Me.uiTefRestButton.Visible = False
Me.uiTraRestButton.Visible = False
ElseIf usrName Like "%CON_%" Then
Me.uiButRestButton3.Visible = False
Me.uiConRestButton.Visible = True
Me.uiNafRestButton.Visible = False
Me.uiSGPRestButton.Visible = False
Me.uiSSRestButton.Visible = False
Me.uiTefRestButton.Visible = False
Me.uiTraRestButton.Visible = False
.................................
Else
Me.uiButRestButton3.Visible = True
Me.uiConRestButton.Visible = True
Me.uiNafRestButton.Visible = True
Me.uiSGPRestButton.Visible = True
Me.uiSSRestButton.Visible = True
Me.uiTefRestButton.Visible = True
Me.uiTraRestButton.Visible = True
End IfBassically, we have alot of usernames that start w/ the same thing like. CONT_ or BUT_ ect..... and i am trying to make a catch all. I tried if usrName = "%but_%" and if usrName like "%but_%" And of course, no love. I am sure it's something simple and my lack of experience is to blame. Thank you in advance.
__________________
_Marshall_ "America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt." |
|
|
|
|
|
|
#8 |
|
Programming Guru
![]() ![]() ![]() |
Try substrings...
If usrName.Substring(0, 4).ToUpper = "BUT_" Then
Me.uiButRestButton3.Visible = True
...Substring(STARTING POSITION, NUM OF CHARS TO RETURN) All strings start at 0, so for the %CON_% instance, you will need to determine where in the string CON_ starts... For instance: USCON_MYID usrName.Substring(2, 4).ToUpper = "CON_" If the position of the keyword is not always constant in the username string, you could take the high road and use the .IndexOf string property to determine if the keyword is in that string... anywhere. Another thing is... are you sure you want to disable the view property or just disable the ability to click the button? button.Visible = False vs button.Enabled = False
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#9 |
|
Programmer
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3
![]() |
IR, i like the substring idea. I'll put that in. The 3 letter connotations apprear the same in all the names so it should work quite well. As for visibility, wer are doing this to cut down on technician time out in the area. The users are out in the area are used to doing MFG type line work, so they hardly know anything about computers, let alone what a start menue is. That's fine as long as they do the line work perfect most the time.
I am going to stack the buttons i have so it only appears as if there is one to any one user. Then i am going to control the visibility so that only the button they need for that area appears. Otherwise, they will either get confused or play around to much and muck up the configs for that area. Once I am done I'll post up pic's of the final form so it will make more sense. Right now I have alot of unneeded output feilds on the form to verify all the gears are turning in the direction. This is turning out to be alot of fun for me. Thank you again.
__________________
_Marshall_ "America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt." |
|
|
|
|
|
#10 |
|
Programmer
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3
![]() |
Here's what the code ends up looking like when using the substring pull on the variable.
Dim usrName As String
'Who the currently logged in user
usrName = Environment.UserName
usrName = usrName.ToUpper
Me.uiUserLabel2.Text = usrName
'makes certian buttons available based on username
If usrName.Substring(0, 3) = "BUT" Then
Me.uiButRestButton3.Visible = True
Me.uiConRestButton.Visible = False
Me.uiNafRestButton.Visible = False
Me.uiSGPRestButton.Visible = False
Me.uiSSRestButton.Visible = False
Me.uiTefRestButton.Visible = False
Me.uiTraRestButton.Visible = False
ElseIf usrName.Substring(0, 3) Like "CON" Then
Me.uiButRestButton3.Visible = False
Me.uiConRestButton.Visible = True
Me.uiNafRestButton.Visible = False
Me.uiSGPRestButton.Visible = False
Me.uiSSRestButton.Visible = False
Me.uiTefRestButton.Visible = False
Me.uiTraRestButton.Visible = False
.
.
.
.
.
Else
Me.uiButRestButton3.Visible = True
Me.uiConRestButton.Visible = True
Me.uiNafRestButton.Visible = True
Me.uiSGPRestButton.Visible = True
Me.uiSSRestButton.Visible = True
Me.uiTefRestButton.Visible = True
Me.uiTraRestButton.Visible = True
End IfIt works great. I do apreciate it. Now I am moving on to the copy / progress screen part of it. I can copy the files, but i've been tumbling through and a progress that's not completely foreign to build.
__________________
_Marshall_ "America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| FiveDigit + RandomeNumber Game. | TecBrain | Java | 0 | Nov 18th, 2005 2:53 PM |
| User Input for Number Format | ericelysia1 | Java | 0 | Jul 21st, 2005 3:41 PM |
| Instant Messaging App Help | AusTex | C | 0 | Apr 27th, 2005 4:52 PM |
| Loading and Destroying web user controls into a panel | see07 | C# | 0 | Feb 2nd, 2005 12:38 PM |
| Show web user control hidden | see07 | C# | 1 | Feb 2nd, 2005 10:35 AM |