Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Const SM_REMOTESESSION As Long = &H1000
Function IsTerminalServer() As Boolean
' Vérifie si la session est une session distante (Terminal Server ou Remote Desktop)
IsTerminalServer = (GetSystemMetrics(SM_REMOTESESSION) <> 0)
End Function
Sub Test_IsTerminalServer()
If IsTerminalServer Then
MsgBox "Le PC est en mode Terminal Server (session distante).", vbInformation
Else
MsgBox "Le PC est en session locale.", vbInformation
End If
End Sub
'****************************************************************************************
'une fonction toute bête
Function GetComputerName() As String
GetComputerName = Environ("COMPUTERNAME")
End Function
Sub Test_GetComputerName()
MsgBox GetComputerName
End Sub
'****************************************************************************************
'récupérer l'addresse Mac
Function GetMACAddress() As String
Dim objWMIService As Object
Dim colItems As Object
Dim objItem As Object
Dim macAddress As String
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem In colItems
If Not IsNull(objItem.macAddress) Then
macAddress = objItem.macAddress
Exit For
End If
Next objItem
GetMACAddress = macAddress
End Function
Sub testaddMac()
MsgBox GetMACAddress
End Sub
'****************************************************************************************
'recuperer le GUID du pc {Globally Unique Identifier]
Function GetPCGUID() As String
Dim objWMIService As Object
Dim colItems As Object
Dim objItem As Object
Dim guid As String
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystemProduct")
For Each objItem In colItems
guid = objItem.UUID
Exit For
Next objItem
GetPCGUID = guid
End Function
Sub Test_GetPCGUID()
MsgBox GetPCGUID
End Sub
'****************************************************************************************
'identifiant de la carte mère
Function GetMotherboardID() As String
Dim objWMIService As Object
Dim colItems As Object
Dim objItem As Object
Dim motherboardID As String
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BaseBoard")
For Each objItem In colItems
motherboardID = objItem.SerialNumber
Exit For
Next objItem
GetMotherboardID = motherboardID
End Function
Sub Test_GetMotherboardID()
MsgBox GetMotherboardID
End Sub
'****************************************************************************************