-
November 29th, 2002, 03:42 AM
#1
computer name
hi, i am new to this forum !!
in VB6.0, is there any object i can retrieve the computer name when a user is executing a exe.
THX
KEith
-
November 29th, 2002, 04:31 AM
#2
Retrieve computer name
Hi, welcome to this forum!
You can use GetComputerName Api
from Api-guide, a free tool you can download at www.allapi.net
Code:
'example by Donavon Kuhn (Donavon.Kuhn@Nextel.com)
Private Const MAX_COMPUTERNAME_LENGTH As Long = 31
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_Load()
Dim dwLen As Long
Dim strString As String
'Create a buffer
dwLen = MAX_COMPUTERNAME_LENGTH + 1
strString = String(dwLen, "X")
'Get the computer name
GetComputerName strString, dwLen
'get only the actual data
strString = Left(strString, dwLen)
'Show the computer name
MsgBox strString
End Sub
Cesare Imperiali
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
November 29th, 2002, 09:24 AM
#3
No need for API, here is a simpler method:
Code:
MsgBox Environ$("computername")
JeffB
-
November 29th, 2002, 12:34 PM
#4
computer name
How can I get a unique id of a computer which is definitely different from other computers? Is there any? thanks
-
December 4th, 2002, 07:19 PM
#5
There are different ways to do this, depending on what you want to get. You can use the CoCreateGuid API call, or you can use the hard drive serial number to generate a code, or the installation date and time, or...
Actually, there are many ways. To use the hard drive serial number, use the GetVolumeInformation API call. You can also mix in a name entered by the user, along with the date and time to create the unique number.
If you distribute the app on CD (or floppy), you can use the serial number of the disc.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
December 5th, 2002, 11:29 AM
#6
thanks for your help.
i am very interested in what u said "you can use the serial number of the disc". Please tell me how I can code to get serial number of the disc (cd or floppy).
-
December 5th, 2002, 12:42 PM
#7
-
December 5th, 2002, 02:56 PM
#8
thanks.
But what i want to know now is how to code to get the id of cd or floppy disk.
-
December 5th, 2002, 05:27 PM
#9
The GetVolumeInformation API works for CD and floppy also.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
January 29th, 2003, 06:56 AM
#10
Getting Computer Name
The following code is not giving any output
MsgBox Environ$("computername")
where as the api works but i find its a lengthy code,
pls help.
Dennis.
-
January 29th, 2003, 11:14 AM
#11
Here is some documentation on Environ:
http://www.developerfusion.com/show/1640/show.aspx
(Use the Next >> to read the others pages)
If it is not working, that is probably because you do not have the environnenement variable "computername", someone might have play with windows settings or you just need a reboot. If you still have problem, GetComputerName should be used instead of Environ$
JeffB
-
April 4th, 2005, 12:58 PM
#12
Re: computer name
First let's start by simplifing the code. I'm a strong believer in the less code the better.
Why not use the Environ function.
==========================================================
Code:
Private Sub cmdGetInfo_Click()
Dim strPath As String
Dim strUserName As String
Dim strCompName As String
Dim strOpSystem As String
strPath = Environ("Path")
strUserName = Environ("UserName")
strCompName = Environ("ComputerName")
strOpSystem = Environ("OS")
lblPath = strPath
lblUserName = strUserName & " ---- " & strCompName
lblOpSystem = strOpSystem
End Sub
happy coding
NetWiz
Last edited by Cimperiali; May 5th, 2005 at 04:38 AM.
Reason: Added Code Tags
-
April 4th, 2005, 01:39 PM
#13
Re: computer name
Easiest way of getting the Computer Name (without API's)
1.Check Active DS Type Library is choosen (activeds.tlb)
2.code:
Dim objActiveDs As New ActiveDs.WinNTSystemInfo
MsgBox objActiveDs.ComputerName
-
April 4th, 2005, 05:15 PM
#14
Re: computer name
Originally Posted by socrates4c
Why not use the Environ function...
Note that Environ$() won't work for every case, so API would be more reliable.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
May 2nd, 2005, 05:26 AM
#15
How do i get computer names in my Network or domain
How can i get the computer names in my network. getting a computer name is easy. Please assist. I will be waiting. Thnx
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
|