System32またはSysWOW64ディレクトリからc#でプログラムで1つのdllファイルを移動しようとしています。私は次のコードを使用しています:system32またはSysWOW64からdllファイルを移動または削除する方法programatically
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));
}
}
}
私はこのメソッドをWCFサービスで一定の条件で使用しています。私はそれを私のローカル環境でやってもうまくいっています。しかし、私は別のマシン上で実行していたときに、それは誤り以下投げている:
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)
は、どのように私はそれがdllファイルの名前を変更して移動するように、C#でのアクセスを取得する権限を与えることができますか?
https://stackoverflow.com/questions/2818179/how-do-iforce-my-net-application-to-run-as-administratorの可能な複製 –
ユーザーはプロセスが2台目のマシンにはディレクトリとファイルのアクセス権がありますか? – MORCHARD
@MORCHARD私はそうは思いません。それでは、プログラム的に許可を取る方法。 – Kumar