|
-
Jun 15th, 2006, 05:36 AM
#1
Thread Starter
Hyperactive Member
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.
-
Jun 15th, 2006, 05:53 AM
#2
Re: who is using the pc
Use GetUserName api from AdvAPI32.dll
VB Code:
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.
-
Jun 15th, 2006, 05:54 AM
#3
Re: who is using the pc
VB Code:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As _
String, nSize As Long) As Long
Private UserAccount As String
Private Sub GetUserAccount()
Dim sBuffer As String
Dim lSize As Long
sBuffer = Space$(255)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)
If lSize > 0 Then
UserAccount = Left$(sBuffer, lSize - 1)
Else
UserAccount = vbNullString
End If
End Sub
-
Jun 15th, 2006, 05:56 AM
#4
-
Jun 15th, 2006, 05:57 AM
#5
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jun 15th, 2006, 06:10 AM
#6
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.
-
Jun 15th, 2006, 06:47 AM
#7
Thread Starter
Hyperactive Member
-
Jun 15th, 2006, 06:53 AM
#8
Re: who is using the pc
 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
-
Jun 15th, 2006, 07:01 AM
#9
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.
-
Jun 15th, 2006, 07:08 AM
#10
Re: RESOLVED - who is using the pc
 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.
 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
-
Jun 15th, 2006, 06:16 PM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jun 15th, 2006, 09:43 PM
#12
Fanatic Member
On Error GoTo Hell
Hell:
Kill Me
Food For Thought:
- Do not judge a book... if you're not a judge!

-
Jun 15th, 2006, 10:00 PM
#13
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jun 15th, 2006, 11:14 PM
#14
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:
Dim lEnv As Long
Do While True
If Environ(lEnv) = "" Then
Exit Do
End If
Debug.Print Environ(lEnv)
lEnv = lEnv + 1
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.
-
Jun 16th, 2006, 01:55 AM
#15
Re: RESOLVED - who is using the pc
 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
-
Jun 16th, 2006, 01:56 AM
#16
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jun 16th, 2006, 02:28 AM
#17
Re: RESOLVED - who is using the pc
 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.
 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
-
Jun 16th, 2006, 09:56 AM
#18
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jun 17th, 2006, 10:19 AM
#19
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|