FileCreateShortcut and Program Files problem.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
KilliK
Posts: 255
Joined: 10 Mar 2016, 21:19

FileCreateShortcut and Program Files problem.

14 Sep 2017, 01:23

Hello.

Notepad2.exe is an 64bit utility installed in the Program Files folder of Windows. It doesnt exist in the Program Files (x86) folder.
If I create its shortcut with the below code:

FileCreateShortcut, "C:\Program Files\Notepad2\Notepad2.exe",Notepad2.lnk

the created shortcut has instead the path "C:\Program Files (x86)\Notepad2\Notepad2.exe and ofc it doesnt work.
What causes this and how can I fix it?

My OS is Windows 10 Pro 64bit
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: FileCreateShortcut and Program Files problem.

14 Sep 2017, 04:02

Does this work for you?

Code: Select all

q::
FileCreateShortcut, "C:\Program Files\Notepad2\Notepad2.exe", %A_Desktop%\Notepad2 (error).lnk
if A_Is64bitOS
	DllCall("kernel32\Wow64DisableWow64FsRedirection", PtrP,0)
FileCreateShortcut, "C:\Program Files\Notepad2\Notepad2.exe", %A_Desktop%\Notepad2.lnk
return
On Windows 7, using AHK 32-bit it actually seems to give me link files with exactly the same contents. With/without the redirection.
Last edited by jeeswg on 17 Feb 2019, 17:25, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
KilliK
Posts: 255
Joined: 10 Mar 2016, 21:19

FileCreateShortcut and Path Redirection problem.

22 Oct 2017, 03:50

Helllo.
No, unfortunately it doesnt work at all.
Both resulted shortcuts have in their target path Program Files (x86) instead of Program Files.
Shouldnt the DLL command be enough to bypass the Windows' path redirection? :eh:

I also used this small script I found, to edit the resulted shortcut and change its target path to Program Files, but again the path becomes Program Files (x86):

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; https://msdn.microsoft.com/en-us/library/xsy6k3ys(v=vs.84).aspx
; https://msdn.microsoft.com/en-us/library/xk6kst2k(v=vs.84).aspx
wsh := ComObjCreate("WScript.Shell")
lnk := wsh.CreateShortcut("<path to existing lnk file or one to create>")
lnk.TargetPath := "D:\"
lnk.Save()
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: FileCreateShortcut and Program Files problem.

22 Oct 2017, 11:21

Btw did you try this in AHK x64?

If it works in AHK x64, then in the worst-case scenario you could use AHK x32 with ExecScript to run a temporary x64 script.

Run / RunWait
https://autohotkey.com/docs/commands/Run.htm#ExecScript
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
KilliK
Posts: 255
Joined: 10 Mar 2016, 21:19

Re: FileCreateShortcut and Program Files problem.

23 Oct 2017, 06:19

I have installed the 64bit version of AHK. and I am running Windows 10 64bit.
I used a batch file to create a shortcut and the Program Files path was kept. only AHK changes it to Program Files (x86)
I will try your suggestion.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: FileCreateShortcut and Program Files problem.

23 Oct 2017, 12:11

Btw could you post the code for the batch file, because AHK can usually execute batch commands directly. I had meant to suggest batch files as a workaround if other things failed, although I haven't used it before to create shortcut files.

Since I didn't have any problems doing this with AHK x32 in Windows 7, perhaps Windows 10 has changed something re. handling x32 processes, or perhaps something about the FileCreateShortcut command no longer works with Windows 10.

One possible workaround. Although the Recent folder doesn't work with exe files I believe. But if this did work, it might confirm that certain things do still work on Windows 10.

Code: Select all

q::
;vPath := "C:\Program Files\7-Zip\7zFM.exe"
vPath := "C:\Program Files\test.txt"
SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
DllCall("shell32\SHAddToRecentDocs", UInt,0x3, Str,vPath) ;SHARD_PATHW = 0x3
vPath1 := "C:\Users\" A_UserName "\AppData\Roaming\Microsoft\Windows\Recent\" vNameNoExt ".lnk"
MsgBox, % FileExist(vPath1)
vPath2 := A_Desktop "\z my test lnk.lnk"
FileCopy, % vPath1, % vPath2
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: FileCreateShortcut and Program Files problem.

23 Oct 2017, 12:23

huh... using just this:
FileCreateShortcut, "C:\Program Files (x86)\Notepad2\Notepad2.exe", %A_Desktop%\Notepad2.lnk
or
FileCreateShortcut, "C:\Program Files\Notepad2\Notepad2.exe", %A_Desktop%\Notepad2.lnk
makes the shortcut with the correct address on my system. Also win 10 64 pro.
Maybe theres something else wrong with the OS instead?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RandomBoy and 394 guests