Get and set local computer name
By: Lorenzo Dalla Vecchia Date: 16/07/2001
File:

computername.zip

Size:

524 bytes

Download now!

The module you can download here contains two procedures, a function and a sub, the first allowing you to get the network name of your computer and the second to change it to whatever you like.
This setting can be modified manually with the Network icon of the Control Panel.

Syntax

result = GetComputerName
SetComputerName(NewName)

Parameters

NewName: the new name for the local computer

Type of data

String
N/A

Returns

The current network name of the computer as a text string
N/A

-

Example

The following code first reads for the current computer name and then changes it to Computer18.

Dim CurrName As String

'Read current name

CurrName = GetComputerName
MsgBox "The current name is: " & CurrName

'Set new name and verify the change

Call SetComputerName("Computer18")
CurrName = GetComputerName
MsgBox "Name changed to " & CurrName

The procedures are contained in a module. You can include it in any program of yours.

Click Here!


Visual Basic Programming Zone is a website by Lorenzo Dalla Vecchia.
To contact the Webmaster, click here.
Hosted by InWind: www.inwind.it