WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Control Panel

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

RunwithLogon and Control Panel Applets


Keywords: Control Panel Applets .cpl wntRunAs RunAs RunwithLogon Problem Launching Run Running

Question:

Trying to open up the Network Connections window (WinXp). Should RunWithLogon work in this case ?:
prog = "control.exe"
prog_params = "ncpa.cpl"
runas_user ="administrator"
runas_domain = ""
runas_pswd = "password"

Run (prog, prog_params)


RunWithLogon(prog, prog_params, "", @NORMAL, @NOWAIT, runas_user, runas_domain, runas_pswd,0)
The first simple RUN opens up the right window.

The RunWithLogon opens up a window displaying the contents of the C:\ drive. By the way, I can directly launch other control panel applets using RunWithLogon, except the Network Connection applet does not open with the right window ???

I seem to recall reading a note some time ago stating that RunWithLogon() cannot be used to directly launch a control panel applet. I'm not sure what the root cause of the problem was, but I do recall reading about it.

How about using Script A to run Script B via RunWithLogon(), and then have Script B launch the control panel applet via the Run() function.

Answer:

I found an excellent write-up of this on the Web that discusses why this happens. In a nutshell, ncpa.cpl isn't like the other .cpl files in that it simply uses the underlying ShellExecute() Win32 API function to ask the Windows Explorer to display the network connections, which is really just a folder to be displayed via a shell extension. Since the Windows Explorer likes to minimize the # of copies of itself that are executing, when this happens, the new instance of the Windows Explorer tells the previous instance to handle the request and then quietly exits. When this is done via RunAs [or the RunWithLogon() function in WinBatch], the side effect is that the shell folder to be displayed gets messed up and thus you see C:\ folder being displayed.

Here's the URL for the full discussion and a listing of some work arounds that should solve the problem.

http://blogs.msdn.com/aaron_margosis/archive/2004/07/07/175488.aspx

I would recommend that the URL and some of its contents be placed into the tech support database for future reference, including being tagged with the keywords "RunAs", "RunWithLogon", "ncpa.cpl", "network connections" and "control panel".


Article ID:   W17038
File Created: 2007:07:03:14:27:48
Last Updated: 2007:07:03:14:27:48