Creating a hard link
Posted: Sun Sep 09, 2018 4:02 pm
The hard link requirements by microsoft for windows are : NTFS file system V5 or above, administrator rights to create them, with win32 API : CreateHardLinkW or via commandline "{systemfolder}\cmd.exe /q /s mklink /h" (its a standard cmd.exe internal command with recent windows versions). I tried both methods and try to get a clean simple win32 api method running, but no matter which kind of string passing or pototype for import i use, i always get the result of "failed" with a lasterror() of 2 (see error codes). I tried pointers and direct argument passing as p-utf8, p-unicode and string on PB 5.62 x86. The NTFS versions are the latest official, so it should be above Ver. 5. My OS is Windows7 x64, i wonder if i have to use the 64bit PB 5.62 version 
Any hint why it does'nt work?
The snippet was comiled in a project with admin rights and i get the UAC confirmation request so that should be fine.
ignore the german text, it should be irrelevant to the problem 

Any hint why it does'nt work?
The snippet was comiled in a project with admin rights and i get the UAC confirmation request so that should be fine.
Code: Select all
Import "Kernel32.lib"
CreateHardLinkW(lpLinkFileName.p-unicode, lpExistingFileName.p-unicode, lpSecurityAttributes.i = 0)
GetLastError.i()
EndImport
EnableExplicit
Define LinkResult.i, ErrorCode.i = 0
Debug "link test"
LinkResult = CreateHardLinkW("e:\linktest.exe", "e:\streamwriter.exe")
If (LinkResult = 0)
Debug "Ein fehler ist aufgetreten"
ErrorCode = GetLastError()
EndIf
Debug "Ergebnis war " + Str(LinkResult) + " ErrorCode = " + Str(ErrorCode)
