I wrote a C# console application which connects to azure file share using net command and then perform some tasks on files. Below is the code which will connect to file share using process.It is working fine when running from local system as a console application.
string netUseCommand = applicationDbContext.AccountConfigurations.FirstOrDefault().NetUseCommand;//Get net use command from database
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo
{
CreateNoWindow = false,
UseShellExecute = false,
Verb = "runas",
FileName = "cmd.exe",
WindowStyle = ProcessWindowStyle.Hidden,
Arguments = @"/c " + netUseCommand + " & " + " Z: && " + "//command to perform file operations"
};
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch (Exception ex)
{
// Log error.
Console.Out.WriteLine("Error Occurred: Error:" + ex.Message);
throw ex;
}
When i deployed this console application as a webjob in azure it started failing while executing netuse command with the below error
[10/23/2018 04:12:45 > 7b7826: ERR ] Access is denied.
I found that azure Powershell is not supported in webjob. Is it the same issue with process(cmd.exe). Please provide the solution or any other alternatives solutions.
Thank you.