Hi all!
I am looking for a script to copy and paste a specific file to my Total Commander window at the press of a HotKey. My current script worked beautifully for several years until yesterday, and I cannot figure out why it does not work anymore. When I try to run it, it crashes without an error message.
Here is the current non-working script:
Code: Select all
#IfWinActive, Total Commander ; this script adds the template file to your current Total Commander Window with Ctrl+Shift+4
^+4::FileToClipboard("\\homeserver\users\ID001\template.dbf")
FileToClipboard(PathToCopy,Method="copy")
{
FileCount:=0
PathLength:=0
; Count files and total string length
Loop,Parse,PathToCopy,`n,`r
{
FileCount++
PathLength+=StrLen(A_LoopField)
}
pid:=DllCall("GetCurrentProcessId","uint")
hwnd:=WinExist("ahk_pid " . pid)
; 0x42 = GMEM_MOVEABLE(0x2) | GMEM_ZEROINIT(0x40)
hPath := DllCall("GlobalAlloc","uint",0x42,"uint",20 + (PathLength + FileCount + 1) * 2,"UPtr")
pPath := DllCall("GlobalLock","UPtr",hPath)
NumPut(20,pPath+0),pPath += 16 ; DROPFILES.pFiles = offset of file list
NumPut(1,pPath+0),pPath += 4 ; fWide = 0 -->ANSI,fWide = 1 -->Unicode
Offset:=0
Loop,Parse,PathToCopy,`n,`r ; Rows are delimited by linefeeds (`r`n).
offset += StrPut(A_LoopField,pPath+offset,StrLen(A_LoopField)+1,"UTF-16") * 2
DllCall("GlobalUnlock","UPtr",hPath)
DllCall("OpenClipboard","UPtr",hwnd)
DllCall("EmptyClipboard")
DllCall("SetClipboardData","uint",0xF,"UPtr",hPath) ; 0xF = CF_HDROP
; Write Preferred DropEffect structure to clipboard to switch between copy/cut operations
; 0x42 = GMEM_MOVEABLE(0x2) | GMEM_ZEROINIT(0x40)
mem := DllCall("GlobalAlloc","uint",0x42,"uint",4,"UPtr")
str := DllCall("GlobalLock","UPtr",mem)
if (Method="copy")
DllCall("RtlFillMemory","UPtr",str,"uint",1,"UChar",0x05)
else if (Method="cut")
DllCall("RtlFillMemory","UPtr",str,"uint",1,"UChar",0x02)
else
{
DllCall("CloseClipboard")
return
}
DllCall("GlobalUnlock","UPtr",mem)
cfFormat := DllCall("RegisterClipboardFormat","Str","Preferred DropEffect")
DllCall("SetClipboardData","uint",cfFormat,"UPtr",mem)
DllCall("CloseClipboard")
setwindelay, 2
Send ^v
return
}
return
The default template.dbf file always stays in it's home location: \\homeserver\users\ID001\template.dbf
All I need this script to do is instantly copy/paste the default template.dbf file into my current TC location.
I believe my current script stopped working due to a Windows update, because it not longer works in Win 10, but still works perfectly in Windows 7.
I am open to any ideas.
Thank you,
BeRoM