PDA

Click to See Complete Forum and Search --> : Application Location


rotcrules
Mar 18th, 2004, 11:41 AM
Does anyone know how to get the location of the Application?
What I am trying to do is to make the app run every time windows starts. I already have all of the info of how to put it into the registry but I need to know where the application is.

I was thinking maby get the location from the properties of the *.exe or something along that line.

Thank You

TheFIDDLER
Mar 18th, 2004, 03:21 PM
Can we have more details? What application are we talking about?

Are we talking about an MS Office component, or a custom exe file.

Using the StartUp Menu would seem kind of obvious....

Conceivably, if you can open the application, you can just cut and paste this shortcut to the startup folder.

Or do you want to code this as part of your setup.exe process?

alex_read
Mar 19th, 2004, 07:45 AM
I'm guessing you want to run this from within your application itself.

If this is a vb project, you can use the app.path statement to retreive the current location of the exe.

If this is an MsOffice application, you can call upon the application.path statement to do the same thing.

lachspieren
Apr 3rd, 2004, 04:34 PM
do you have a command to find your driveletter?

as C, D etc.

RobDog888
Apr 3rd, 2004, 05:11 PM
The Application.Path will contain the drive letter in the path if that
is what you mean. Or do you mean find all drive letters on your
system?

lachspieren
Apr 3rd, 2004, 05:37 PM
I mean the drive letter from your harddisk.

?:\windows\

where ? is your driveletter, but i dont know the function.

(My English is not good, sorry)

RobDog888
Apr 3rd, 2004, 05:47 PM
Here is an example to return all your drive letters.
Reqs.
1 textbox set to multi-line (txtAllDrives)
2 command buttons (cmdGetDrives and cmdClose)
Option Explicit

Private Const DRIVE_UNKNOWN = 0
Private Const DRIVE_ABSENT = 1
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6
' returns errors for UNC Path
Private Const ERROR_BAD_DEVICE = 1200&
Private Const ERROR_CONNECTION_UNAVAIL = 1201&
Private Const ERROR_EXTENDED_ERROR = 1208&
Private Const ERROR_MORE_DATA = 234
Private Const ERROR_NOT_SUPPORTED = 50&
Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Private Const ERROR_NO_NETWORK = 1222&
Private Const ERROR_NOT_CONNECTED = 2250&
Private Const NO_ERROR = 0

Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, cbRemoteName As Long) As Long

Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Private Function fGetDrives() As String
'Returns all mapped drives
Dim lngRet As Long
Dim strDrives As String * 255
Dim lngTmp As Long
lngTmp = Len(strDrives)
lngRet = GetLogicalDriveStrings(lngTmp, strDrives)
fGetDrives = Left(strDrives, lngRet)
End Function

Private Function fGetUNCPath(strDriveLetter As String) As String

On Local Error GoTo fGetUNCPath_Err

Dim Msg As String, lngReturn As Long
Dim lpszLocalName As String
Dim lpszRemoteName As String
Dim cbRemoteName As Long
lpszLocalName = strDriveLetter
lpszRemoteName = String$(255, Chr$(32))
cbRemoteName = Len(lpszRemoteName)
lngReturn = WNetGetConnection(lpszLocalName, lpszRemoteName, cbRemoteName)
Select Case lngReturn
Case ERROR_BAD_DEVICE
Msg = "Error: Bad Device"
Case ERROR_CONNECTION_UNAVAIL
Msg = "Error: Connection Un-Available"
Case ERROR_EXTENDED_ERROR
Msg = "Error: Extended Error"
Case ERROR_MORE_DATA
Msg = "Error: More Data"
Case ERROR_NOT_SUPPORTED
Msg = "Error: Feature not Supported"
Case ERROR_NO_NET_OR_BAD_PATH
Msg = "Error: No Network Available or Bad Path"
Case ERROR_NO_NETWORK
Msg = "Error: No Network Available"
Case ERROR_NOT_CONNECTED
Msg = "Error: Not Connected"
Case NO_ERROR
' all is successful...
End Select
If Len(Msg) Then
MsgBox Msg, vbInformation
Else
fGetUNCPath = Left$(lpszRemoteName, cbRemoteName)
End If

fGetUNCPath_End:
Exit Function

fGetUNCPath_Err:
MsgBox Err.Description, vbInformation
Resume fGetUNCPath_End

End Function

Private Function fDriveType(strDriveName As String) As String

Dim lngRet As Long
Dim strDrive As String

lngRet = GetDriveType(strDriveName)
Select Case lngRet
Case DRIVE_UNKNOWN 'The drive type cannot be determined.
strDrive = "Unknown Drive Type"
Case DRIVE_ABSENT 'The root directory does not exist.
strDrive = "Drive does not exist"
Case DRIVE_REMOVABLE 'The drive can be removed from the drive.
strDrive = "Removable Media"
Case DRIVE_FIXED 'The disk cannot be removed from the drive.
strDrive = "Fixed Drive"
Case DRIVE_REMOTE 'The drive is a remote (network) drive.
strDrive = "Network Drive"
Case DRIVE_CDROM 'The drive is a CD-ROM drive.
strDrive = "CD Rom"
Case DRIVE_RAMDISK 'The drive is a RAM disk.
strDrive = "Ram Disk"
End Select
fDriveType = strDrive

End Function

Sub sListAllDrives()

Dim strAllDrives As String
Dim strTmp As String

strAllDrives = fGetDrives
If strAllDrives <> "" Then
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives, vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives, vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media":
txtAllDrives = txtAllDrives & "Removable drive : " & strTmp & vbNewLine
Case "CD Rom":
txtAllDrives = txtAllDrives & " CD Rom drive : " & strTmp & vbNewLine
Case "Fixed Drive":
txtAllDrives = txtAllDrives & " Local drive : " & strTmp & vbNewLine
Case "Network Drive":
txtAllDrives = txtAllDrives & " Network drive : " & strTmp & vbNewLine
txtAllDrives = txtAllDrives & " UNC Path : " & _
fGetUNCPath(Left$(strTmp, Len(strTmp) - 1)) & vbNewLine
End Select
Loop While strAllDrives <> ""
End If
End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub

Private Sub cmdGetDrives_Click()
txtAllDrives = "All available drives: " & vbNewLine & vbNewLine
sListAllDrives
End Sub

RobDog888
Apr 3rd, 2004, 05:54 PM
Or maybe if you were asking to get the path to the windows folder...
?:\windows\
Option Explicit

Private Declare Function GetWindowsDirectory Lib "kernel32" _
Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Private Sub Command1_Click()

Dim lWinPath As Long
Dim sBuffer As String * 255
Dim sPath As String

lWinPath = GetWindowsDirectory(sBuffer, 255)
sPath = Left$(sBuffer, lWinPath)
MsgBox "Windows directory = " & sPath, vbOKOnly + vbInformation

End Sub