I am using WinForm application to open a new IE browser with height and width and I got below exception:
System.Runtime.InteropServices.COMException (0x80010108): The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))
And the code it seems to be referencing:
[DllImport("User32.dll")]
public static extern Int32 SetForegroundWindow(int hWnd);
dynamic ie = Activator.CreateInstance(Type.GetTypeFromProgID("InternetExplorer.Application");
string URL = "https://www.google.com/";
ie.ToolBar = 0;
ie.StatusBar = false;
ie.MenuBar = false;
ie.Width = 800;
ie.Height = 550;
ie.Visible = true;
ie.Resizable = false;
ie.AddressBar = false;
ie.Visible = true;
ie.Top = 230;
ie.Left = 300;
ie.Navigate(URL);
SetForegroundWindow(ie.Hwnd)
Any ideas please?
Related
I have created one Xamarin.forms application that runs URL in webview. The app is a digital signage player, So Android TV/Box will run forever.
I found that after 2-3 days the webview either became unstable/hang/crash. I have tried almost all the types of flags but none of them are working.
Some android TV/Box uses com.google.android.webview and some com.android.webview.
Video Android box (Android 7.1 API 25): https://drive.google.com/file/d/1EU7Vf39wFxStNCGJPHyk519G4ifhSEUw/view?usp=sharing
Log (Check Time stamp: 10-21 14:32:36.278 16584): https://drive.google.com/file/d/16bt1vKYNo02Rm9GQA_Hw-PUV36vDvif3/view?usp=sharing
Anyone have any solution?
MyWebClient client = new MyWebClient();
MyWebChromeClient client2 = new MyWebChromeClient();
webView.SetWebViewClient(client);
webView.SetWebChromeClient(client2);
webView.Settings.JavaScriptEnabled = true;
WebSettings webSettings = webView.Settings;
if (Android.OS.Build.VERSION.SdkInt > BuildVersionCodes.Kitkat)
{
webSettings.BuiltInZoomControls = true;
webSettings.SetSupportZoom(false);
webSettings.DisplayZoomControls = false;
if (Element.AspectRatio)
webView.SetInitialScale(100);
}
webSettings.SetPluginState(WebSettings.PluginState.On);
webSettings.SaveFormData = false;
webSettings.SavePassword = false;
webSettings.AllowFileAccess = true;
webSettings.CacheMode = CacheModes.Default;
webSettings.DatabaseEnabled = true;
webSettings.DomStorageEnabled = true;
webSettings.AllowContentAccess = true;
webSettings.AllowFileAccessFromFileURLs = true;
webSettings.AllowUniversalAccessFromFileURLs = true;
webSettings.BlockNetworkImage = false;
webSettings.BlockNetworkLoads = false;
webSettings.JavaScriptEnabled = true;
webSettings.LoadWithOverviewMode = true;
webSettings.UseWideViewPort = true;
webSettings.SetAppCachePath(this.Context.CacheDir.AbsolutePath);
webSettings.SetAppCacheEnabled(true);
webSettings.LoadsImagesAutomatically = true;
webSettings.MixedContentMode = MixedContentHandling.AlwaysAllow;
webSettings.SetEnableSmoothTransition(true);
if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
{
//This flag is for the android box as those are rooted. It's the same displayed on the above video link.
if (MainActivity.IsRootedDevice)
webView.SetLayerType(LayerType.Software, null);
else
webView.SetLayerType(LayerType.Hardware, null);
}
else
{
// older android version, disable hardware acceleration
webView.SetLayerType(LayerType.Software, null);
}
I am writing a WPF UserControl that hosts a RemoteApp session using the AxMSTSCLib library. I'm using the information from this SO question. The code I wrote is very close to the answer of that question.
I placed the RemoteApp ActiveX (axMsRdpClient9NotSafeForScripting1) inside my WPF UserControl, and provide the necessary parameters when connecting.
But the problem is that the WPF Window that contains the UserControl opens but is blank. The RemoteApp actually launches but in a separate window, outside the main WPF Window. How can I ensure the remote app opens inside the WPF UserControl? What am I missing?
Here is my code:
public void Connect()
{
try
{
axMsRdpClient9NotSafeForScripting1.UserName = #"domain\username";
axMsRdpClient9NotSafeForScripting1.Domain = "GTCS";
axMsRdpClient9NotSafeForScripting1.AdvancedSettings7.ClearTextPassword = "password";
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.AuthenticationLevel = 2;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.EnableCredSspSupport = true;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.NegotiateSecurityLayer = false;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.RDPPort = 3389;
axMsRdpClient9NotSafeForScripting1.Server = "GT-DZ1-ATLS.GTCS.LOCAL"; // 10.24.141.199
axMsRdpClient9NotSafeForScripting1.RemoteProgram2.RemoteProgramMode = true;
axMsRdpClient9NotSafeForScripting1.OnConnected += (o, e) =>
{
m_connectionState = axMsRdpClient9NotSafeForScripting1.Connected;
((ITSRemoteProgram)((IMsRdpClient9)axMsRdpClient9NotSafeForScripting1.GetOcx()).RemoteProgram).ServerStartProgram(#"||startchrome", "", "", true, "", false);
//axMsRdpClient9NotSafeForScripting1.RemoteProgram.ServerStartProgram(#"||startchrome", "", "", true, "", false);
};
axMsRdpClient9NotSafeForScripting1.AdvancedSettings7.PublicMode = false;
axMsRdpClient9NotSafeForScripting1.DesktopWidth = SystemInformation.VirtualScreen.Width;
axMsRdpClient9NotSafeForScripting1.DesktopHeight = SystemInformation.VirtualScreen.Height;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.SmartSizing = true;
IMsTscNonScriptable secured = (IMsTscNonScriptable)axMsRdpClient9NotSafeForScripting1.GetOcx();
secured.ClearTextPassword = "password";
axMsRdpClient9NotSafeForScripting1.AdvancedSettings7.ClearTextPassword = "password";
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.RedirectClipboard = true;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.RedirectPrinters = true;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.RedirectPorts = false;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.RedirectSmartCards = true;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.RedirectDrives = true;
axMsRdpClient9NotSafeForScripting1.Visible = true;
axMsRdpClient9NotSafeForScripting1.Enabled = true;
axMsRdpClient9NotSafeForScripting1.Connect();
m_connectionState = axMsRdpClient9NotSafeForScripting1.Connected;
}
catch (Exception ex)
{
var err = ex.Message;
MessageBox.Show(ex.Message);
}
I am attempting to create a console app to create a VPN connection for my company. I am able to create the VPN connection but unable to set a few of the properties. I want Unencrypted password (PAP) to be true and CHAP and CHAP2 to be false. But, the opposite is happening to those settings. I am using DotRas tools. What am i doing wrong or missing?
string VpnName = "Test VPN";
string Destination = "127.0.0.1";
string PresharedKey = "testkey";
RasPhoneBook PhoneBook = new RasPhoneBook();
PhoneBook.Open();
RasEntry VpnEntry = RasEntry.CreateVpnEntry(VpnName, Destination, DotRas.RasVpnStrategy.L2tpOnly, DotRas.RasDevice.Create(VpnName, DotRas.RasDeviceType.Vpn));
VpnEntry.Options.UsePreSharedKey = true;
VpnEntry.Options.UseLogOnCredentials = false;
VpnEntry.Options.RequirePap = true;
VpnEntry.Options.RequireMSChap = false;
VpnEntry.Options.RequireMSChap2 = false;
PhoneBook.Entries.Add(VpnEntry);
VpnEntry.UpdateCredentials(RasPreSharedKey.Client, PresharedKey);
Console.WriteLine("VPN connection created successfully");
You can change the three security checkboxes using a combination of options.
VpnEntry.Options.RequireEncryptedPassword = false;
VpnEntry.Options.RequirePap = true;
VpnEntry.Options.RequireChap = false;
VpnEntry.Options.RequireMSChap = false;
VpnEntry.Options.RequireMSChap2 = false;
Those options will have PAP checked, CHAP unchecked, and MS-CHAP v2 unchecked.
You can connect using the the Windows building dialing command "rasdial.exe", using some code like this :
rasDialFileName = Path.Combine(WinDir, "rasdial.exe");
try
{
string args = $"{connectionName} {userName} {passWord}";
ProcessStartInfo myProcess = new ProcessStartInfo(rasDialFileName, args);
myProcess.CreateNoWindow = true;
myProcess.UseShellExecute = false;
Process.Start(myProcess);
}
catch (Exception Ex)
{
Debug.Assert(false, Ex.ToString());
}
I have to open maximized internet explorer using C#. I have tried the following:
try
{
var IE = new SHDocVw.InternetExplorer();
object URL = "http://localhost/client.html";
IE.ToolBar = 0;
IE.StatusBar = true;
IE.MenuBar = true;
IE.AddressBar = true;
IE.Width = System.Windows.Forms.SystemInformation.VirtualScreen.Width;
IE.Height = System.Windows.Forms.SystemInformation.VirtualScreen.Height;
IE.Visible = true;
IE.Navigate2(ref URL);
ieOpened = true;
break;
}
catch (Exception)
{
}
I can open with different sizes, but I couldn't find how to open maximized IE. I have checked the msdn, there is no property to for maximize.
Please give me some suggestions.
PS: I am developing C# console application, .Net4.5, and VS2012
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Maximize_IE
{
class Program
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
static void Main(string[] args)
{
var IE = new SHDocVw.InternetExplorer();
object URL = "http://google.com/";
IE.ToolBar = 0;
IE.StatusBar = true;
IE.MenuBar = true;
IE.AddressBar = true;
IE.Visible = true;
ShowWindow((IntPtr)IE.HWND, 3);
IE.Navigate2(ref URL);
//ieOpened = true;
}
}
}
I would use the process method.
You could start any executable and
It has a property which starts your process maximized
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle = ProcessWindowStyle.Maximized;
startInfo.Arguments = "www.google.com";
Process.Start(startInfo);
Quick google of "csharp maximize SHDocVw window" gives this example:
[DllImport ("user32.dll")]
private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
private const int SW_MAXIMISE = 3;
public void OpenWindow()
{
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer(); //Instantiate the class.
ShowWindow((IntPtr)ie.HWND, SW_MAXIMISE); //Maximise the window.
ie.Visible = true; //Set the window to visible.
}
try this:
var proc = new Process
{
StartInfo = {
UseShellExecute = true,
FileName = "http://localhost/client.html",
WindowStyle = ProcessWindowStyle.Maximized
}
};
proc.Start();
i am use this code in order to open all link from specific URL, each link will open with new tab, this cause a huge memory use, how can i open the new link on the existing Tab ?
static void Main(string[] args)
{
ProcessStartInfo processStartInfo = null;
string googleChoromePath = "C:\\Users\\Dandin\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe";
string argument = "";
string url = "http://edition.cnn.com/";
WebClient wClient = new WebClient();
string st = wClient.DownloadString(url);
List<string> list = LinkFinder.Find(st);
processStartInfo = new ProcessStartInfo(googleChoromePath);
for (int i = 0; i < list.Count; i++)
{
argument = list[i];
try
{
if (argument.StartsWith("http://"))
{
processStartInfo.Arguments = argument;
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.CreateNoWindow = true;
processStartInfo.UseShellExecute = false;
processStartInfo.ErrorDialog = false;
Process googleChrome = Process.Start(processStartInfo);
Thread.Sleep(1000);
}
}
catch (Exception)
{
}
}
}