0

I have written a win application that works on a network.

In one of its forms user can browse and select file from local computer and add it to a list, so the application copies these files to a folder in My Network Places that no users can access to it but one that i have created already for my application so i have his username and password.Every things works fine up to here.

In this form user can also open a file by select it and press open button, so the file should open in an application that relates to its extension(for example test.xlsx should open in Exel.exe).I have used Process.Start() to do this but for each extension i receive an individual error(for example "Access is denied" for NotePad and "RunTime error" for AdobeReader and "Not enough memory" for Excel).

What is my mistake?

Note : I have used ImpersonatUser to logon that user in my application.

Edit : I have used following code to open the file :

Using(WindowsImpersonationContext impersonateUser = LogonMethod())
{
    ProcessStartInfo pInfo = new ProcessStartInfo(filePathWithExtension);
    pInfo.Domain = MyDomainName;
    pInfo.UseShellExecute = false;
    Process.Start(pInfo);
}

Note : My LogonMethod uses LogonUser method of advapi32.dll.

M_Mogharrabi
  • 1,369
  • 5
  • 29
  • 57
  • 1
    Let see some example code that you've tried? – Chris Moutray Jun 30 '12 at 05:28
  • 1
    It also would be useful to clarify under what account you are trying to run applications as well as code you have to do so (since sometimes there could be mismatch between intentions and implementations). – Alexei Levenkov Jun 30 '12 at 05:43
  • @AlexeiLevenkov, Thanks for your reply.It is a normal account but it can do all other functions such as copy, delete or cut a file, zipping a folder, restoring a database backup and .... – M_Mogharrabi Jun 30 '12 at 07:19

2 Answers2

0

The behavior you are seeing is almost expected.

  • it looks like you are not launching application directly, but rater using association by file name. I don't believe you'll get application launched under account you want. You can check what account application is run unrder using task manager.
  • Most application are not tested to run in "run as" context, so they may work correctly or fail randomly.
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
0

I could not solve this problem, so i have used another way.I have copied the file to a temp folder and then used Process.Start to open this new file.

M_Mogharrabi
  • 1,369
  • 5
  • 29
  • 57