meows

FileCreateShortcut works but not working right,,

3 posts in this topic

236

This works perfect for desktop shortcuts

$ink = "\cleaner.lnk"
$cmd = "C:\AutoIt3\Code\00_Trials\Installer\Cleaner.exe"
$icon = "C:\32.ico"                    ; & "\au3",
FileCreateShortcut($cmd , @DesktopDir & $ink  , @ScriptDir, "", "Tooltip description of the shortcut.", $icon,  @SW_MINIMIZE)

This works perfect for the Program Files Menu

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

$cmd = "C:\AutoIt3\Code\00_Trials\Installer\Cleaner.exe"
$icon = "C:\32.ico"
$ink = "\cleaner.lnk"

FileCreateShortcut($cmd , @ProgramsDir & $ink  , @ScriptDir, "", "Tooltip description of the shortcut.", $icon,  @SW_MINIMIZE)

However this has me so confused and dazed I had to change DishNet to Sirius 60's/70's Motown to chill.

My problem is I have confirmed variables for each section of the script but it does not put the variable in the correct place or it ignores it altogether,

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
Global $ifullpath
Global $iicoFile
Global $iSoftTitle
Global $iincFile
Global $incthing
;------------------$cmd = "C:\00test_Installer\00bons1.exe"
$cmd = $ifullpath
;------------------$icon = "C:\32.ico"
$icon = $iicoFile
;----------------------------$ink = "\file.ini"
$ink = $incthing
;------------------------- $iSoftTitle = \SoftTitle.ini
$Tooltip = $iSoftTitle
IniRead(@ScriptDir & "\SoftTitle.ini", "General", ".", $iSoftTitle)
 Local $iSoftTitle = IniRead(@ScriptDir & "\SoftTitle.ini", "General", ".", "")
 MsgBox(4096,"$iSoftTitle", $iSoftTitle)
; Retrieve the system environment variable called %PATH%.
    Local $sEnvVar = EnvGet("PATH")
    ; Assign the system environment variable called %PATH% with its current value as well as the script directory.
    ; When you assign an environment variable you do so minus the percentage signs (%).
    EnvSet("PATH", $sEnvVar & ";" & @ScriptDir)
    ; Refresh the OS environment for changes to take affect.
    EnvUpdate()
IniRead(@ScriptDir & "\fullpath.ini", "General", ".", $ifullpath)
 Local $ifullpath = IniRead(@ScriptDir & "\fullpath.ini", "General", ".", "")
 MsgBox(4096,"$ifullpath", $ifullpath)
 Local $sEnvVar = EnvGet("PATH")
    ; Assign the system environment variable called %PATH% with its current value as well as the script directory.
    ; When you assign an environment variable you do so minus the percentage signs (%).
    EnvSet("PATH", $sEnvVar & ";" & @ScriptDir)
    ; Refresh the OS environment for changes to take affect.
    EnvUpdate()
IniRead(@ScriptDir & "\icoFile.ini", "General", ".", $iicoFile)
 Local $iicoFile = IniRead(@ScriptDir & "\icoFile.ini", "General", ".", "")
  MsgBox(4096,"$iicoFile", $iicoFile)
  Local $sEnvVar = EnvGet("PATH")
    ; Assign the system environment variable called %PATH% with its current value as well as the script directory.
    ; When you assign an environment variable you do so minus the percentage signs (%).
    EnvSet("PATH", $sEnvVar & ";" & @ScriptDir)
    ; Refresh the OS environment for changes to take affect.
    EnvUpdate()
IniRead(@ScriptDir & "\File.ini", "General", ".", $iincFile)
 Local $iincFile = IniRead(@ScriptDir & "\File.ini", "General", ".", "")
  MsgBox(4096,"$iincFile", $iincFile)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"\" & $iincFile &".ink" = $incthing
