Jump to content
Sign in to follow this  

Filecreate shortcut

Recommended Posts


I'm trying to create a shortcut playing with variables but I can't figure out what's wrong

I got 2 variables joined in one with for instance

Local $path = FileOpenDialog($message, "C:" & "", "Select your executable (*.exe)", 1 + 4)
Local $elev = 'c:\windows\System32\cmd.exe /c start "runhigh" /high '

$target = $elev & $path

FileCreateShortcut($target, @DesktopCommonDir & "\linked.lnk", StringLeft($target,StringInStr($target,"\",0,-1)) , "" , "" , "c:\i.ico")

The problem is that a shortcut is created but instead of the target area I got the start in filled with my variable

My second problem is that when I do a shell execute of the result of $target = $elev & $path, Note that if I do a batch with the variable written manually, it's working.

Share this post

Link to post
Share on other sites

I am not getting what you are trying to do, sorry :)

Click here to see my signature:



  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.




Share this post

Link to post
Share on other sites

Francesco, he's trying to create a shortcut, a .lnk file that is linked to an exe of the users choice

for your last problem, look at the help file for RunAs so you can run cmd as admin and forget that other nonsense.

My resources are limited. You must ask the right questions


Share this post

Link to post
Share on other sites

to the OP, does the example work from the help file? it creates an Explorer.exe shortcut, then deletes it off the desktop. It works for me on multiple OS

#include <MsgBoxConstants.au3>


Func Example()
    ; Create a constant variable in Local scope of the shortcut filepath.
    Local Const $sFilePath = @DesktopDir & "\FileCreateShortcutExample.lnk"

    ; Create a shortcut on the desktop to explorer.exe and set the hotkey combination Ctrl+Alt+T or in AutoIt ^!t to the shortcut.
    FileCreateShortcut(@WindowsDir & "\explorer.exe", $sFilePath, @WindowsDir, "/e,c:\", _
            "Tooltip description of the shortcut.", @SystemDir & "\shell32.dll", "^!t", "15", @SW_SHOWMAXIMIZED)

    ; Retrieve details about the shortcut.
    Local $aDetails = FileGetShortcut($sFilePath)
    If Not @error Then
        MsgBox($MB_SYSTEMMODAL, "", "Path: " & $aDetails[0] & @CRLF & _
                "Working directory: " & $aDetails[1] & @CRLF & _
                "Arguments: " & $aDetails[2] & @CRLF & _
                "Description: " & $aDetails[3] & @CRLF & _
                "Icon filename: " & $aDetails[4] & @CRLF & _
                "Icon index: " & $aDetails[5] & @CRLF & _
                "Shortcut state: " & $aDetails[6] & @CRLF)

    ; Delete the shortcut.
EndFunc   ;==>Example


My resources are limited. You must ask the right questions


Share this post

Link to post
Share on other sites

Hi Gringo,

Using variable $target 3 times in FileCreateShortcut() created your 1st problem. Just use $path instead of $target in FileCreateShortcut() and it will be ok

#include <FileConstants.au3>

$message = "Choose me"
Local $path = FileOpenDialog($message, "C:" & "", "Select your executable (*.exe)", 1 + 4)
Local $elev = 'c:\windows\System32\cmd.exe /c start "runhigh" /high '
$target = $elev & $path

FileCreateShortcut($path, @DesktopCommonDir & "\linked.lnk", StringLeft($path,StringInStr($path,"\",0,-1)) , "" , "" , "c:\i.ico")

PS: this script fixes only your 1st problem : FileCreateShortcut() works now, without using your variables $elev or $target. Let's hope someone will help you with your 2nd problem :)

Edited by pixelsearch

Share this post

Link to post
Share on other sites

Hi and thank you for your answers,

If I only use $path I create a shortcut to the exe file choosen but the purpose of the litle program is to make a shortcut for an exe that will be executed in high priority.

The program that I'm trying to do should work like this :

1 The user choose and exe and it's stored to the variable "path" (for instance "F:\test\test.exe")

2 the path and target are concatened to give the result : c:\windows\System32\cmd.exe /c start "runhigh" /high "F:\test\test.exe"

3 the shortcut is created on the desktop to c:\windows\System32\cmd.exe /c start "runhigh" /high "F:\test\test.exe"

So everytime a user need to launch a program in high priority he can launch the shortcut instead of launching the program and set the priority in task manager.

The two problem are:

-The concatenation of the 2 variable is not working if I do a shellexecute of target I got an error saying windows cannot find the target

-the shortcut is created but the line isn't in the right place if you do a property of the created shortcut

I've figured out that I missed some quote in the path

c:\windows\System32\cmd.exe /c start "runhigh" /high F:\test\test.exe that shoud be c:\windows\System32\cmd.exe /c start "runhigh" /high "F:\test\test.exe"

so I managed to add it

$path2 = '"' & $path & '"'

$target = $elev & $path2

so now if I do an shellexecute it doesn't work buf if I create a batch file it does.

FileWriteLine  ("c:\prior\path.bat", $target)

The batch solution is complicated because I have to take the path variable "F:\test\test.exe" to take to remove the path of the exe file and have something like "F:\test\" then set it as working dir then do a shortcut of that batch to the desktop. But I'm prety sure the direct shortcut way could work, and it's more elegant.


Edited by Gringo
more info

Share this post

Link to post
Share on other sites

@Gringo: here is your script, with Shortcut (high priority) and ShellExecute, both working nicely :

#include <FileConstants.au3>

Local $path = FileOpenDialog("Choose your exe", "C:" & "", "Select your executable (*.exe)", 1 + 4)
Local $elev = ' /c start "runhigh" /high '
Local $target = $elev & chr(34) & $path & chr(34)

FileCreateShortcut("C:\Windows\system32\cmd.exe", _
   @DesktopCommonDir & "\linked.lnk", _
   StringLeft($path,StringInStr($path,"\",0,-1)), _
   $target, _
   "tooltip here" , _

ShellExecute("C:\Windows\system32\cmd.exe", $target)

Good luck for the future :)

Edited by pixelsearch

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Pickpocketz88
      First I would just like to say HELLO! to anyone reading. It has been a while since I've posted to the Forums but I'm always crawling around.
      Now to the matter at hand. I have been looking high and low for a simplistic answer my burned out brain can find but to no avail. I've only recently upped my AutoIt skill and only by a little bit such as ordering my script neatly with my own UDFs and using Global/Dim more often to make my GUI creation understandable and easy to keep things orderly. My current problem however is figuring out how to make my newest endeavor work which is my own "Debugger". I've made a GUI with an Edit Control to display what my Variables are holding and other information from a concurrently running Script. I have access to all of the scripts I'm attempting to connect but I'm dumbfounded on how I would separately read variable information from one running script into another. I'll provide my "Debugger" script that I want to read variables into and a "Meta Script" I'd want to pass info from.
      #Region Include Files #include <AutoItConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ColorConstantS.au3> #EndRegion #Region AutoIt Options ;Opt("TrayAutoPause", 0) ;Opt("TrayMenuMode", 3) #EndRegion #Region Hotkeys HotKeySet("{ESC}", "ExitProgram") HotKeySet("{PGDN}", "PauseProgram") HotKeySet("!1", "Snippet_1") HotKeySet("!2", "Snippet_2") HotKeySet("!3", "Snippet_3") HotKeySet("!4", "Snippet_4") HotKeySet("!5", "Snippet_5") HotKeySet("!6", "Snippet_6") HotKeySet("!7", "Snippet_7") HotKeySet("!8", "Snippet_8") HotKeySet("!9", "Snippet_9") #EndRegion #Region Global Variables #Region Globals Global $gMain, $ctrlEdit ;, $gParent #EndRegion #Region $gMain Params Dim $gMainW = @DesktopWidth / 2 Dim $gMainH = @DesktopHeight / 2 Dim $gMainX = (@DesktopWidth / 2) - ($gMainW / 2) Dim $gMainY = (@DesktopHeight / 2) - ($gMainH / 2) Dim $gMainStyle = $WS_POPUP Dim $gMainStyleEx = -1 ;Dim $gMainParent = $gParent #EndRegion #Region $ctrlEdit Params Dim $ctrlEditW = Round($gMainW * 0.98) Dim $ctrlEditH = Round($gMainH * 0.98) Dim $ctrlEditX = ($gMainW - $ctrlEditW) / 2 Dim $ctrlEditY = ($gMainH - $ctrlEditH) / 2 Dim $ctrlEditStyle = -1 Dim $ctrlEditStyleEx = -1 #EndRegion #EndRegion #Region GUI Initialization ;$gParent = GUICreate("", -1, -1, -1, -1, -1, $WS_EX_TOOLWINDOW) $gMain = GUICreate("", $gMainW, $gMainH, $gMainX, $gMainY, $gMainStyle, $gMainStyleEx) GUISetBkColor($COLOR_BLACK, $gMain) $ctrlEdit = GUICtrlCreateEdit("MainW: " & $gMainW & @CRLF & "MainH: " & $gMainH & @CRLF & "EditW: " & $ctrlEditW & @CRLF & "EditH: " & $ctrlEditH, $ctrlEditX, $ctrlEditY, $ctrlEditW, $ctrlEditH, $ctrlEditStyle, $ctrlEditStyleEx) GUISetState(@SW_SHOW, $gMain) #EndRegion MainFunction() #Region Main Function (GUI) Func MainFunction() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit EndIf WEnd EndFunc #EndRegion #Region Functions Func Functions() EndFunc #EndRegion #Region Program 1 Func Snippet_1() EndFunc #EndRegion #Region Program 2 Func Snippet_2() EndFunc #EndRegion #Region Program 3 Func Snippet_3() EndFunc #EndRegion #Region Program 4 Func Snippet_4() EndFunc #EndRegion #Region Program 5 Func Snippet_5() EndFunc #EndRegion #Region Program 6 Func Snippet_6() EndFunc #EndRegion #Region Program 7 Func Snippet_7() EndFunc #EndRegion #Region Program 8 Func Snippet_8() EndFunc #EndRegion #Region Program 9 Func Snippet_9() EndFunc #EndRegion #Region Pause/Exit Functions Func PauseProgram() While 1 Sleep(1000) WEnd EndFunc Func ExitProgram() Exit EndFunc #EndRegion Pause/Exit Functions #Region Snippets #CS #CE #EndRegion #Region Other Information #CS #CE #EndRegion That's the Debugger script. Please forgive anything ignorant but point it out if you will, I'll take any pointers to get better! (I usually use a Select to get $GUI_EVENT_CLOSE but this is early on)
      Now if I made another script with a basic GUI similar to this and wanted to read say the GUI Width ($gMainW) into the Debugger Edit Control could I do it? If so, could I do it for every variable I have in a script? I read something about the Run function and adding the variables as an option parameter I believe which I think I could do with an array to keep it from being super long and ugly but would that be the only way to do this? Any information is going to be appreciated and thank you in advance for your time!
      Edit: Sadly it just dawned on me that I could make a UDF that will create a child window that will do this instead of having a separate script trying to invade another... I'll still be keeping an eye on this for any comments but I apologize if I wasted your time!
    • By Pricehacker
      Im wondering if it is possible to 'empty' the variable value to save memory, for example i often use variable as a onetime use thing and would prefer to 'forget' it after is is used
      Maybe it is just as easy as to setting $vVar = Null, but i wanted to make sure that this is the case
    • By CarlD
      Is there a reliable way to ensure that data assigned to variables in a script is overwritten or deleted when the script exits? I have scripts that encrypt/decrypt data and would like to ensure, if possible, that the encryption keys and decrypted data do not stay in memory after the script exits. Thanks.
    • By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

    • By ShakeelAhmad
      I've to upload different number of photos online in different assignments. There is a problem that all photos cannot be selected at once to upload. I have to choose and upload photos one by one. For this purpose I have made a script to automate whatever I have to do manually for choosing and uploading photos one by one.
      Please see my script below and check the last "MouseClick" command. This command clicks the button to choose and upload next photo. The problem I'm facing is; the last "MouseClick" works 1 step extra when all photos have been selected and uploaded. I mean if 7 photos are to be uploaded, this command opens the box from where next photo is selected and uploaded then it again opens the box and next photo is choosen and so on.... when last photo is selected and uploaded, this button once again opens the box. When all photos are uploaded, it should not click the button to select next photo. Please suggest how can I resolve this issue.
      #include <AutoItConstants.au3> Sleep(200) HotKeySet("{ESC}","Quit") ;Press ESC key to quit Send("{ALT DOWN}") Send("{TAB}") Send("{ALT UP}") Sleep(200) Local $photos = InputBox("Question", "How many photos to upload?", "#", "", _ - 1, -1, 0, 0) ; How many photos to upload Local $selector = 0 While $photos <> $selector MouseClick("Left", 281, 238, 1) ; mouse click on very first photo in the box. if $selector = 0 Then Send("{ENTER}") ; for selecting very first photo from "open" window. Sleep(800) Else sleep(200) Send("{RIGHT " & $selector & "}") ; for selecting 2nd to onward photos from "open" window. sleep(1000) Send("{ENTER}") sleep(1000) EndIf MouseClick("Left", 495, 198, 1) ; for clicking a button to choose next photo to upload $selector = $selector + 1 WEnd Beep(1500, 300) ; beep when all photos uploaded Exit Regards,
  • Create New...