Sign in to follow this  
Followers 0
hans_schwaebli

How to run shortcuts (.lnk files)?

22 posts in this topic

I want to run a shortcut instead of the cmd file itself.

I tried it with Run('C:/aProgram.lnk')

But it says Error.

How can I run shortcuts, .lnk files?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I've done it a very long time ago so i might be wrong

I think it requires the use of rundll32.exe and shell32.dll

here you go

Run(@ComSpec & " /c " & "C:\aProgram.lnk")

Edited by CWorks

Share this post


Link to post
Share on other sites

I've done it a very long time ago so i might be wrong

I think it requires the use of rundll32.exe and shell32.dll

here you go

Run(@ComSpec & " /c " & "C:\aProgram.lnk")

Thank you.

But it does not work like I expected it.

I tried to start a .cmd file. In the .lnk file I configured color and size of the dos box which appears when I double click the link. But when I start the link with your line, it uses the default colors and sizes.

Any idea why that is or a solution?

Share this post


Link to post
Share on other sites

I've done it a very long time ago so i might be wrong

I think it requires the use of rundll32.exe and shell32.dll

here you go

Run(@ComSpec & " /c " & "C:\aProgram.lnk")

I thing CWorks has it right on the Run() command. Since a .lnk file is not an executable itself, it needs a command interpreter to handle it, which you get by running it with @ComSpec. The console window need not be visible:

Run(@ComSpec & " /c " & "C:\aProgram.lnk", @TempDir, @SW_HIDE)

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thank you.

But it does not work like I expected it.

I tried to start a .cmd file. In the .lnk file I configured color and size of the dos box which appears when I double click the link. But when I start the link with your line, it uses the default colors and sizes.

Any idea why that is or a solution?

Try using CMD with switches... and COLOR with switches... the size is another matter, so is the font... have to dig deeper for that one.

-----------------------------8<---------------------------------

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]

[ [/C | /K] string]

/T:fg Sets the foreground/background colors (see COLOR /? for more info)

Sets the default console foreground and background colors.

-------------------------------------------------------------------------------------------

COLOR [attr]

attr Specifies color attribute of console output

Color attributes are specified by TWO hex digits -- the first

corresponds to the background; the second the foreground. Each digit

can be any of the following values:

0 = Black 8 = Gray

1 = Blue 9 = Light Blue

2 = Green A = Light Green

3 = Aqua B = Light Aqua

4 = Red C = Light Red

5 = Purple D = Light Purple

6 = Yellow E = Light Yellow

7 = White F = Bright White

-------------------------------------8<------------------------------------------


> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

I can set only some colors in the dos box. I cannot use the many colors which I can by configuring the link.

And more important, I cannot change any other things like box size, buffer size and font.

I didn't find any solution. So I simly try to start the link programatically so that I get the same effect as if I start it by double clicking the link. I know that I could configure a keyboard shortcut, but that would be another workaround.

So is there any programatical solution for such a "simple" thing which everyone of us does dozens of times each day manually: starting a link?

Share this post


Link to post
Share on other sites

maybe try by using the command start ...

start c:\aProgram.lnk

/J


> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

maybe try by using the command start ...

start c:\aProgram.lnk

/J

It does not work if I use: Run("start C:/my.lnk")

If the link points to a .cmd file and I configured the link, the cmd file is started, but without the configuration from the lnk file (colors, fonts, buffers etc.)

Share this post


Link to post
Share on other sites

try:

Run(@ComSpec & " /c " & 'start c:\aProgram.lnk', "", @SW_HIDE)

but it might not work either :/ ... I'm trying to help out though :)


> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

try:

Run(@ComSpec & " /c " & 'start c:\aProgram.lnk', "", @SW_HIDE)

but it might not work either :/ ... I'm trying to help out though :)

Same effect. :P

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

you need to use mode to set the extended attributes of the cmd window

use mode in your batch file

add this to the top of your batch file to see how it works

@echo off& Color F8&MODE CON: COLS=73 LINES=20

or you can do it like this

@echo off
Color F8
MODE CON: COLS=73 LINES=20

to get color codes do this in cmd window

color /?

Edited by CWorks

Share this post


Link to post
Share on other sites

Dang...

I just tried it, and it works for me with the comspec-code... it just doesn't bring the changes in the lnk file... strange...

not as easy as I first thought :)


> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

HI,

this should work

Run(@ComSpec & ' /c camstudio.lnk', @DesktopCommonDir, @SW_HIDE)

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

HI,

this should work

Run(@ComSpec & ' /c camstudio.lnk', @DesktopCommonDir, @SW_HIDE)

So long,

Mega

It does not work. It starts the shortcut, but doesn't use its settings (colors, buffer and so on of the DOS box).

Share this post


Link to post
Share on other sites

Hi,

what app are you trying to start? It works for me. :)

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Hi,

what app are you trying to start? It works for me. :)

So long,

Mega

Okay, here is the recipe for failure:

1. Create a new .cmd file and write just one line in it: pause

2. Create a new shortcut for the new .cmd file.

3. Modify the shortcut properties, changing DOS box' colors, font, size and so on.

4. Try to start that .lnk shortcut file programatically and expect that it a) starts and that it :P displays the colors, font and size you configured.

Share this post


Link to post
Share on other sites

[codeMODE CON: COLS=73 LINES=20

It does not show a scroll bar if there are more characters than 73 in a line. Instead it breaks it to the next line, which I don't want. In the shortcut properties I can set a width and height buffer. Can I do this with a DOS command too?

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

I can get a) working without problem. :) is another matter, it just doesn't read the .lnk fileattributes it seems... hmmmmm....

one way is to use a configuration file, although that is a bit harsh.... still looking. (btw, it reads the maximize attribute from the .lnk file so it is in fact running the lnk file)

Edited by jinxter

> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

This will change the Command prompt :) a bit safe I know, but it's just so it doesn't send in the dosbox.

and this is probably not the solution, but it works at least. I will look further.

Run(@ComSpec & " /k " & 'start c:\q.cmd.lnk', "", @SW_HIDE)
WinWait("C:\WINNT\system32\cmd.exe","")
If Not WinActive("C:\WINNT\system32\cmd.exe","") Then WinActivate("C:\WINNT\system32\cmd.exe","")
WinWaitActive("C:\WINNT\system32\cmd.exe","")
WinWait("""C:\WINNT\system32\cmd.exe"" Properties","")
If Not WinActive("""C:\WINNT\system32\cmd.exe"" Properties","") Then WinActivate("""C:\WINNT\system32\cmd.exe"" Properties","")
WinWaitActive("""C:\WINNT\system32\cmd.exe"" Properties","")
Send("{ALTDOWN}{SPACE}{ALTUP}p{TAB}{RIGHT}{RIGHT}{SHIFTDOWN}{TAB}{SHIFTUP}{LEFT}{TAB}20")
WinWait("Apply Properties","")
If Not WinActive("Apply Properties","") Then WinActivate("Apply Properties","")
WinWaitActive("Apply Properties","")
Send("{ENTER}{ENTER}")

You can set the values for all the cmd-prompts, but I guess that is not what you want.

Edited by jinxter

> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

does shellexecute command work?


Many times you need to think like hobby-bob:')

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  
Followers 0