Recent

Author Topic: [Solved] GetCurrentDir is giving me location of my shortcut  (Read 443 times)

nikel

  • Full Member
  • ***
  • Posts: 240
[Solved] GetCurrentDir is giving me location of my shortcut
« on: February 10, 2025, 06:04:18 am »
Hello, I'm trying to get my executeble's location. I had been using GetCurrentDir command, I compiled it as msi and installed it. The desktop shortcut is giving me this folder: C:\Users\User\Desktop

How can I get location of my executable?
« Last Edit: February 10, 2025, 09:10:21 am by nikel »

Fibonacci

  • Hero Member
  • *****
  • Posts: 653
  • Internal Error Hunter
Re: GetCurrentDir is giving me location of my shortcut
« Reply #1 on: February 10, 2025, 06:29:25 am »
GetCurrentDir returns current working directory. For the actual location you can use ParamStr(0):
Code: Pascal  [Select][+][-]
  1. ExtractFileDir(ParamStr(0))

If on Windows, you can also use GetModuleFileName:
Code: Pascal  [Select][+][-]
  1. var
  2.   s: string;
  3.  
  4. begin
  5.   setlength(s, 500);
  6.   setlength(s, GetModuleFileName(0, @s[1], length(s)));
  7.   writeln('GetModuleFileName = ', ExtractFileDir(s));

nikel

  • Full Member
  • ***
  • Posts: 240
Re: GetCurrentDir is giving me location of my shortcut
« Reply #2 on: February 10, 2025, 07:43:24 am »
Thanks for the info. I'll try that.

Zvoni

  • Hero Member
  • *****
  • Posts: 2921
Re: GetCurrentDir is giving me location of my shortcut
« Reply #3 on: February 10, 2025, 08:35:52 am »
Application.Location?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018