c# - Open the process is the process ID is known -


how open link application using process id of ie process.

i have 2 instances of ie open , have process id of 1 of them.

edit: code have written below :

bool isactive = false;          if (file.exists("processid.txt"))         {             processid = convert.toint32(file.readalltext("processid.txt"));             process[] activeprocess = process.getprocesses();              foreach (process proc in activeprocess)             {                 if (proc.id == processid)                 {                     isactive = true;                     break;                 }             }         }          //existingprocess = process.getprocessbyid(processid);         if (!string.isnullorempty(textbox1.text))         {             if (isactive)             {                 //process oldproc = process.getcurrentprocess();                 process oldproc = process.getprocessbyid(processid);                 processstartinfo psi = new processstartinfo(textbox1.text);                   //string processname = oldproc.processname;                 //string mainwindowtitle = oldproc.mainwindowtitle;                                     //setfocus(new handleref(null, oldproc.handle));                  //psi.useshellexecute = false;                  oldproc.startinfo = psi;                 oldproc.start();                  int prhandle = process.getcurrentprocess().id;                 label1.text = prhandle.tostring();                  //file.writealltext("processid.txt", prhandle.tostring());              }             else              {                 processstartinfo pi = new processstartinfo(@"c:\program files\internet explorer\iexplore.exe", textbox1.text);                 newprocess.startinfo = pi;                 newprocess.start();                  int prhandle = newprocess.id;                 label1.text = prhandle.tostring();                  file.writealltext("processid.txt", prhandle.tostring());                                 }         }         else         {              messagebox.show("enter url ");         } 

thanks in advance.

to achieve desired result, can try this. there unnecessary casting going on , it's not written, should gist of it.

[dllimport("user32.dll", setlasterror = true)] static extern uint getwindowthreadprocessid(intptr hwnd, out uint processid);  public void navigate2url(int processid, string strurl) {     shdocvw.shellwindows sws = new shdocvw.shellwindows();     shdocvw.internetexplorer ie = null;      (int = 0; < sws.count; i++)     {         ie = (shdocvw.internetexplorer)sws.item(i);          uint pid;         getwindowthreadprocessid((intptr)ie.hwnd, out pid);         if ((intptr)ie.hwnd == (intptr)pid)         {             object o = null;             ie.navigate2(strurl, ref o, ref o, ref o, ref o);         }     } } 

then use this

navigate2url(12108, "mydomain.com"); 

note change url tabs inside pid, if want target specific tab in ie process, code longer , more hackish.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -