System.AppDomain objAPDom = System.AppDomain.CurrentDomain;
object obj = objAPDom.GetData("APP_LAUNCH_URL");
| “name”的值 |
屬性 |
| "APPBASE" |
ApplicationBase |
| "APP_CONFIG_FILE" |
ConfigurationFile |
| "DYNAMIC_BASE" |
DynamicBase |
| "DEV_PATH" |
(無屬性) |
| "APP_NAME" |
ApplicationName |
| "CACHE_BASE" |
PrivateBinPath |
| "BINPATH_PROBE_ONLY" |
PrivateBinPathProbe |
| "SHADOW_COPY_DIRS" |
ShadowCopyDirectories |
| "FORCE_CACHE_INSTALL" |
ShadowCopyFiles |
| "CACHE_BASE" |
CachePath |
| (應用程式特定的) |
LicenseFile |
錯誤碼:
//應用程式定義域
System.AppDomain objAPDom = System.AppDomain.CurrentDomain;
object obj = objAPDom.GetData("APP_LAUNCH_URL");
if (obj == null)
{
strURL = "";
}
else
{
strURL = obj.ToString();
}
首先需要匯入 C:\WINDOWS\System32\mshtml.tlb、Interop.SHDocVw.dll兩個動態庫檔案
-收縮
C#代碼/// <summary>
/// 返回指定Url的IE視窗下的 IHTMLDocument2 對象。
/// </summary>
/// <returns>IHTMLDocument2</returns>
public static IHTMLDocument2 GetIHTMLDocument2ByUrl(string url)
{
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
string filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals("iexplore") && ie.LocationURL == url)
{
return ie.Document as IHTMLDocument2;
}
}
}
通過 GetIHTMLDocument2ByUrl 方法可以擷取已開啟的IE視窗中指寫地址的視窗中的 IHTMLDocument2 對象。
利用這個對象,就可以進行相關操作。
1.填寫表單
-收縮
C#代碼IHTMLDocument2 iHTMLDocument2 = GetIHTMLDocument2ByUrl("http://www.163.com");
IHTMLInputElement input = (IHTMLInputElement)iHTMLDocument2.all.item("Username", 0); // 擷取指定名稱的對象
input.value = "Xiao"; // 賦值
2.點擊按鈕
-收縮
C#代碼IHTMLDocument2 iHTMLDocument2 = GetIHTMLDocument2ByUrl("http://www.163.com");
HTMLDocumentClass obj = (HTMLDocumentClass)iHTMLDocument2;
IHTMLElement iHTMLElement = null;
IHTMLElementCollection c = obj.getElementsByTagName("input");
foreach (IHTMLElement e in c)
{
if (e.outerHTML.IndexOf("登入") != -1)
{
iHTMLElement = e;
break;
}
}
if (iHTMLElement != null)
{
iHTMLElement.click(); // 點擊登入按鈕
}
Winform擷取當前IEURL地址
- System.Diagnostics.Process[] _List = System.Diagnostics.Process.GetProcessesByName("iexplore");
-
- [DllImport("user32.dll")]
- public static extern int EnumChildWindows(IntPtr hWndParent, EnumWindowsProc ewp, int lParam);