Cannot copy files on a mapped drive with Ranorex

Ask general questions here.
rickcuddihey
Posts: 7
Joined: Fri Mar 14, 2014 8:04 pm

Cannot copy files on a mapped drive with Ranorex

Post by rickcuddihey » Wed Feb 20, 2019 5:55 pm

Hi,

I have C# code that simply copies a file from one folder to another folder on a mapped network drive.

This code works fine in Visual Studio. When I run the exact same code in Ranorex I get "System.IO.DirectoryNotFoundException: Could not find a part of the path 'R:\Myshare'."

Why can't I run this code in Ranorex but it works fine in Visual Studio? Even if I make the code into an assembly in Visual Studio, include that assembly in Ranores, and call the code in an assembly it still does not work in Ranorex.

So I tried creating a console application in Visual Studio to copy the file... but when I launch the console application from a Ranorex script I get the same error.

This is driving me nuts. All I want to do is copy a file in my testing that is on a mapped drive and it seems impossible.

Thank you if you can help me out.

Rick

ahoisl
Certified Professional
Certified Professional
Posts: 192
Joined: Fri Sep 07, 2007 8:16 am

Re: Cannot copy files on a mapped drive with Ranorex

Post by ahoisl » Wed Feb 20, 2019 9:10 pm

Are you running Ranorex as administrator? Network shares mapped to a drive are user settings that will not be valid as admin.
Try running Ranorex as a normal user or use a full network path.
If both does not help, try disabling the "Use UiaLauncher..." option in the Advanded settings.

Regards,
Alex
Ranorex Team

rickcuddihey
Posts: 7
Joined: Fri Mar 14, 2014 8:04 pm

Re: Cannot copy files on a mapped drive with Ranorex

Post by rickcuddihey » Thu Feb 21, 2019 5:44 pm

Thank you for the reply.

Disabling the "Use UiaLauncher..." option did not help.

Running Ranorex in non-administrator mode does fix my problem with accessing the shared drive but now I have a problem copying local files.

I am running Ranorex in administrator mode. I need to copy local files on my system. If I am not in admin mode I get "Access to the path ... is denied". I'm using Windows 10 and disabled UAC, etc.

So when running as normal user I can copy mapped network files but cannot copy local files. In administrator mode I cannot copy network files but I can copy local files.

This makes no sense to me and I cannot run Ranorex in both modes. Is this a bug or done on purpose?

Thanks again.

Rick

dhale
Posts: 84
Joined: Thu Feb 27, 2014 7:33 pm

Re: Cannot copy files on a mapped drive with Ranorex

Post by dhale » Thu Feb 21, 2019 6:15 pm

You might need to impersonate user - we do that when we need to copy files around on the network

rickcuddihey
Posts: 7
Joined: Fri Mar 14, 2014 8:04 pm

Re: Cannot copy files on a mapped drive with Ranorex

Post by rickcuddihey » Thu Feb 21, 2019 7:26 pm

I have fixed this for now by running in normal mode and impersonating the local user when I want to copy files locally.

I would still like to know if this this a bug or not? Why does Visual Studio (same IDE framework used by Ranorex I believe) not experience this issue?

Thanks again.

Rick

ahoisl
Certified Professional
Certified Professional
Posts: 192
Joined: Fri Sep 07, 2007 8:16 am

Re: Cannot copy files on a mapped drive with Ranorex

Post by ahoisl » Thu Feb 21, 2019 10:32 pm

rickcuddihey wrote:
Thu Feb 21, 2019 7:26 pm
I would still like to know if this this a bug or not? Why does Visual Studio (same IDE framework used by Ranorex I believe) not experience this issue?
I'm not 100% sure that I understand how you experience the difference. If debugging with Ranorex Studio/Visual Studio? Do you start both Ranorex Studio and Visual Studio as admin or normal user?

If you run the executable directly, it will definitely not make a difference, as file handling is nothing Ranorex specific, but you are basically then just using the plain .NET Framework APIs that also Ranorex is built on. There could be a difference, though, in the way the two IDEs start and/or debug an executable.

Anyway, the problem that user-mapped network shares are not available if you run an executable or command line as Administrator, is nothing specific to Ranorex. The same thing happens if you start a normal Windows command line as Administrator - you will need to map the network shares to drives again then.

