Disable ethernet

Ask general questions here.
SanMan
Posts: 204
Joined: Tue Apr 13, 2010 9:59 am

Disable ethernet

Post by SanMan » Tue May 07, 2019 7:54 am

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

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 5071
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Disable ethernet

Post by odklizec » Tue May 07, 2019 8:10 am

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 ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

SanMan
Posts: 204
Joined: Tue Apr 13, 2010 9:59 am

Re: Disable ethernet

Post by SanMan » Tue May 07, 2019 12:50 pm

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?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 5071
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Disable ethernet

Post by odklizec » Tue May 07, 2019 12:59 pm

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 ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

SanMan
Posts: 204
Joined: Tue Apr 13, 2010 9:59 am

Re: Disable ethernet

Post by SanMan » Tue May 07, 2019 1:09 pm

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...

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 5071
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Disable ethernet

Post by odklizec » Tue May 07, 2019 1:11 pm

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
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

SanMan
Posts: 204
Joined: Tue Apr 13, 2010 9:59 am

Re: Disable ethernet

Post by SanMan » Wed May 08, 2019 5:50 am

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?

McTurtle
Posts: 255
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Disable ethernet

Post by McTurtle » Wed May 08, 2019 11:47 am

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

SanMan
Posts: 204
Joined: Tue Apr 13, 2010 9:59 am

Re: Disable ethernet

Post by SanMan » Thu May 09, 2019 11:14 am

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!