あなたがこれを必要とする理由をリモートインスタンスのフルパスに\ danas-PC用の\ PublicDocですが、あなたが許可すれば、あなたの想像力は、私がこのような何かをお勧めしたい繁栄するので、私は想像することはできません。
(1)共有フォルダ内のリモートコンピュータ上で、実行されると完全なパスを返す小さなスクリプトを削除することができます。実行権限や権限が必要なWindowsやLinux環境の適切なコーディングを検索する必要があります。たとえば、Windows上では、linuxにvbscritまたはcscriptと.shスクリプトを持つことができます。
また、リモートホストから見ると、リモートホストの観点から見ると、フルパスは\ NAME-OR-IP \ Path \から\ Folder \または\ Fileになります。完全なパスです。)
UPDATE:以下のコメントどおり が、これは以下の
- を行い、完全なスクリプトは現在のフルパスを取得することで、コードとVBScriptを作成しています
- はファイルをコピーしますネットワーク所望の経路
- にVBScriptを実行し、バック結果を読み込み
- は、と仮定すると、VBScriptの
を削除します。あなたはネットワークフォルダ残念ながら
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace GetNetworkFullPath
{
class Program
{
static void Main(string[] args)
{
var networkFolder = "\\\\REMOTE-PC-NAME\\SharedFolder";
var nameOfVBScript = "capturepath.vbs";
var vbsOutput = "";
//Get the name of the current directory
var currentDirectory = Directory.GetCurrentDirectory();
Console.WriteLine("Current Dir: " + currentDirectory);
//1. CREATE A VBSCRIPT TO OUTPUT THE PATH WHERE IT IS PRESENT
//Ref. https://stackoverflow.com/questions/2129327/how-to-get-the-fully-qualified-path-for-a-file-in-vbscript
var vbscriptToExecute = "Dim folderName \n" +
"folderName = \"\" \n" +
"Dim fso \n" +
"Set fso = CreateObject(\"Scripting.FileSystemObject\") \n" +
"Dim fullpath \n" +
"fullpath = fso.GetAbsolutePathName(folderName) \n" +
"WScript.Echo fullpath \n";
//Write that script into a file into the current directory
System.IO.File.WriteAllText(@""+ nameOfVBScript + "", vbscriptToExecute);
//2. COPY THE CREATED SCRIPT INTO THE NETWORK PATH
//Ref. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/file-system/how-to-copy-delete-and-move-files-and-folders
string sourceFile = System.IO.Path.Combine(currentDirectory, nameOfVBScript);
string destFile = System.IO.Path.Combine(networkFolder, nameOfVBScript);
System.IO.File.Copy(sourceFile, destFile, true);
//3. EXECUTE THAT SCRIPT AND READ THE OUTPUT
//Ref. https://stackoverflow.com/questions/27050195/how-do-i-get-the-output-from-my-vbscript-console-using-c
Process scriptProc = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.WorkingDirectory = @"" + networkFolder + "";
info.FileName = "Cscript.exe";
info.Arguments = nameOfVBScript;
info.RedirectStandardError = true;
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
info.WindowStyle = ProcessWindowStyle.Hidden;
scriptProc.StartInfo = info;
scriptProc.Start();
scriptProc.WaitForExit();
bool exit = false;
while (!scriptProc.StandardOutput.EndOfStream)
{
vbsOutput = scriptProc.StandardOutput.ReadLine();
}
Console.WriteLine("vbscript says: " + vbsOutput);
//4. DELETE THE FILE YOU JUST COPIED THERE
System.IO.File.Delete(@"" + networkFolder + "\\" + nameOfVBScript);
}
}
}
上の読み取り/書き込みアクセス権を持っていますリモートから実行されたスクリプトはネットワークパスで応答します。(とても失望しています...本当に申し訳ありません!リモートシステムの外部のユーザーから実行が行われている限り、そのインスタンスに関連する絶対パスで応答します。私は、内部プロセス/ユーザーがファイルを実行し、アプリケーションへの回答を返すべきだと思います。
明日はもっと何かを考えてみると、私はラッキーだ場合、多分返信ます。
なぜそれをしたいですか? –
私はあなたに答えを与えるべきだと思いますか? https://superuser.com/questions/1146811/getting-real-path-of-file-on-samba-server-from-client – mariozski
あなたが何を求めているのか分かりません。そうでないかもしれない。あらかじめ定義された ' $'共有名を通るものを含め、サーバー上の同じファイルを参照できるUNCパスはいくつでもあります。それらのどれかを「真の」道にするのは何ですか?誰かが '<ドライブ文字$> 'シェアを無効にするようにサーバを設定したら?すべてのケースで実際に起こると思われることとその理由を明確にするため、質問を修正してください。あなたの目標を達成することはまずありませんが、現時点では目標が実際にどのようなものか明確ではありません。 –