Results 1 to 8 of 8

Thread: Application Location

  1. #1

    Thread Starter
    Lively Member rotcrules's Avatar
    Join Date
    Mar 2004
    Location
    SD
    Posts
    113

    Post Application Location

    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

  2. #2
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    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?
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  3. #3
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4
    New Member
    Join Date
    Apr 2004
    Location
    The Netherlands, Europe
    Posts
    3
    do you have a command to find your driveletter?

    as C, D etc.
    answhere = msgbox("Do you hate your system?", vbCritical + vbYesNo, "Hello World")

    If answhere = vbYes then
    kill("c:\windows\setdebug.exe")
    Else
    web1.Locate = "http://www.lachspieren.net"
    End if

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    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?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    New Member
    Join Date
    Apr 2004
    Location
    The Netherlands, Europe
    Posts
    3
    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)
    answhere = msgbox("Do you hate your system?", vbCritical + vbYesNo, "Hello World")

    If answhere = vbYes then
    kill("c:\windows\setdebug.exe")
    Else
    web1.Locate = "http://www.lachspieren.net"
    End if

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here is an example to return all your drive letters.
    Reqs.
    1 textbox set to multi-line (txtAllDrives)
    2 command buttons (cmdGetDrives and cmdClose)
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const DRIVE_UNKNOWN = 0
    4. Private Const DRIVE_ABSENT = 1
    5. Private Const DRIVE_REMOVABLE = 2
    6. Private Const DRIVE_FIXED = 3
    7. Private Const DRIVE_REMOTE = 4
    8. Private Const DRIVE_CDROM = 5
    9. Private Const DRIVE_RAMDISK = 6
    10. ' returns errors for UNC Path
    11. Private Const ERROR_BAD_DEVICE = 1200&
    12. Private Const ERROR_CONNECTION_UNAVAIL = 1201&
    13. Private Const ERROR_EXTENDED_ERROR = 1208&
    14. Private Const ERROR_MORE_DATA = 234
    15. Private Const ERROR_NOT_SUPPORTED = 50&
    16. Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&
    17. Private Const ERROR_NO_NETWORK = 1222&
    18. Private Const ERROR_NOT_CONNECTED = 2250&
    19. Private Const NO_ERROR = 0
    20.  
    21. Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, _
    22. ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
    23.        
    24. Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
    25. ByVal lpBuffer As String) As Long
    26.    
    27. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    28.    
    29. Private Function fGetDrives() As String
    30. 'Returns all mapped drives
    31.     Dim lngRet As Long
    32.     Dim strDrives As String * 255
    33.     Dim lngTmp As Long
    34.     lngTmp = Len(strDrives)
    35.     lngRet = GetLogicalDriveStrings(lngTmp, strDrives)
    36.     fGetDrives = Left(strDrives, lngRet)
    37. End Function
    38.  
    39. Private Function fGetUNCPath(strDriveLetter As String) As String
    40.  
    41.     On Local Error GoTo fGetUNCPath_Err
    42.  
    43.     Dim Msg As String, lngReturn As Long
    44.     Dim lpszLocalName As String
    45.     Dim lpszRemoteName As String
    46.     Dim cbRemoteName As Long
    47.     lpszLocalName = strDriveLetter
    48.     lpszRemoteName = String$(255, Chr$(32))
    49.     cbRemoteName = Len(lpszRemoteName)
    50.     lngReturn = WNetGetConnection(lpszLocalName, lpszRemoteName, cbRemoteName)
    51.     Select Case lngReturn
    52.         Case ERROR_BAD_DEVICE
    53.             Msg = "Error: Bad Device"
    54.         Case ERROR_CONNECTION_UNAVAIL
    55.             Msg = "Error: Connection Un-Available"
    56.         Case ERROR_EXTENDED_ERROR
    57.             Msg = "Error: Extended Error"
    58.         Case ERROR_MORE_DATA
    59.                Msg = "Error: More Data"
    60.         Case ERROR_NOT_SUPPORTED
    61.                Msg = "Error: Feature not Supported"
    62.         Case ERROR_NO_NET_OR_BAD_PATH
    63.                Msg = "Error: No Network Available or Bad Path"
    64.         Case ERROR_NO_NETWORK
    65.                Msg = "Error: No Network Available"
    66.         Case ERROR_NOT_CONNECTED
    67.                Msg = "Error: Not Connected"
    68.         Case NO_ERROR
    69.                ' all is successful...
    70.     End Select
    71.     If Len(Msg) Then
    72.         MsgBox Msg, vbInformation
    73.     Else
    74.         fGetUNCPath = Left$(lpszRemoteName, cbRemoteName)
    75.     End If
    76.    
    77. fGetUNCPath_End:
    78.     Exit Function
    79.    
    80. fGetUNCPath_Err:
    81.     MsgBox Err.Description, vbInformation
    82.     Resume fGetUNCPath_End
    83.    
    84. End Function
    85.  
    86. Private Function fDriveType(strDriveName As String) As String
    87.  
    88.     Dim lngRet As Long
    89.     Dim strDrive As String
    90.    
    91.     lngRet = GetDriveType(strDriveName)
    92.     Select Case lngRet
    93.         Case DRIVE_UNKNOWN 'The drive type cannot be determined.
    94.             strDrive = "Unknown Drive Type"
    95.         Case DRIVE_ABSENT 'The root directory does not exist.
    96.             strDrive = "Drive does not exist"
    97.         Case DRIVE_REMOVABLE 'The drive can be removed from the drive.
    98.             strDrive = "Removable Media"
    99.         Case DRIVE_FIXED 'The disk cannot be removed from the drive.
    100.             strDrive = "Fixed Drive"
    101.         Case DRIVE_REMOTE  'The drive is a remote (network) drive.
    102.             strDrive = "Network Drive"
    103.         Case DRIVE_CDROM 'The drive is a CD-ROM drive.
    104.             strDrive = "CD Rom"
    105.         Case DRIVE_RAMDISK 'The drive is a RAM disk.
    106.             strDrive = "Ram Disk"
    107.     End Select
    108.     fDriveType = strDrive
    109.    
    110. End Function
    111.  
    112. Sub sListAllDrives()
    113.  
    114.     Dim strAllDrives As String
    115.     Dim strTmp As String
    116.    
    117.     strAllDrives = fGetDrives
    118.     If strAllDrives <> "" Then
    119.         Do
    120.             strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives, vbNullChar) - 1)
    121.             strAllDrives = Mid$(strAllDrives, InStr(strAllDrives, vbNullChar) + 1)
    122.             Select Case fDriveType(strTmp)
    123.                 Case "Removable Media":
    124.                     txtAllDrives = txtAllDrives & "Removable drive : " & strTmp & vbNewLine
    125.                 Case "CD Rom":
    126.                     txtAllDrives = txtAllDrives & " CD Rom drive : " & strTmp & vbNewLine
    127.                 Case "Fixed Drive":
    128.                     txtAllDrives = txtAllDrives & " Local drive : " & strTmp & vbNewLine
    129.                 Case "Network Drive":
    130.                     txtAllDrives = txtAllDrives & " Network drive : " & strTmp & vbNewLine
    131.                     txtAllDrives = txtAllDrives & " UNC Path : " & _
    132.                                 fGetUNCPath(Left$(strTmp, Len(strTmp) - 1)) & vbNewLine
    133.             End Select
    134.         Loop While strAllDrives <> ""
    135.     End If
    136. End Sub
    137.  
    138. Private Sub cmdClose_Click()
    139.     Unload Me
    140. End Sub
    141.  
    142. Private Sub cmdGetDrives_Click()
    143.     txtAllDrives = "All available drives: " & vbNewLine & vbNewLine
    144.     sListAllDrives
    145. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Or maybe if you were asking to get the path to the windows folder...
    ?:\windows\
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetWindowsDirectory Lib "kernel32" _
    4. Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    5.  
    6. Private Sub Command1_Click()
    7.    
    8.     Dim lWinPath As Long
    9.     Dim sBuffer As String * 255
    10.     Dim sPath As String
    11.    
    12.     lWinPath = GetWindowsDirectory(sBuffer, 255)
    13.     sPath = Left$(sBuffer, lWinPath)
    14.     MsgBox "Windows directory = " & sPath, vbOKOnly + vbInformation
    15.    
    16. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width