Regards,
Alex
Ranorex Team

rickcuddihey
Posts: 7
Joined: Fri Mar 14, 2014 8:04 pm

Re: Cannot copy files on a mapped drive with Ranorex

Post by rickcuddihey » Fri Feb 22, 2019 2:54 pm

It has nothing to do with the drives being mapped or not mapped. They are always mapped and available. Here's a better explanation.

I develop common code in Visual Studio that is used in Ranorex and other test applications.

I have a class for copying files. This class copies from local drives and from mapped drives. When I run the code in Visual Studio to copy the files it all works fine. It will copy from my local drive to a mapped drive, mapped drive to a local drive, etc. without any problems. I am not running Visual Studio as admin.

My expectations are that I can now simply use this class in Ranorex and it would work fine as it did in Visual Studio. However, when I try and use this class in Ranorex the local copying of the files cannot be done unless Ranorex is run as Admin. Without Ranorex running as admin access is denied to the files that are local. But, when I am in Admin mode Ranorex cannot find the mapped drive.

To summarize, when running code in Visual Studio I can copy from local drives to mapped drives no problem.

In Ranorex I get this:

Admin mode - can copy local files (good), cannot find mapped drives (bad).
Normal mode - cannot access local files (bad), can find mapped drives (good).

So I'm stuck not being able to copy a local file to a mapped drive.

Rick

ahoisl
Certified Professional
Certified Professional
Posts: 192
Joined: Fri Sep 07, 2007 8:16 am

Re: Cannot copy files on a mapped drive with Ranorex

Post by ahoisl » Sat Feb 23, 2019 8:57 pm

rickcuddihey wrote:
Fri Feb 22, 2019 2:54 pm
My expectations are that I can now simply use this class in Ranorex and it would work fine as it did in Visual Studio.
Your expectation is 100% correct when always starting the executable using Windows Explorer, e.g. by double-clicking the executable; then the executable will always have the same behavior, no matter if compiled using VS or Ranorex Studio.
The behavior for debugging or starting directly from within Visual Studio or Ranorex Studio may be different though, because both Visual Studio and Ranorex Studio may have different security privileges and thus may also start the executable with different accounts or privileges.
That said, 99% of times the behavior should be the same, you probably found some edge case :?

I'm a bit out of ideas what to suggest currently. To my knowledge, both VS and Ranorex Studio should behave very similar: Both should have access to local files if running as non-admin, unless those files are available to the administrator only. And both should actually not have access to mapped drives if running as administrator and the drives are only mapped by the user (and not mapped for the administrator account, see here for more info).

As there are at least 3 ways to run as administrator in Windows and the same number of ways to map network drives and everything's a bit different on every Windows version, it's hard to give some general suggestions other than above.
To narrow things down, can you please exactly describe:
  • What version of Windows you use; use the command "winver" in the start menu to get the exact version
  • How you start Ranorex as administrator, i.e. using a shortcut, by the automatic restart invoked by Ranorex, by selecting "Run as admin"...
  • Which files and in which folder you want to copy locally; are these in secure folders?
  • How you map your network drives and if they are also mapped as administrator; you can find out by starting a Windows command line as administrator (right-click and choose "Run as admin") and then write the command "net use"
Thanks!

Regards,
Alex
Ranorex Team

ETS
Posts: 1
Joined: Fri Mar 29, 2019 10:40 pm

Re: Cannot copy files on a mapped drive with Ranorex

Post by ETS » Fri Mar 29, 2019 10:57 pm

I've ran into this issue before where the network drive is only mapped on the local user and isn't available to any programs being "Run as administrator".

To get around this you can recreate the network share for the Administrator.
To do this manually to see if it solves your issue, run cmd(.)exe as administrator (Right click on it and select Run as Administrator).
Then create the network share while cmd is running as admin, for example: "net use R: \\mySharedFolder"


Then see if your program running as administrator has access to the networked folder. If that solves it then you can create a user code function called at the start of your program to do this for you using:

System.Diagnostics.Process.Start("CMD(.)exe",@"/c net use R: \\mySharedFolder");

Replace the (.)'s with just a period, the forum won't let the post the text otherwise.