Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 21st, 2006, 11:13 AM   #1
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
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."
randum77 is offline   Reply With Quote
Old Aug 21st, 2006, 1:32 PM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,466
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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 Module

Or 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."
Infinite Recursion is online now   Reply With Quote
Old Aug 21st, 2006, 1:51 PM   #3
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
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."
randum77 is offline   Reply With Quote
Old Aug 21st, 2006, 3:34 PM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,466
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is online now   Reply With Quote
Old Aug 24th, 2006, 1:42 PM   #5
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
Quote:
Originally Posted by Infinite Recursion
Console.WriteLine("Current User: " + Environment.UserName)
IR, you rock. I just used the Environment.Username pull and put the username in a text box. Kick ass. Now all i have to do is a string compare and activate / deactivate buttons based on that. I guess I could use a ElseIf or Case Select.

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."
randum77 is offline   Reply With Quote
Old Aug 24th, 2006, 2:10 PM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,466
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is online now   Reply With Quote
Old Aug 31st, 2006, 10:34 AM   #7
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
Quote:
Originally Posted by Infinite Recursion
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.
You sir about read my mind. *puts on tin foil beany* Here is the method I was using for button control based on username. It's not working, but it's my first excecution, so it's expected. Feel free to stomp it and offer alternatives.

        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 If

Bassically, 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."
randum77 is offline   Reply With Quote
Old Aug 31st, 2006, 11:04 AM   #8
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,466
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is online now   Reply With Quote
Old Aug 31st, 2006, 12:39 PM   #9
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
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."
randum77 is offline   Reply With Quote
Old Aug 31st, 2006, 1:13 PM   #10
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
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 If

It 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."
randum77 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:59 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC