Results 1 to 19 of 19

Thread: RESOLVED - who is using the pc

  1. #1

    Thread Starter
    Hyperactive Member samsyl's Avatar
    Join Date
    Jun 2001
    Location
    London
    Posts
    338

    Resolved RESOLVED - who is using the pc

    i want to show who is using the pc now. just show the username of pc to a text box.

    thanks
    Last edited by Hack; Jun 15th, 2006 at 07:02 AM. Reason: Added green "resolved" checkmark Last edited by samsyl : Today at 07:48 AM.

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: who is using the pc

    Use GetUserName api from AdvAPI32.dll
    VB Code:
    1. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: who is using the pc

    VB Code:
    1. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As _
    2. String, nSize As Long) As Long
    3.  
    4. Private UserAccount As String
    5.  
    6. Private Sub GetUserAccount()
    7.  
    8.     Dim sBuffer As String
    9.     Dim lSize As Long
    10.    
    11.     sBuffer = Space$(255)
    12.     lSize = Len(sBuffer)
    13.     Call GetUserName(sBuffer, lSize)
    14.     If lSize > 0 Then
    15.         UserAccount = Left$(sBuffer, lSize - 1)
    16.     Else
    17.         UserAccount = vbNullString
    18.     End If
    19.    
    20. End Sub

  4. #4
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: who is using the pc

    Check out the robdog's post:

    How Do I Get The Current Windows Username?
    CS

  5. #5
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: who is using the pc

    An easier way would be
    VB Code:
    1. Environ("UserName")
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  6. #6
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: who is using the pc

    There are few drawbacks if you use environ variables check out the link i posted in my previous post.
    CS

  7. #7

    Thread Starter
    Hyperactive Member samsyl's Avatar
    Join Date
    Jun 2001
    Location
    London
    Posts
    338

    Re: who is using the pc

    DONE

    Thanks Everyone

  8. #8
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: who is using the pc

    Quote Originally Posted by cssriraman
    There are few drawbacks if you use environ variables check out the link i posted in my previous post.
    I don't see any drawbacks.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  9. #9
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: RESOLVED - who is using the pc

    Using the environment variables are easy to use but unreliable for these reasons -

    1. The user can edit the value to anything they want by going to the System Properties and changing the values.
    2. The user can delete the environment variables too.
    3. To get the user name is that this variable is not set by default on Win9x/Me.

    So, The GetUserName API is probably the most reliable and secure way to retrieve the username. It cannot be changed by the user as long as Windows permissions dissallow it.
    CS

  10. #10
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: RESOLVED - who is using the pc

    Quote Originally Posted by cssriraman
    1. The user can edit the value to anything they want by going to the System Properties and changing the values.
    2. The user can delete the environment variables too.
    How can a user change the UserName in the System Properties or Delete it? Can you give me the steps that will delete this particular Environment Variable or change it.

    Quote Originally Posted by cssriraman
    3. To get the user name is that this variable is not set by default on Win9x/Me.
    Never tested it on Win9x/ME.
    Last edited by Shuja Ali; Jun 16th, 2006 at 01:52 AM. Reason: Corrected the quote tag
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: RESOLVED - who is using the pc

    I believe its when used under Windows 95/98 that you can mess with the username environment variable. You can create a duplicate Environmental variable but depends on the method used to read it (API vs Environ(UserName)).
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12
    Fanatic Member eimroda's Avatar
    Join Date
    Jul 2000
    Location
    Philippines
    Posts
    642

    Re: who is using the pc

    Quote Originally Posted by Shuja Ali
    An easier way would be
    VB Code:
    1. Environ("UserName")
    what are the other arguments (aside from Username) for Environ()? (my first time to hear that)

    On Error GoTo Hell

    Hell:
    Kill Me


    Food For Thought:

    - Do not judge a book... if you're not a judge!


  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: RESOLVED - who is using the pc

    You can view, add, edit, and delete the variables from -

    Control Panel > System Properties > Advanced tab > Environment Variables button.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: RESOLVED - who is using the pc

    what are the other arguments (aside from Username) for Environ()? (my first time to hear that)
    to get the variables execute this code
    VB Code:
    1. Dim lEnv As Long
    2. Do While True
    3.    If Environ(lEnv) = "" Then
    4.      Exit Do
    5.    End If
    6.    Debug.Print Environ(lEnv)
    7.    lEnv = lEnv + 1
    8. Loop
    but before using the environ variables consider Post #9 by cssriraman
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  15. #15
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: RESOLVED - who is using the pc

    Quote Originally Posted by RobDog888
    I believe its when used under Windows 95/98 that you can mess with the username environment variable. You can create a duplicate Environmental variable but depends on the method used to read it (API vs Environ(UserName)).
    In Win2K & XP, the Environmental Variables like UserName, etc are not shown to the user in the System Properties. Even If the user tries to change it using Set Command the System will still show the correct USERNAME. So I guess using Environ in Win 2K/XP is safe. What say?
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: RESOLVED - who is using the pc

    Yes, but if your app is multi-platform then you cant take the chance. Easier to just use the more stable and secure way and not have to worry about it.

    You know you can create a UserName variable in 2000/XP but when reading it it will give the system value.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: RESOLVED - who is using the pc

    Quote Originally Posted by RobDog888
    Yes, but if your app is multi-platform then you cant take the chance. Easier to just use the more stable and secure way and not have to worry about it.
    I strongly beleive that people who are still using Win98/ME do not have any right to get my applications.

    I especially hate people who are using Win ME. Win ME comes up with all kind of weird problems.

    Quote Originally Posted by RobDog888
    You know you can create a UserName variable in 2000/XP but when reading it it will give the system value.
    Thats what I said in my previous post. And using Environ in that case is Safe.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: RESOLVED - who is using the pc

    Well I just believe you dont assume anything in programming and using the Environ function is partly an assumption of what OS your app may be running on and other issues already posted. I dont like problems in my apps so I dont use it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: RESOLVED - who is using the pc

    True. I also beleive in making software that doesn't give unusual results..

    But the place where I work, they don't use any other OS apart from XP. So I guess my Apps are safe.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width