Recent

Author Topic: Creating a symbolic link  (Read 953 times)

antispam88

  • New member
  • *
  • Posts: 47
Creating a symbolic link
« on: January 28, 2019, 05:17:46 pm »
Hi,

I'm using mklink to create a symboic link under windows (7/8.1/10).
Because mklink is part of the cmd I use following code:
Code: Pascal  [Select]
  1.       proc := TProcess.Create(nil);
  2.       proc.Executable := STR_EXE_CMD;
  3.       proc.Options := proc.Options + [poUsePipes];
  4.       proc.Execute;
  5.       mklink_cmd := Format('%s %s "%s" "%s"%s', [STR_EXE_MKLINK,
  6.         STR_PARAM_SYMLINK, __path_reports_dst, __path_reports_src, LineEnding]);
  7.       proc.Input.Write(mklink_cmd[1], Length(mklink_cmd));
  8.       Sleep(100);

But with that code I don't get any response from mklink.
I have already checked the Output stream, but there is only the cmd header and the mklink call:
Code: Pascal  [Select]
  1. Microsoft Windows [Version 10.0.17134.523]
  2. (c) 2018 Microsoft Corporation. Alle Rechte vorbehalten.
  3.  
  4. C:\daten\src\projects\project1\bin>mklink /D "C:\server\reports\" "C:\server\www\reports\"
  5.  
  6. C:\daten\src\projects\project1\bin>

So is there a way to get the response of mklink?
Or is another option the create a symbolic link under windows.

Best regards,
antispam88
« Last Edit: January 28, 2019, 05:19:19 pm by antispam88 »


Bart

  • Hero Member
  • *****
  • Posts: 3435
    • Bart en Mariska's Webstek
Re: Creating a symbolic link
« Reply #2 on: January 28, 2019, 06:42:45 pm »
Googling windows sybolic link gives me: https://docs.microsoft.com/en-us/windows/desktop/api/WinBase/nf-winbase-createsymboliclinka

Code: C  [Select]
  1. BOOLEAN CreateSymbolicLinkA(
  2.   LPCSTR lpSymlinkFileName,
  3.   LPCSTR lpTargetFileName,
  4.   DWORD  dwFlags
  5. );

The function is in Kernel32.dll

Bart

antispam88

  • New member
  • *
  • Posts: 47
Re: Creating a symbolic link
« Reply #3 on: January 28, 2019, 09:48:02 pm »
I had already read about these functions.
But I thought, that there is an option to use mklink in a correct way ...

Nevertheless I'm using now CreateSymbolicLinkW and it is working as expected.

While the initial way is not solved the main target is.

Thanks,
antispam88