2017-06-23 4 views
-2

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#でのアクセスを取得する権限を与えることができますか?

+0

https://stackoverflow.com/questions/2818179/how-do-iforce-my-net-application-to-run-as-administratorの可能な複製 –

+0

ユーザーはプロセスが2台目のマシンにはディレクトリとファイルのアクセス権がありますか? – MORCHARD

+0

@MORCHARD私はそうは思いません。それでは、プログラム的に許可を取る方法。 – Kumar

答えて

0

希望のフォルダの内容を変更するには、管理者権限の昇格(管理者)権限が必要です。つまり、管理者としてアプリを実行する必要があります。あなたはおそらくローカル管理者であり、あなた自身のシステムを変更する権利を持っているため、あなたのローカル環境で動作します。

関連する問題