Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Private Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer Private Declare Function GetForegroundWindow Lib "user32" () As Long Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Public Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type ' ********************************** ' ********************************** Public Function getWinVersion() As String Dim osinfo As OSVERSIONINFO Dim retvalue As Integer osinfo.dwOSVersionInfoSize = 148 osinfo.szCSDVersion = Space$(128) retvalue = GetVersionExA(osinfo) With osinfo Select Case .dwPlatformId Case 1 If .dwMinorVersion = 0 Then getWinVersion = "Windows 95" ElseIf .dwMinorVersion = 10 Then getWinVersion = "Windows 98" End If Case 2 If .dwMajorVersion = 3 Then getWinVersion = "Windows NT 3.51" ElseIf .dwMajorVersion = 4 Then getWinVersion = "Windows NT 4.0" ElseIf .dwMajorVersion = 5 Then getWinVersion = "Windows 2000" End If Case Else getWinVersion = "Failed " & "Platform Id " & Str(dwPlatformId) & "Maj " & Str(dwMajorVersion) End Select End With End Function ' Returns the window title text Public Function TopWindow() As String Dim hWnd As Long, llen As Long Dim strTitle As String strTitle = Space(255) & vbNullChar hWnd = GetForegroundWindow() llen = GetWindowText(hWnd, strTitle, 255&) If llen > 0 Then strTitle = Left$(strTitle, llen) TopWindow = strTitle Else TopWindow = "Error retrieving title" End If End Function Public Function GetWinDir() As String Dim strPath As String * 255 ReturnLength = GetWindowsDirectory(strPath, Len(strPath)) GetWinDir = AlphaNumericsOnly(strPath) End Function Public Function GetWinSysDir() As String Dim strPath As String * 255 ReturnLength = GetSystemDirectory(strPath, Len(strPath)) GetWinSysDir = AlphaNumericsOnly(strPath) ' a must have. End Function Public Function GetSysDir() As String GetSysDir = GetWinSysDir End Function Public Function GetDesktop() As String Dim strDesktop As String Dim strOS As String Dim strWinDir As String Dim strUserName As String Dim lngNameLen As Long strUserName = Space(64) lngNameLen = Len(strUserName) strOS = getWinVersion strWinDir = GetWinDir GetUserName strUserName, lngNameLen strDesktop = "" If Left$(strOS, 9) = "Windows 9" Then strDesktop = strWinDir + "\Desktop" Else strDesktop = strWinDir & _ "\Profiles\" & _ Left$(Trim$(strUserName), Len(Trim$(strUserName)) - 1) & _ "\Desktop\" End If If Dir$(strDesktop, vbDirectory) <> "" Then GetDesktop = strDesktop End If End Function
"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams