Reputation: 5468
This is somewhat in continuation of How to create a Windows Control Panel window using CLSID in Powershell? : what I want to do, is call a command, that will open the "Control Panel" properties of a specific network connection, from another process.
This procedure is described in how to open tcp/ip properties from cmd or run directly? - Super User: the gist of it is that we need the CLSID of the Control Panel "Network Connections" window, to which we append backslash, and then the CLSID of the particular network adapter (which is found in the registry). Unfortunately, I cannot get that specific example to fully work for me, so I'm trying to come up with an invocation that works for me.
So as a first test, I'm trying to replicate working PowerShell commands in cmd.exe
, to make sure quoting and such is good.
To begin with, the CLSID of the Control Panel "Network Connections" window is ::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
(via https://www.autohotkey.com/docs/v1/misc/CLSID-List.htm) ; and from the Windows Registry I've found the CLSID of the network adapter I want is {6B3F2BFD-43E9-4CA9-9F36-1DC80ED4EBF6}
.
So, first: I try to raise just the Control Panel "Network Connections" from PowerShell:
Start-Process "::{7007ACC7-3202-11D1-AAD2-00805FC1270E}" ; echo done
This works fine, and the window is raised/shown:
Then, I try to repeat this command in cmd.exe
, with the below command (with escaped double quotes):
PowerShell -Command "Start-Process """::{7007ACC7-3202-11D1-AAD2-00805FC1270E}"""; echo done"
This works fine too, and the window is raised/shown:
So, now let's test opening a specific window - in principle, we just need to append a backslash \
and the specific network connection ID {6B3F2BFD-43E9-4CA9-9F36-1DC80ED4EBF6}
, to the "Network Connections" window CLSID ::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
, in the above commands.
So first, testing directly in PowerShell, with this command, where I've literally just appended \{6B3F2BFD-43E9-4CA9-9F36-1DC80ED4EBF6}
after the ::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
compared to the previous respective command:
Start-Process "::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\{6B3F2BFD-43E9-4CA9-9F36-1DC80ED4EBF6}"; echo done
This again works fine - a window is shown:
(Somewhat strangely, when this network connection window opens, it does not have focus, and usually ends up instantiated behind existing windows, so it is a bit hard to see; with the first command, the newly created window always pops up in front and is clearly visible.)
HOWEVER, if I try the same in cmd.exe
- reusing the quote escaping as it was, and literally just appending \{6B3F2BFD-43E9-4CA9-9F36-1DC80ED4EBF6}
after the ::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
compared to the previous respective command:
PowerShell -Command "Start-Process """::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\{6B3F2BFD-43E9-4CA9-9F36-1DC80ED4EBF6}"""; echo done"
... then this does NOT raise/show the specific network connection window:
And unfortunately, there is no error reported either: certainly not in terminal; and I've checked the PowerShell entries in Windows Log viewer - the command above is indeed logged, but all of the log entries are Information, no warnings, no errors.
NOTE that as far as plain cmd.exe
is concerned, the usual start
there does work and raises the specific network connection window:
start ::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\{6B3F2BFD-43E9-4CA9-9F36-1DC80ED4EBF6}
... however, I simply cannot get this invocation to work when called from an external program - which is why I decided to try to invoke the window via PowerShell instead.
So I'm interested specifically in how to get the PowerShell command, when called from cmd.exe
, working (and not just getting some form of a command that can raise the window in cmd.exe
- that one is already given above).
So, to summarize, the question is: why does the first cmd.exe
command work and raises a window:
PowerShell -Command "Start-Process """::{7007ACC7-3202-11D1-AAD2-00805FC1270E}"""; echo done"
... while the second cmd.exe
command does not work, in that it does not raise a window:
PowerShell -Command "Start-Process """::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\{6B3F2BFD-43E9-4CA9-9F36-1DC80ED4EBF6}"""; echo done"
... even if both of these commands ultimately work from within PowerShell?
And how can I get the second command (one raising the specific network connection window) to work in cmd.exe
?
(Quoting certainly should not be the problem; otherwise, the only difference I can guess between these two cases, is that PowerShell in the cmd.exe
case runs as a child process of cmd.exe
, and thus maybe it inherits some "wrong" variables or execution policies... but who knows, I'm not really a Windows expert, which is why I'm asking)
Upvotes: 1
Views: 126