locked
app.path usage points to system32 instead of the actual start location RRS feed

  • Question

  • VB6 programming.  In the past I have relied on the usage of app.path to identify the actual location of the directory in which my program starts.  Now, I find that app.path is pointing to somewhere in windows system 32.  Why is this happening and how can I return app.path usage to what I expect it to be?  In explanation, if my program 'prog.exe' exists in location c:\users\dan\mystuff and the code of my program reads 'fileloc = app.path' then I expect the contents of fileloc to read "c:\users\dan\mystuff" instead of somewhere in windows system 32. Thanks in advance for any possible clue to solving this problem.  My e-mail name is shandelby@gmail.com
    • Edited by Shandelby Tuesday, July 28, 2020 3:04 PM
    Tuesday, July 28, 2020 3:01 PM

All replies

  • Hi

    Here are a few of the many possible:  the one you are asking for is the AppStartUpPath

    Dim DeskTopPath As String = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop)
    Dim MyDocumentsPath As String = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments)
    Dim AppStartUpPath As String = IO.Path.Combine(Application.StartupPath)

    the 'IO.Path.Combine will append further nodes to the Path as needed. For example:

    Dim AppStartUpPath2 As String = IO.Path.Combine(Application.StartupPath, "Data", "Engines", "MyFile.xml")
    
    ' result: .....\Documents\Projects\WindowsApp3\WindowsApp3\bin\Debug\Data\Engines\MyFile.xml


    Regards Les, Livingston, Scotland


    • Edited by leshay Tuesday, July 28, 2020 3:42 PM
    Tuesday, July 28, 2020 3:38 PM
  • Hello,

    These will do get the executable path.

    Console.WriteLine(Directory.GetCurrentDirectory())
    Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory)
    I prefer AppDomain.CurrentDomain.BaseDirectory over Application.StartupPath as Application.StartupPath doesn't always work in certain projects.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, July 28, 2020 4:18 PM