Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using NCPA.CPL to access Local Area Conn. properties

Status
Not open for further replies.

plarocque

MIS
Jul 2, 2003
26
CA
Hi,

I'm trying (and failing) to find a way of scripting access directly to the 'General' tab of 'Local Area Connections' properties, i.e. without having to go through the 'Control Panel > Network Connections' route then right-clicking on 'Local Area Connection' then choosing the 'Properties' button.

I've tried using the following command:
rundll32.exe shell32.dll,Control_RunDLL ncpa.cpl,,1
(found on VBNet) but this still only gets me to the 'Local Area Connection'.

Does anyone know of a way?

Pierre.
 
I don't know, perhaps. I will have a look. Thank you anyway.
 
What are you actually trying to do when you bring up the Properties screen? As Linney has hinted, you can probably use VBScript to achieve what you want

BTW, if you run CONTROL NCPA.CPL, it does the same job as your RUNDLL32 statement...

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
I'm trying to access the TCP/IP properties page. It will be a vbscript that run once when a thin client is getting installed. The person installing the hardware will have to specify either if the thin will use a DHCP to obtain an IP address, or if it will use a static IP, and if it is the case, enter it.

Because vbscript is so limited with interaction with the user, I thought it would be simpler to use the actual applet then to create a new one to ask and receive input from the user.

LINNEY:

Haven't tried anything yet, I had a quick look, looks promising but the problem is, as we are a gouverment office, I'm not suppose, or I don't have the right to use freeware/shareware.
 
Plarocque,

I used to use AutoIt but now tend to use AutoHotkey more frequently instead. (See
Whichever one you use, once you are happy with your script, just compile it into an executable using the compilers that are provided with each program. That way you don't have to install either AutoIt or AutoHotkey itself on the PC's at work.

Here's an example AutoHotkey script. Copy/Paste it into Notepad and save as something like 'nic-properties.ahk'.

Code:
; Open Network Connections
Run ncpa.cpl
WinWaitActive, Network Connections,
 
; Select the first object starting with L and open its Status window
Send, L{ENTER},
WinWaitActive, Local Area,
 
; Press the Properties button to open its window
Send, {SPACE},
sleep, 200
WinWait, Local Area,
IfWinNotActive, Local Area, , WinActivate, Local Area,
WinWaitActive, Local Area,

When you run this using AutoHotkey it will open the Properties of the Local Area Network Connection for you.

Hope this helps...
 
And this is the VBScript equivalent. Just paste the code into a text file, save it with a VBS extension (eg NETWORK.VBS) then double-click on it to run it. If you were to automate the running of this code, you would need to use WSCRIPT (eg WSCRIPT NETWORK.VBS)

Code:
set WshShell = CreateObject("WScript.Shell")

'Launch NCPA and wait for 2 seconds
WshShell.Run "control ncpa.cpl"
WScript.Sleep 2000

'Wait until the application has loaded - Check every second
While WshShell.AppActivate("Network Connections") = FALSE
wscript.sleep 1000
Wend

'Bring the application to the foreground
WshShell.AppActivate "Network Connections"
WScript.Sleep 500

'Send keys to select the first connection starting with L
WshShell.SendKeys "L"
WScript.Sleep 501

'Send keys to Bring up the File Menu
WshShell.SendKeys "%f"
WScript.Sleep 501

'Send keys to Choose Properties (shortcut key is R)
WshShell.SendKeys "r"
WScript.Sleep 501

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
I have posted many questions over time in different forum in here, but never received as many helpful hint as this one generate, it's great. Thank you to every one. I think I've got all the tools I need to continue my project.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top