Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a .net framework 4.7 project (dll) in which i am calling an exe (.net framework) as follows:

Process visProc = Process.GetCurrentProcess();
                          ProcessStartInfo startInfo = new ProcessStartInfo();
                          startInfo.FileName = "C:\program files\Test.exe"
                          startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                          startInfo.UseShellExecute = true;
                          startInfo.Verb = "runas";
                          startInfo.Arguments = "Hello";

                          try
                          {
                              Process exeProcess = Process.Start(startInfo);

                              exeProcess.WaitForExit();
                          }
                          catch (Exception e)
                          {

                          }


The above code when i am invoking through UI, the process.start() invoking my Test.exe project perfectly and getting all the output as expected. But when the same code is executed through schedule workflow (batch job), the Process.Start throwing an exception. UAC is high on my machine..

Not sure whats wrong in the code code for schedule workflows.

Message in event viewer as follows:

System error number 0x5: Access is denied.
Standard-ouput file could not be returned to backup destination.
File removed.

System error number 0x5: Access is denied.
Process exit status: -532462766.

What I have tried:

The reason why i should run my exe as admin (verb = "runas") is i have to create a folder in C:\Program Files\softwares run time. so the code is
ProcessStartInfo startInfo = new ProcessStartInfo();
                         startInfo.FileName = "C:\program files\Test.exe"
                         startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                         startInfo.UseShellExecute = true;
                         startInfo.Verb = "runas";
                         startInfo.Arguments = "Hello";
Posted
Updated 11-Nov-21 22:47pm

If you're creating folders under Program Files, you're doing something wrong. You should NEVER be writing data to anywhere under Program Files because the entire folder is ReadOnly to users.

Also, you cannot run as an Admin under UAC without being prompted for a password for that account.

The solution to this is to create your folders and put your data in a more appropriate place, like in a folder under C:\ProgramData or similar.
 
Share this answer
 
Comments
Sampath579 11-Nov-21 22:58pm    
But its working fine in UI mode even if i create folder in C:\Program Files with UAC high. But creating the folder in C:\program files is secondary, but in the first place the Process should get invoke. That itself is not happening.
Dave Kreskowiak 11-Nov-21 23:09pm    
I don't care if "it's working fine" on your machine under your ID. It's working fine because you are running the code as an administrator. Normal users will NOT have that ability and your code will fall on its face when a normal user tries to run it.

Is your Test.exe really in the Program Files folder? Next possible problem is your path to that .exe needs to be surrounded in quotes. You're trying to launch this path:
    C:\Program Files\Test.exe

when you need to be launching this path instead:
    "C:\Program Files\Test.exe"

So, your code for that path needs to look like this:
    startInfo.FileName = @"""C:\Program Files\Test.exe""";
Sampath579 12-Nov-21 0:07am    
I took care of spaces in the path. Thats just an example i mentioned here, but in the code i handled it.
Dave Kreskowiak 12-Nov-21 0:10am    
Yeah, don't do that. Post the REAL code so everybody isn't wasting their time on fake code.
Sampath579 12-Nov-21 0:54am    
i pasted the real code here.
startInfo.FileName = "C:\program files\Test.exe"
It worked for me when i remove process.Vert = "runas" even in schedule workflow too. But only issue is unable to create the folders in "C:\Program Files\" location. Does any one know how to make both of them work ?
 
Share this answer
 
Comments
Sampath579 1-Aug-22 0:04am    
Resolved on my own by changing the workflow little bit.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900