I am trying to move one dll file programatically in c# from System32 or SysWOW64 directory. I am using following code:
string path32 = "c:/windows/System32/";
string path64 = "c:/windows/SysWOW64/";
string fileName = "mydll.dll";
string[] paths = { path32, path64 };
foreach (string p in paths)
{
if (int.Parse(year) == 1)
{
DirectoryInfo d = new DirectoryInfo(p);
FileInfo[] infos = d.GetFiles(fileName);
foreach (FileInfo f in infos)
{
// Do the renaming here
File.Move(f.FullName, Path.Combine(f.DirectoryName, "1" + f.Name));
}
}
}
I am using this method on certain condition in WCF service. When I do it my local environment, it is working fine. But when I am running on different machine, it is throwing following error:
the server encountered an error processing the request. Please see the service help page for constructing valid requests to the service. The exception message is 'Access to the path is denied.'. See server logs for more details. The exception stack trace is:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.File.InternalMove(String sourceFileName, String destFileName, Boolean checkHost) at SyncInvokeCalculateFestivaldate(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
How can I give permission to get access in c# so that it will rename and move the dll file?