コンピュータ名・ユーザ名の取得             <TOP>


コンピュータ名およびユーザ名を取得します。

GetComputerName コンピュータ名取得

GetUserName ユーザ名を取得

 


参照
ユーザ名を取得

 

'================================================================
'= コンピュータ名・ユーザー名取得
'=    (ComUsrName.bas)
'================================================================
#include "Windows.bi"

' コンピュータの名前を文字列として取得
Declare Function Api_GetComputerName& Lib "Kernel32" Alias "GetComputerNameA" (ByVal lpBuffer$, nSize&)

' ユーザー名を取得
Declare Function Api_GetUserName& Lib "advapi32" Alias "GetUserNameA" (ByVal lpBuffer$, nSize&)

Var Shared Text1 As Object
Var Shared Button1 As Object

Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14

'================================================================
'= 
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var PcName As String
    Var UserName As String
    Var Length As Long
    Var txt As String
    Var Ret As Long

    PcName = String$(250, Chr$(0))
    Length = Len(PcName)
    Ret = Api_GetComputerName(PcName, Length)
    PcName = Left$(PcName, InStr(PcName, Chr$(0)) - 1)

    UserName = String$(250, Chr$(0))
    Length = Len(UserName)
    Ret = Api_GetUserName(UserName, Length)
    UserName = Left$(UserName, InStr(UserName, Chr$(0)) - 1)

    txt = "Computer Name:" & PcName & Chr$(13, 10) & "User Name    :" & UserName
    Text1.SetWindowtext txt
End Sub

'================================================================
'= 
'================================================================
While 1
    WaitEvent
Wend
Stop
End