How to find current computer/machine name? 
Author Message
 How to find current computer/machine name?

I am using Access97 to build app. I need to find current
computer/machine name my application is running. Is there any lib
function I can use? I knew environ() might help, but my application need
to be able to run on both NT4.0 and Win95. Win95 does not have the
machine name environment variable in the environment string table.

Thanks - John



Tue, 09 Jan 2001 03:00:00 GMT  
 How to find current computer/machine name?

John,

You can use win api. Below are the codes for a function called ComputerName that return the machine name. I've got it from other people in this group before and it works in win95.

Declare Function GetComputerName Lib "kernel32" _
     Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function ComputerName() As String
Dim strComputerName As  string

strComputerName = Space(255)
If GetComputerName(strComputerName, (Len(strComputerName) + 1)) Then
    strComputerName = Trim$(strComputerName)
    strComputerName = Left(strComputerName, Len(strComputerName) - 1)
    ComputerName = strComputerName
    Else
    ComputerName = "ComputerNameError"
End If
ComputerName_Exit:
Exit Function
ComputerName_Err:
    MsgBox Err.Description
    Resume ComputerName_Exit
End Function

Hope this helps

Circe

Quote:

>I am using Access97 to build app. I need to find current
>computer/machine name my application is running. Is there any lib
>function I can use? I knew environ() might help, but my application need
>to be able to run on both NT4.0 and Win95. Win95 does not have the
>machine name environment variable in the environment string table.

>Thanks - John




Tue, 09 Jan 2001 03:00:00 GMT  
 How to find current computer/machine name?
Here is an example:
http://c85.cemi.rssi.ru/access/TipDetail.idc?TipID=12

Best regards,
___________
Alex Dybenko
Point Limited

Home Page: http://www.geocities.com/SiliconValley/Heights/5091/
Moscow MS Access User Group
http://www.arimsoft.ru/msaccess

Quote:

>I am using Access97 to build app. I need to find current
>computer/machine name my application is running. Is there any lib
>function I can use? I knew environ() might help, but my application need
>to be able to run on both NT4.0 and Win95. Win95 does not have the
>machine name environment variable in the environment string table.

>Thanks - John




Tue, 09 Jan 2001 03:00:00 GMT  
 How to find current computer/machine name?
It works, Thanks!

-John

Quote:

> Here is an example:
> http://c85.cemi.rssi.ru/access/TipDetail.idc?TipID=12

> Best regards,
> ___________
> Alex Dybenko
> Point Limited

> Home Page: http://www.geocities.com/SiliconValley/Heights/5091/
> Moscow MS Access User Group
> http://www.arimsoft.ru/msaccess


> >I am using Access97 to build app. I need to find current
> >computer/machine name my application is running. Is there any lib
> >function I can use? I knew environ() might help, but my application
> need
> >to be able to run on both NT4.0 and Win95. Win95 does not have the
> >machine name environment variable in the environment string table.

> >Thanks - John




Tue, 09 Jan 2001 03:00:00 GMT  
 How to find current computer/machine name?
Hi John,
You can use the following Class

Create a new Class module, call it cVol and paste the following in.

'***************  Code Start  *****************
Option Compare Database
Option Explicit

Private Const FS_CASE_SENSITIVE As Long = &H1
Private Const FS_CASE_IS_PRESERVED As Long = &H2
Private Const FS_UNICODE_STORED_ON_DISK As Long = &H4
Private Const FS_PERSISTENT_ACLS As Long = &H8
Private Const FS_FILE_COMPRESSION As Long = &H10
Private Const FS_VOL_IS_COMPRESSED As Long = &H8000

Private Type TypeVolInfo
  RootPath As String
  ComputerName As String
  VolNameBuff As String
  VolNameSize As Long
  VolSerialNum As Long
  MaxCompLength As Long
  FileSysFlags As Long
  FileSysName As String
  FileSysNameSize As Long
End Type

Private Declare Function GetVolumeInformation Lib "kernel32" Alias _
    "GetVolumeInformationA" (ByVal lpRootPathName As String, _
    ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _
    lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, _
    lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, _
    ByVal nFileSystemNameSize As Long) As Long

Private Declare Function GetComputerName Lib "kernel32" Alias _
    "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Const MAX_PATH = 255
Private VolumeInfo As TypeVolInfo

Property Let Drive(DriveLetter As String)
  VolumeInfo.RootPath = DriveLetter & ":\"
  Call VolInfo
End Property
Property Get Drive() As String
  Drive = Left(VolumeInfo.RootPath, 1)
End Property

Property Get VolName() As String
  VolName = VolumeInfo.VolNameBuff
End Property

Property Get VolSystem() As String
  VolSystem = VolumeInfo.FileSysName
End Property
Property Get VolNum() As String

End Property
Property Get ComputerName() As String
  ComputerName = VolumeInfo.ComputerName
End Property

Private Sub VolInfo()
  Dim lngRet As Long
  With VolumeInfo
    .FileSysNameSize = MAX_PATH
    .ComputerName = String$(MAX_PATH, 0)
    lngRet = GetComputerName(.ComputerName, .FileSysNameSize)
    .ComputerName = Left(.ComputerName, .FileSysNameSize)
    .FileSysNameSize = MAX_PATH
    .VolNameBuff = String$(12, 0)
    .VolNameSize = 12
    .FileSysName = String$(255, 0)
    lngRet = GetVolumeInformation(.RootPath, _
             .VolNameBuff, .VolNameSize, .VolSerialNum, _
             .MaxCompLength, .FileSysFlags, _
             .FileSysName, .FileSysNameSize)
    .VolNameBuff = Left(.VolNameBuff, InStr(.VolNameBuff, vbNullChar) - 1)
    .FileSysName = Left(.FileSysName, InStr(.FileSysName, vbNullChar) - 1)
  End With
End Sub
'***************  Code End  *****************

Call it in the following manner

Function TestcVol()
  Dim loVol As cVol
  Set loVol = New cVol
  With loVol
    .Drive = "c"
    Debug.Print .Drive
    Debug.Print .ComputerName
    Debug.Print .VolName
    Debug.Print .VolNum
    Debug.Print .VolSystem
  End With
End Function

Quote:

>I am using Access97 to build app. I need to find current
>computer/machine name my application is running. Is there any lib
>function I can use? I knew environ() might help, but my application need
>to be able to run on both NT4.0 and Win95. Win95 does not have the
>machine name environment variable in the environment string table.

>Thanks - John




Tue, 09 Jan 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How do I find the Computer Name for a NT machine

2. ADSI:GetObject network path not found reading info other than the current computer name

3. retreiving the computer login name and machine name

4. Getting current machine name

5. Need machine names of all networked computers

6. Retrieve name of current sub/function and name of current module

7. Finding Machine Name

8. How to find name of remote machine

9. Finding Current Procedure Name in Code

10. How to find current field name

11. Finding the current control name.

 

 
Powered by phpBB® Forum Software