1

I have this code:

public void OpenInterOption()
{
    System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo();
    proc.FileName = @"C:\\Windows\\System32\\RunDll32.exe";
    proc.Arguments = "shell32.dll,Control_RunDLL inetcpl.cpl,Internet,4";
    System.Diagnostics.Process.Start(proc);
}

The result is Internet Properties window opened.
But actually I want to open "Local Area Network (LAN) Settings Window" in the Internet Properties tab.
I think the problem in this line:"shell32.dll,Control_RunDLL inetcpl.cpl,Internet,4"; Does it need more arguments?

Buh Buh
  • 7,443
  • 1
  • 34
  • 61
vyclarks
  • 854
  • 2
  • 15
  • 39
  • I think if you just want to update the proxy, that would be done with `Registry`, someone says that it's a bad practice but if your application is targeted for a certain Windows OS, I think that'll be OK. And here are the links which would help you work around http://stackoverflow.com/questions/197725/programmatically-set-browser-proxy-settings-in-c-sharp and http://stackoverflow.com/questions/5570004/how-to-change-lan-settings-proxy-configuration-programmatically :) – King King Jun 15 '13 at 11:58
  • Anh King King là Vietnammese thì em nói Vietnammese luôn cho dễ hiểu nhé. Hic. Em đang làm 1 project giả lập người dùng, là đổi proxy sang các nước khác. Em Em đã thực hiện dòng code để chuyển đối, giống như anh nói. Nhưng em nhận ra, sau khi đổi, nếu mình mở Lan Setting của máy ra (chỉ mở ra và xem) thì kết quả mới thành công tuyệt đối. Biết nói sao nhỉ, sau khi đổi proxy bằng code-> truy cập trang: iplocation.net để kiểm tra-> nếu không view bảng Lan Setting thì máy tính vẫn nhận diện ip mình ở VN. Bây giờ em muốn hiện bảng đó 1 cách tự động. Vì project em làm là tự động. HUHU. Help me!! – vyclarks Jun 15 '13 at 14:04
  • The girl in the picture is me :p – vyclarks Jun 15 '13 at 14:11
  • cái câu hỏi thứ 2 của em anh trả lời hết trong đấy rồi nhé. theo anh thì em nên tìm cách khác chứ show dialog and close có vẻ không chuyển nghiệp. Rất tiếc là anh thiếu kinh nghiệm trong vấn đề lập trình liên quan đến cài đặt mạng, ... Nói thật nhé, từ trước đến giờ anh thấy con gái tin đa số là không xinh, vậy mà giờ gặp một ngoại lệ đấy :) – King King Jun 15 '13 at 17:02
  • Hì, dây cũng là lần đầu tiên em thực hiện 1 project liên quan đến các kiến thức về mạng nhiều như vậy. Em cũng tìm hiểu nhiều, nhưng đa phần đều không thành công tuyệt đối. vì em muốn giả lập trên nhiều máy nên cần phải cho chương trình chạy tự động. Đổi proxy thì chắc ai cũng làm được bằng code, nhưng kết quả không hoàn hảo cho lắm. Hic, em sẽ tìm hiểu thêm. – vyclarks Jun 16 '13 at 06:23

1 Answers1

3

I don't know if opening the network settings would be the right way to go, because if you have more than one LAN including wireless ones which one you want to open? So, you better off opening the Network Connections settings instead and let the user decide which one to open. Thus you could use the code below to open Network Connection settings like:

ProcessStartInfo startInfo = new ProcessStartInfo("NCPA.cpl");
startInfo.UseShellExecute = true;

Process.Start(startInfo);

Update:

You could not call directly LAN Property Settings using any .cpl program. However, there is an unconventional way using your own code and by using SendKeys like this:

   System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo();
   proc.FileName = @"C:\\Windows\\System32\\RunDll32.exe";
   proc.Arguments = "shell32.dll,Control_RunDLL inetcpl.cpl,Internet,4";
   System.Diagnostics.Process.Start(proc);
   SendKeys.Send("{TAB}{TAB}{TAB}{TAB}{ENTER}");

Another way is to use Alt+L instead of Tab. Now, for me this is more sure because in Tab you never know if all will be registered right away or it hops to exactly number of locations like buttons. However, I have to use Timer in order to make sure that it will really effect like this:

   tmr.Interval = 500;

   System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo();
   proc.FileName = @"C:\\Windows\\System32\\RunDll32.exe";
   proc.Arguments = "shell32.dll,Control_RunDLL inetcpl.cpl,Internet,4";
   System.Diagnostics.Process.Start(proc);
   tmr.Tick += new EventHandler(tmr_Tick);
   tmr.Start();

And your Event handler for your Timer:

   void tmr_Tick(object sender, EventArgs e)
   {
       SendKeys.SendWait("%L");
       tmr.Stop();    
   }

Now, make sure that you declare the Timer as global in your class whether inside a form or something else like:

   Timer tmr = new Timer();

Like in my case I put it under and inside Form1 class like:

  public partial class Form1 : Form
  {
    Timer tmr = new Timer();
  .....more code here not shown

Not the most elegant but it will get the job done ;-)

Edper
  • 9,144
  • 1
  • 27
  • 46
  • I mean I just need to open Lan setting window because I've changed proxy in code, Just open to update it. I can open the Internet Option but I dont know how to open the Lan setting window, plzzz – vyclarks Jun 15 '13 at 06:36
  • Have you tired my code yet? Also see this link for different apps in wondows under control panel http://pcsupport.about.com/od/tipstricks/a/control-panel-command-line.htm and this one also http://support.microsoft.com/kb/192806 – Edper Jun 15 '13 at 06:39
  • oh dear! I've tried it. I think I need open Lan Setting window, and Network Connection isn't needed. help me!!! – vyclarks Jun 15 '13 at 06:42
  • Check my unconventional solution @vyclarks ;-) – Edper Jun 15 '13 at 11:02
  • oh dear! @Edper: thank you so much !!! It've worked ! Thanks a lot ^^ By the way, can you tell me how can I close or hide that Lan Setting Window and Internet Option after I viewed it??? By code plzzz, thanks again!!! – vyclarks Jun 15 '13 at 14:19
  • Thats work but i didnot understand the proper commas in processinfo string i used processes before but not commas can you please explain the working of commas ? i know they are taking us on other tabs but i want to know how ? thanks – Ahmad May 04 '18 at 06:55