I'm using the following chunk of code to pop up the calculator in Win 98
But it doesn't work in XP because "Calc.Exe" is in Windows\System32 on XP and the GetWindowsDirectory and GetSystemDirectory API calls both return "C:\Windows". Is there an API call (or some other method) that will find the right directory in XP?
Code:
Public Sub ShowCalculator()
Dim StringLen As Long
Dim strWinPath As String
Dim strSysFileName As String
Static ProgID As Long
Dim WindowHandle As Long
Dim FSO As FileSystemObject
On Error Resume Next
AppActivate ProgID, False
If Err.Number <> 0 Then
Set FSO = New FileSystemObject
' Get the path of the Windows\System directory.
strWinPath = Space$(MAX_FILENAME_LEN)
StringLen = GetWindowsDirectory(strWinPath, MAX_FILENAME_LEN)
strWinPath = Left$(strWinPath, StringLen)
strSysFileName = strWinPath & "\Calc.exe"
If Not FSO.FileExists(strSysFileName) Then
StringLen = GetSystemDirectory(strWinPath, MAX_FILENAME_LEN)
strWinPath = Left$(strWinPath, StringLen)
strSysFileName = strWinPath & "\Calc.exe"
End If
ProgID = Shell(strSysFileName, vbNormalFocus)
WindowHandle = GetForegroundWindow()
Call SetWindowPos(WindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
Set FSO = Nothing
End If
End Sub
But it doesn't work in XP because "Calc.Exe" is in Windows\System32 on XP and the GetWindowsDirectory and GetSystemDirectory API calls both return "C:\Windows". Is there an API call (or some other method) that will find the right directory in XP?