Jump to content

[Closed] How to Run a Shortcut to the "Local Area Network" Network Connection?


Zohar
 Share

Recommended Posts

Hi

 

I am using Windows XP SP3,

I opened Windows Explorer, Navigated to Control Panel\Network Connections,

then created a Shortcut to the "Local Area Network" item there,

and put it in C:\.

 

I want to run this shortcut now,

so If the network connection is closed, it will now start...

 

How can I do it?

 

Thank you

Zohar

Edited by Zohar
Link to comment
Share on other sites

Runnnig ncpa.cpl, opens the Network Connections list.

I want to directly run a specific connection from there,

and not to show the list..

By specific, are you referring to a connection that requires you to dial up or connect before you can use it?

 

 

Link to comment
Share on other sites

Hi Starstar

Thank you, this will indeed run it,

but my hope was to achieve it not via automating the GUI, but a simple programmatic way

(like Run() can run an executable, without automating Windows Explorer's GUI)

Link to comment
Share on other sites

Link to comment
Share on other sites

Danyfirex:

 

Thank you.

It's not a MenuItem tho,

it appears like a regular item in the list (just like files appear there)

 

Does it mean I can still achieve it using the way you wrote?

 

BetaLeaf:

Sorry I missed your reply earlier.

It is the "Local Area Connection" network connection

Edited by Zohar
Link to comment
Share on other sites

Interesting

 

I tried

ShellExecute("D:\ShortcutToLAN.lnk","","","Disable")

But it didn't work.

When I changed the first parameter there from a shortcut to a file (JPG), and changed the verb to "Edit", then it succeeded..

Maybe ShellExecute() cannot work on Shortcuts, only on files?

(or maybe there's a way to make it work on shortcuts too? I don't know what to change)

 

Link to comment
Share on other sites

you can always

run( "cmd", "", @SW_SHOWMAXIMIZED )
$hWnd = WinWait("[CLASS:cmd]", "", 1)
WinActivate($hWnd)

Send("Path\ShortcutName.lnk{Enter}")

;Sleep(2000)

;ProcessClose("CMD.exe")

Edit: For some reason the above code runs the .lnk but doesnt enable network connection, Alternatively you can
set a shortcut key in .lnk file properties example control + alt + m then

Send("{CTRLDOWN}{ALTDOWN}m{CTRLUP}{ALTUP}")

just read you dont want to automate gui...dont know if the shortcut key solution falls in that category but ill look in other "programmatic" solution

Edit: got it, took me a while to crack it ^^

THE SHORTCUT HAS TO BE CREATED WHILE THE NETWORK IS DISABLED! otherwise it wont work!!

you also might need to elevate but try without elevation first.

then

run( "cmd /k ""ShortcutPath.lnk""", "", @SW_SHOWMAXIMIZED )

tell me if it works for you...

Edited by CrypticKiwi
Link to comment
Share on other sites

i added this part as an edit of my last post so maybe you missed it and i'd like your feedback if it works for you and not only in my pc....

""Edit: got it, took me a while to crack it ^^

THE SHORTCUT HAS TO BE CREATED WHILE THE NETWORK IS DISABLED! otherwise it wont work!!

you also might need to elevate but try without elevation first.

then

run( "cmd /k ""ShortcutPath.lnk""", "", @SW_SHOWMAXIMIZED )

tell me if it works for you...""

Edited by CrypticKiwi
Link to comment
Share on other sites

Hi CrypticKiwi

Thank you very much for the ideas.

 

When I run

Run("cmd /k ""ShortcutPath.lnk""")

I only get a DOS window, nothing is run..

 

In addition I tried to create the Shortcut again, when the network connection was disabled,

but there was no difference in the result.

(BTW, before, when I created the network shortcut when the network was enabled, the shortcut worked when I run it manually(via Windows Explorer),

I just cannot run it programatically.. and it doesn't work both, with the first one I created, nor the second one (while offline, as you suggested)).

 

You say that it does run, for you?

Maybe it's because you're on a different version of Windows than XP..

 

Link to comment
Share on other sites

Yes, indeed I use a different version of Windows (8.1) so unfortunately I don't have xp and cannot test to make it work... The strange thing is that on 8.1 most .lnk shortcuts work programmatically except the enabling the network connection shortcut you want , so maybe it's a security thing?  but I got it to work with the instructions in last post, it didn't work with /c only /k and only when I create the shortcut offline...ill do some more tests on different pc (win7) and see result, also I did a lot of messing around before the .lnk worked so maybe it's something I did before not the /k while offline only... I'll let you know the result....

update: win7 works exactly as win 8.1 /k is important and it has to be while the connection is disabled. 

I'm thinking of a way to get my hands on xp easily...maybe a virtual machine but I don't have a copy :-/....or maybe you could upgrade to 7 or 8.1 it's better for security anyway :P

Edited by CrypticKiwi
Link to comment
Share on other sites

Thank you so much :)

 

OK then, in the future when I'll use a different version of Windows, I will get back to it..

 

Meanwhile, I will automate it via GUI operations..

 

Thank you for the help CrypticKiwi

Edited by Zohar
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...