環境変数取得(U) <TOP>
環境変数を取得します。
GetEnvironmentVariable 環境変数取得
F-BASICでのenviron$関数と同じです。
'================================================================ '= 環境変数取得
'= (GetEnvironmentVariable.bas) '================================================================ #include "Windows.bi" ' 環境変数取得 Declare Function Api_GetEnvironmentVariable& Lib "kernel32" Alias "GetEnvironmentVariableA" (ByVal lpszName$, ByVal lpszValue$, ByVal cchValue&) Var Shared Text1 As Object Var Shared Combo1 As Object Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14 Combo1.Attach GetDlgItem("Combo1") : Combo1.SetFontSize 14 Var Shared kh(29) As String '================================================================ '= '================================================================ Declare Function GetEnv(sName As String) As String Function GetEnv(sName As String) As String Var Buffer As String Var Size As Long Var Ret As Long GetEnv = "" Buffer = String$(512, Chr$(0)) Size = Api_GetEnvironmentVariable(sName, Buffer, 512) If Size = 0 Then Else If Size <= 512 Then GetEnv = Left$(Buffer, InStr(Buffer, Chr$(0)) - 1) Else Buffer = String$(Size, Chr$(0)) Ret = Api_GetEnvironmentVariable(sName, Buffer, Size) If Ret = Size - 1 Then GetEnv = Left$(Buffer, InStr(Buffer, Chr$(0)) - 1) End If End If End Function '================================================================ '= '================================================================ Declare Sub MainForm_Start edecl () Sub mainForm_Start() Combo1.ResetContent For i = 1 To 29 Read kh(i) Combo1.AddString Format$(i,"##:") & kh(i) Next '-------------------- data ALLUSER data ALLUSERSPROFILE data APPDATA data CLIENTNAME data CommonProgramFiles data COMPUTERNAME data ComSpec data FP_NO_HOST_CHECK data HOMEDRIVE data HOMEPATH data LOGONSERVER data NUMBER_OF_PROCESSORS data OS data Path data PATHEXT data PROCESSOR_ARCHITECTURE data PROCESSOR_IDENTIFIER data PROCESSOR_LEVEL data PROCESSOR_REVISION data ProgramFiles data SESSIONNAME data SystemDrive data SystemRoot data TEMP data TMP data USERDOMAIN data USERNAME data USERPROFILE data WINDIR End Sub '================================================================ '= '================================================================ Declare Sub Combo1_Change edecl () Sub Combo1_Change() Var index As Long index = Combo1.GetCursel + 1 Text1.SetWindowText GetEnv(kh(index)) End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End