$incthing=("\" & $iincFile &".ink")
 MsgBox(4096,"$incthing", $incthing)
FileCreateShortcut($cmd , @ProgramsDir & $ink  , @ScriptDir, "", $Tooltip, $icon,  @SW_MINIMIZE)

This does make a programfiles menu item

The target is Computer and not the var $Cmd

The start in is the correct directory

It added a shortcut key! that I did not add

It ignored the comment altogether and that is empty

and the wrong icon.

01.jpg

Are there different rules if you use a variable instead of a text string?

Thanks for looking.

Oh yes I almost forgot, I use this fancy piece of code I found in the forums one day that really saved me.

I could not get things straight bouncing between things and put this in and all of a sudden the path I wanted was there,

I do apologize as I do not remember who posted it

Local $sEnvVar = EnvGet("PATH")
    ; Assign the system environment variable called %PATH% with its current value as well as the script directory.
    ; When you assign an environment variable you do so minus the percentage signs (%).
    EnvSet("PATH", $sEnvVar & ";" & @ScriptDir)
    ; Refresh the OS environment for changes to take affect.
    EnvUpdate()

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I think you need to look at the order of your operations.. everything is done line by line. your $cmd for instance is always empty because you copy $ifullpath to it when $ifullpath is still not read from your ini file.

Edit: Also you have decleared $ifullpath both as a local and as a global variable, this can cause you some headace.

Edited by Geir1983

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

303

 

 

Oh my gosh, Thank you for the awake eyes. too many doubleshift days. THanks , it works now., just the icon not placed..

Thanks and *hugs*

 

I have no clue about anything, if it works it works until it no longer works. but thanks to some help from

I got a Filecreateshortcut using all Variables working.. YES i am positive there is another 500 versions, I just in 3 weeks of looking and trying did not find one.. so here is one Filecreateshortcut  that works using variables

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
Global $ifullpath
Global $incthing
Global $iSoftTitle
Global $iincFile
Global $iicoFile




IniRead(@ScriptDir & "\fullpath.ini", "General", ".", $ifullpath)
 Local $ifullpath = IniRead(@ScriptDir & "\fullpath.ini", "General", ".", "")
 MsgBox(4096,"$ifullpath", $ifullpath)
 Local $sEnvVar = EnvGet("PATH")
       EnvSet("PATH", $sEnvVar & ";" & @ScriptDir)
       EnvUpdate()
IniRead(@ScriptDir & "\File.ini", "General", ".", $iincFile)
 Local $iincFile = IniRead(@ScriptDir & "\File.ini", "General", ".", "")
  MsgBox(4096,"$iincFile", $iincFile)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"\" & $iincFile &".ink" = $incthing
$incthing=("\" & $iincFile &".ink")
 MsgBox(4096,"$incthing", $incthing)

  Local $sEnvVar = EnvGet("PATH")
    ; Assign the system environment variable called %PATH% with its current value as well as the script directory.
    ; When you assign an environment variable you do so minus the percentage signs (%).
    EnvSet("PATH", $sEnvVar & ";" & @ScriptDir)
    ; Refresh the OS environment for changes to take affect.
    EnvUpdate()

IniRead(@ScriptDir & "\SoftTitle.ini", "General", ".", $iSoftTitle)
 Local $iSoftTitle = IniRead(@ScriptDir & "\SoftTitle.ini", "General", ".", "")
 MsgBox(4096,"$iSoftTitle", $iSoftTitle)
     Local $sEnvVar = EnvGet("PATH")
    EnvSet("PATH", $sEnvVar & ";" & @ScriptDir)
    EnvUpdate()

IniRead(@ScriptDir & "\icoFile.ini", "General", ".", $iicoFile)
 Local $iicoFile = IniRead(@ScriptDir & "\icoFile.ini", "General", ".", "")
  MsgBox(4096,"$iicoFile", $iicoFile)

;------------------$cmd = "C:\00test_Installer\00bons1.exe"
$cmd = $ifullpath
$ink = $incthing
$Tooltip = $iSoftTitle
$icon = $iicoFile
;------------------$icon = "C:\32.ico"

;----------------------------$ink = "\file.ini"

;------------------------- $iSoftTitle = \SoftTitle.ini

FileCreateShortcut($cmd , @ProgramsDir & $ink  , @ScriptDir, "", $Tooltip, $icon,  @SW_MINIMIZE)

A note, when making the ini for icon file use FULL path

icofile.ini

[General]
.=C:AutoIt3Code00_TrialsInstaller32.ico 

Just using the file name did not work.

To test here are the files the ini and icon

http://78ez.com/Installer.7z

Thanks to Geri1983 for the second set of eyes.. and the hundreds of thousands of posts i use here at Autoit to figure things out.

*hugs* hubby is waking up. got to go and catch that midnight train

25
Edited by meows

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • rudi
      By rudi
      Hello.
      Windows shortcuts have the option to check "Run as administrator" in the "advanced settings" on the tab "Shortcut"
       
      Is it possible to use the function FileCreateShortcut() to define this? Or to use this function and modify this option afterwards? Is it possible to "read" this option's current state for a given LNK file? (FileGetShortcut() doesn't seem to offer that?)  
      Regards, Rudi.
    • satanico64
      By satanico64
      hi guys, how are you ??  fine? good...
      Here is a little question: is it possible to know whish shortcut has been used to launch my autoit app ?
      i'm quite sure that there's nothing to do with autoit, but mostly windows ...
       
      My context: i have an app accessed from the network by my user.
      In my app i use FileCreateShortcut to point to \\myfileserver\myapp.exe
      Soon, in october, they are going to change my fileserver, so my app will be on \myNEWfileserver\myapp.exe
      So in my code, i just rewrite my shortcut on the desktop's user. Everything works fine.
      BUT..some users have several shortcut for my app (they just manually create another shortcut which i don't know the name).
      So maybe they don't use my shortcut but their own ...
      => i know I could list all file on desktop, and for all the .lnk i check if destination is myapp.exe and modify the path but do you see another way ?
       
      thanks
      have fun !
       
    • ur
      By ur
      I am trying to launch the shortcut through autoit, but I am getting below error.
      [Window Title] C:\Windows\system32\cmd.exe /c start "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\erwin\erwin Mart Server r9.8 (64-bit)\Create MartServer Service.lnk" [Content] Windows cannot find 'C:\Windows\system32\cmd.exe /c start "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\erwin\erwin Mart Server r9.8 (64-bit)\Create MartServer Service.lnk"'. Make sure you typed the name correctly, and then try again. [OK] Launching the target directly is not feasible as it is dynamic.
      I tried.
      $r = ShellExecute(@ComSpec & " /c " & "start """& @ProgramsCommonDir & "\erwin\erwin Mart Server r9.8 (64-bit)\Create MartServer Service.lnk""")
       
      and also Run and RUnwait
       
       
    • ur
      By ur
      I am trying to launch a shortcut.
      But I am getting a file not found error.
      Even I kept a condition to check the file exist and it is there but still I am getting the below error on run command.
      $release = "r10.0" $bit = "64" $erwinShortcut = @ProgramsCommonDir&"\erwin\erwin Data Modeler "& $release &" ("& $bit &"-bit)\erwin Data Modeler "& $release &" ("& $bit &"-bit).lnk" Run(@ComSpec & " /c """& $erwinShortcut &"""", @TempDir, @SW_HIDE) [Window Title] C:\ProgramData\Microsoft\Windows\Start Menu\Programs\erwin\erwin Data Modeler r10.0 (64-bit)\erwin Data Modeler r10.0 (64-bit).lnk [Content] C:\ProgramData\Microsoft\Windows\Start Menu\Programs\erwin\erwin Data Modeler r10.0 (64-bit)\erwin Data Modeler r10.0 (64-bit).lnk The specified path does not exist. Check the path, and then try again. [OK] Any suggestions?
      Even I tried surrounding with both double and single quotes for the path of lnk.
      And even changed the working directory to startmenu folder and also exe folder.
    • odaylton
      By odaylton
      Translated by Google. Sorry for any mistakes.
      Sorry for creating this post based on other great creations but after 15 days searching for a solution to a problem beast I solved them.
      Maybe someone new like me can take advantage of this solution for their programs without wasting so much time
      I want to leave here my thanks to the 2 post that saved my life
      First the Yashied for the excellent work in the article:

      And commenting on improvements to the _FileGetShortcutEX function Commented on by
      Ascend4nt

      Here is my list linking the 2 articles
      #Include <GUIConstantsEx.au3> #Include <GUIImageList.au3> #Include <GUITreeView.au3> #Include <TreeViewConstants.au3> #Include <WindowsConstants.au3> #Include <WinAPIEx.au3> #include "_FileGetShortcutEX.au3" Opt('MustDeclareVars', 1) Global $hForm, $hTreeView, $hImageList, $hItem = 0, $hSelect = 0, $hInput, $Input, $Dummy1, $Dummy2 ;novas linhas <<<<< Global $hInput2, $Input2 Global $X, $Y, $sPath, $sRoot = @ProgramsCommonDir; mudado para o projeto @HomeDrive $hForm = GUICreate('MyGUI', 600, 600) $Input = GUICtrlCreateInput('', 20, 20, 560, 19) $hInput = GUICtrlGetHandle(-1) GUICtrlSetState(-1, $GUI_DISABLE) ;novas linhas <<<<< $Input2 = GUICtrlCreateInput('', 20, 40, 560, 19) $hInput2 = GUICtrlGetHandle(-1) ;GUICtrlSetState(-1, $GUI_DISABLE) ;$hTreeView = _GUICtrlTreeView_Create($hForm, 20, 50, 560, 530, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) ;_GUICtrlTreeView_SetHeight($hTreeView, 18) GUICtrlCreateTreeView(20, 90, 560, 530, -1, $WS_EX_CLIENTEDGE) $hTreeView = GUICtrlGetHandle(-1) $Dummy1 = GUICtrlCreateDummy() $Dummy2 = GUICtrlCreateDummy() If _WinAPI_GetVersion() >= '6.0' Then _WinAPI_SetWindowTheme($hTreeView, 'Explorer') EndIf $hImageList = _GUIImageList_Create(16, 16, 5, 1) _GUIImageList_AddIcon($hImageList, @SystemDir & '\shell32.dll', 3) _GUIImageList_AddIcon($hImageList, @SystemDir & '\shell32.dll', 4) _GUIImageList_AddIcon($hImageList, @SystemDir & '\shell32.dll', 51) _GUICtrlTreeView_SetNormalImageList($hTreeView, $hImageList) $sRoot = StringRegExpReplace(FileGetLongName($sRoot), '\\+\Z', '') $sPath = StringRegExpReplace($sRoot, '^.*\\', '') If StringInStr($sPath, ':') Then $sRoot &= '\' $sPath &= '\' EndIf If _WinAPI_PathIsDirectory($sRoot) Then $hItem = _GUICtrlTreeView_AddChild($hTreeView, 0, $sPath, 0, 0) If FileClose(FileFindFirstFile($sRoot & '\*')) Then _GUICtrlTreeView_AddChild($hTreeView, $hItem, '', 2, 2) EndIf EndIf GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUISetState() If $hItem Then _GUICtrlTreeView_Expand($hTreeView, $hItem) EndIf While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Dummy1 ; Update GUISetCursor(1, 1) _TVUpdate($hTreeView, GUICtrlRead($Dummy1)) GUISetCursor(2, 0) Case $Dummy2 ; Menu $hItem = GUICtrlRead($Dummy2) $sPath = _TVGetPath($hTreeView, $hItem, $sRoot) ConsoleWrite('-------------------------------' & @CR) ConsoleWrite('Handle: ' & $hItem & @CR) ConsoleWrite('Path: ' & $sPath & @CR) If _WinAPI_PathIsDirectory($sPath) Then ConsoleWrite('Type: ' & 'Directory' & @CR) Else ConsoleWrite('Type: ' & 'File' & @CR) EndIf ConsoleWrite('X: ' & MouseGetPos(0) & @CR) ConsoleWrite('Y: ' & MouseGetPos(1) & @CR) ConsoleWrite('-------------------------------' & @CR) EndSwitch WEnd Func _TVGetPath($hTV, $hItem, $sRoot) Local $Path = StringRegExpReplace(_GUICtrlTreeView_GetTree($hTV, $hItem), '([|]+)|(\\[|])', '\\') If Not $Path Then Return '' EndIf If Not StringInStr($Path, ':') Then Return StringRegExpReplace($sRoot, '(\\[^\\]*(\\|)+)\Z', '\\') & $Path EndIf Return $Path EndFunc ;==>_TVGetPath Func _TVSetPath($hTV, $hItem, $sRoot) ;16/11/24 incerindo variaveis pra detalhamento Local $Arq = _TVGetPath($hTV, $hItem, $sRoot) Local $sDir_Name = StringRegExpReplace($Arq, "(^.*\\)(.*)", "\1") Local $NomeArq = StringRegExpReplace($Arq, "^.*\\", "") Local $NomeArqPos = StringInStr($NomeArq, ".", 0, -1);localiza o ponto da extenso if $NomeArqPos Then Local $NomeArq2 = StringLeft($NomeArq, $NomeArqPos - 1) Local $ArqTipo = StringTrimLeft($NomeArq, $NomeArqPos ) if $ArqTipo="lnk" Then Local $t=_FileGetShortcutEX($Arq);FileGetShortcut($Arq) if $t[2]<> "" Then $t[0] &= "' '"&$t[2] EndIf GUICtrlSetData($Input2,"'"&$t[0] &"'") EndIf Else Local $NomeArq2=$NomeArq Local $ArqTipo='' EndIf Local $sDOS_Dir = FileGetShortName($sDir_Name, 1) GUICtrlSetData($Input, _WinAPI_PathCompactPath($hInput,$Arq, 554)) $hSelect = $hItem EndFunc ;==>_TVSetPath Func _TVUpdate($hTV, $hItem) Local $hImageList = _SendMessage($hTV, $TVM_GETIMAGELIST) Local $Path = StringRegExpReplace(_TVGetPath($hTV, $hItem, $sRoot), '\\+\Z', '') Local $hIcon, $hSearch, $hSubitem Local $Index, $File _WinAPI_LockWindowUpdate($hTV) _GUICtrlTreeView_Delete($hTV, _GUICtrlTreeView_GetFirstChild($hTV, $hItem)) $hSearch = FileFindFirstFile($Path & '\*') If $hSearch = -1 Then If Not @error Then If FileExists($Path) Then ; If _WinAPI_PathIsDirectory($Path) Then ; ; Access denied ; EndIf Else _GUICtrlTreeView_Delete($hTV, $hItem) _WinAPI_LockWindowUpdate(0) Return 0 EndIf EndIf Else While 1 $File = FileFindNextFile($hSearch) If @error Then ExitLoop EndIf If @extended Then $hSubItem = _GUICtrlTreeView_AddChild($hTV, $hItem, $File, 0, 0) If FileClose(FileFindFirstFile($Path & '\' & $File & '\*')) Then _GUICtrlTreeView_AddChild($hTV, $hSubItem, '', 2, 2) EndIf EndIf WEnd FileClose($hSearch) EndIf $hSearch = FileFindFirstFile($Path & '\*') If $hSearch = -1 Then Else While 1 $File = FileFindNextFile($hSearch) If @error Then ExitLoop EndIf If Not @extended Then $hIcon = _WinAPI_ShellExtractAssociatedIcon($Path & '\' & $File, 1) $Index = _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon) _GUICtrlTreeView_AddChild($hTV, $hItem, $File, $Index, $Index) _WinAPI_DestroyIcon($hIcon) EndIf WEnd FileClose($hSearch) EndIf _GUICtrlTreeView_SetItemParam($hTV, $hItem, 0x7FFFFFFF) _WinAPI_LockWindowUpdate(0) Return 1 EndFunc ;==>_TVUpdate Func _WinAPI_LockWindowUpdate2($hWnd) Local $Ret = DllCall('user32.dll', 'int', 'LockWindowUpdate', 'hwnd', $hWnd) If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0) EndIf Return 1 EndFunc ;==>_WinAPI_LockWindowUpdate ;AutoIt_Debugger_Command:Disable_Debug Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMTREEVIEW = DllStructCreate($tagNMTREEVIEW, $lParam) Local $hItem = DllStructGetData($tNMTREEVIEW, 'NewhItem') Local $iState = DllStructGetData($tNMTREEVIEW, 'NewState') Local $hTV = DllStructGetData($tNMTREEVIEW, 'hWndFrom') Local $ID = DllStructGetData($tNMTREEVIEW, 'Code') Local $tTVHTI, $tPoint Switch $hTV Case $hTreeView Switch $ID ;AutoIt_Debugger_Command:Enable_Debug Case $TVN_ITEMEXPANDEDW If Not FileExists(_TVGetPath($hTV, $hItem, $sRoot)) Then _GUICtrlTreeView_Delete($hTV, $hItem) If BitAND($iState, $TVIS_SELECTED) Then _TVSetPath($hTV, _GUICtrlTreeView_GetSelection($hTV), $sRoot) EndIf Else If Not BitAND($iState, $TVIS_EXPANDED) Then _GUICtrlTreeView_SetSelectedImageIndex($hTV, $hItem, 0) _GUICtrlTreeView_SetImageIndex($hTV, $hItem, 0) Else _GUICtrlTreeView_SetSelectedImageIndex($hTV, $hItem, 1) _GUICtrlTreeView_SetImageIndex($hTV, $hItem, 1) If Not _GUICtrlTreeView_GetItemParam($hTV, $hItem) Then GUICtrlSendToDummy($Dummy1, $hItem) EndIf EndIf EndIf Case $TVN_SELCHANGEDW If BitAND($iState, $TVIS_SELECTED) Then If Not FileExists(_TVGetPath($hTV, $hItem, $sRoot)) Then _GUICtrlTreeView_Delete($hTV, $hItem) $hItem = _GUICtrlTreeView_GetSelection($hTV) EndIf If $hItem <> $hSelect Then _TVSetPath($hTV, $hItem, $sRoot) EndIf EndIf Case $NM_RCLICK $tPoint = _WinAPI_GetMousePos(1, $hTV) $tTVHTI = _GUICtrlTreeView_HitTestEx($hTV, DllStructGetData($tPoint, 1), DllStructGetData($tPoint, 2)) $hItem = DllStructGetData($tTVHTI, 'Item') If BitAND(DllStructGetData($tTVHTI, 'Flags'), $TVHT_ONITEM) Then _GUICtrlTreeView_SelectItem($hTreeView, $hItem) If Not FileExists(_TVGetPath($hTV, $hItem, $sRoot)) Then _GUICtrlTreeView_Delete($hTV, $hItem) $hItem = _GUICtrlTreeView_GetSelection($hTV) Else GUICtrlSendToDummy($Dummy2, $hItem) EndIf If $hItem <> $hSelect Then _TVSetPath($hTV, $hItem, $sRoot) EndIf EndIf ;AutoIt_Debugger_Command:Disable_Debug EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY ;AutoIt_Debugger_Command:Enable_Debug