Jump to content

Filecreate shortcut


Recommended Posts

Hi,

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.

Link to comment
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>

Example()

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)
    EndIf

    ; Delete the shortcut.
    FileDelete($sFilePath)
EndFunc   ;==>Example

 

My resources are limited. You must ask the right questions

 

Link to comment
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
Link to comment
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
Link to comment
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" , _
   "C:\i.ico")

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

Good luck for the future :)

Edited by pixelsearch
Link to comment
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
 Share

×
×
  • Create New...