Page 1 of 1

Disable ethernet

Posted: Tue May 07, 2019 7:54 am
by SanMan
Hi,

can I use this code in Ranorex to disable LAN?

static void DisableLan(string interfaceName)
{

interfaceName="Ethernet";
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface name=" + interfaceName + " admin=ENABLE");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();

}

It needs admin rights; is the console running with admin rights?

This does not work for me...get some exception

Re: Disable ethernet

Posted: Tue May 07, 2019 8:10 am
by odklizec
Hi,

If it requires admin rights, then you must start Studio or your test exe as administrator. Also, if you disable network, Ranorex will not be able to check its license and therefore, it will issue a popup dialog about unavailable license. So I don't think it's a good idea to test such scenario with Ranorex ;)

Re: Disable ethernet

Posted: Tue May 07, 2019 12:50 pm
by SanMan
Hi,

I am running the Ranorex Studio as administrator so "test run console" is also running as admin mode?

When I remove LAN cable while running test case, I did not got any pop-up about license....

Could there be something else that I have missed while trying to disable the LAN?

Re: Disable ethernet

Posted: Tue May 07, 2019 12:59 pm
by odklizec
Hi,

I'm not quite sure what you mean with "test run console"? If the test is started from Ranorex Studio, started as administrator, the test exe runs as admin as well. I guess your laptop is on company's wifi as well? So once you disconnected LAN, it switched to wifi and the license is checked that way? If you disable wifi as well, the license popup will definitely appear ;)

Re: Disable ethernet

Posted: Tue May 07, 2019 1:09 pm
by SanMan
Hi,

Yes, I meant just that about the "console".

Hmm...I have disabled Wlan also and disconnected LAN cable (no internet access), but still not get the license pop-up?
I am using node-locked license...

Re: Disable ethernet

Posted: Tue May 07, 2019 1:11 pm
by odklizec
SanMan wrote:
Tue May 07, 2019 1:09 pm
Hmm...I have disabled Wlan also and disconnected LAN cable (no internet access), but still not get the license pop-up?
I am using node-locked license...
Hehe this explains it then :D

Re: Disable ethernet

Posted: Wed May 08, 2019 5:50 am
by SanMan
Yes :)

static void DisableLan(string interfaceName)
{
interfaceName="Ethernet";
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface name=" + interfaceName + " admin=ENABLE");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
}

Could someone help what could be wrong with this code when trying to disable Ethernet?

Re: Disable ethernet

Posted: Wed May 08, 2019 11:47 am
by McTurtle
Hi SanMan,

Enable some debugging of your code by redirecting the stream:
public void DisableLan()
		{
			string interfaceName="Ethernet";
			System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface name=" + interfaceName + " admin=Disable");
			System.Diagnostics.Process p = new System.Diagnostics.Process();
			p.StartInfo = psi;
			p.StartInfo.UseShellExecute=false;
			p.StartInfo.RedirectStandardOutput=true;
			p.Start();
			
			var reader = p.StandardOutput;
			while (!reader.EndOfStream)
			{
				var nextLine = reader.ReadLine();
				Report.Info(nextLine);
			}

			p.WaitForExit();
			Console.ReadKey();
		}
What does your Ranorex console or report say now?

Regard,
McTurtle

Re: Disable ethernet

Posted: Thu May 09, 2019 11:14 am
by SanMan
Hi McTurtle,

just copy & paste your code and now it is working!!

I got some error from debug but when commented it out, works like a charm :)

00:09.449 Error Module
Jump to item View Help
Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.
Show/Hide Stacktrace
at System.Console.ReadKey(Boolean intercept)at System.Console.ReadKey()at MyTest.Recording1.DisableLan() in c:\...\Recording1.UserCode.cs:line 60at MyTest.Recording1.Ranorex.Core.Testing.ITestModule.Run() in c:\...\Recording1.cs:line 82at Ranorex.Core.Testing.TestModuleLeaf.RunInternal(DataContext parentDataContext, Int32 iteration, Int32 iterationCount, Boolean skipIteration)

Thanks!