Visual Basic 中学校 > Visual Basic サンプル集 > Visual Basic サンプル集目次 >
Windowsフォルダの場所を取得する
WindowsFolder = Environment.GetEnvironmentVariable("WINDIR") |
メモ:Windowsフォルダは標準ではWindows95/98/Me/XPは「C:\Windows」、Windows NT/2000では「C:\Winnt」。しかし、標準でインストールしない人やドライブを変えている人がいるので上記の例のようにWindowsフォルダの場所を取得する必要がある。
参考:環境変数に依存しない方法
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer |
Private
Function WindowsFolder()
As
String
Dim FolderName As
String = New
String(" ", 260) RetLength = GetWindowsDirectory(FolderName, FolderName.Length) Return FolderName.Substring(0, RetLength) End Function |
Private
Sub Button1_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles Button1.Click MsgBox(WindowsFolder()) End Sub |
参照
システムフォルダの場所を取得する Tempフォルダの場所を取得する
VB6では「Windowsフォルダの場所を取得する」を参照。