C# 如何自动导航到 {GUID} 目录?

发布于 2024-10-07 16:28:55 字数 1086 浏览 0 评论 0原文

我有一个程序,它利用第三方工具来创建日志文本文件。

但是该工具需要Windows XP的还原点目录。存储还原点的目录是“C:\System Volume Information_restore{GUID}”。

_restore{GUID} 文件夹将包含所有还原点。然而,{GUID} 是完全随机的数字,并且对于每台计算机来说都是不同的。 “C:\System Volume Information”目录通常只包含 1 个文件夹,即“_random{GUID}”文件夹。

那么有没有办法让C#程序使用任何代码或方法来自动填充工具的命令参数呢?

有人可以建议一下代码吗?谢谢!

代码:

        Process process = new Process();
        process.StartInfo.FileName = @"C:\test\ftk\ripxp\ripxp.exe";
        // How to automatically navigate to the {GUID} folder?
        process.StartInfo.Arguments = @"-r C:\test\ftk\ntuser.dat -d C:\System Volume Information\_restore{GUID} -p runmru";
        process.StartInfo.CreateNoWindow = false;
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardInput = true;
        process.StartInfo.RedirectStandardError = true;
        process.Start();

第 3 方工具 (2008 H. Carvey) 参数:

C:\>ripxp -r d:\cases\ntuser.dat -d d:\cases\svi -p userassist

I have a program which utilizes a 3rd party tool to create a log text file.

However the tool requires the restore point directory of windows XP. The directory that stores the Restore points is the "C:\System Volume Information_restore{GUID}".

The _restore{GUID} folder would contain all the restore points. However the {GUID} are totally random numbers and are different for each computers. The "C:\System Volume Information" directory would only usually contain 1 folder which is the "_random{GUID}" folder.

Therefore is there a way for the C# program to use any codes or methods to automatically fill in the command arguments for the tool?

May someone please advise on the codes? Thanks!

The codes:

        Process process = new Process();
        process.StartInfo.FileName = @"C:\test\ftk\ripxp\ripxp.exe";
        // How to automatically navigate to the {GUID} folder?
        process.StartInfo.Arguments = @"-r C:\test\ftk\ntuser.dat -d C:\System Volume Information\_restore{GUID} -p runmru";
        process.StartInfo.CreateNoWindow = false;
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardInput = true;
        process.StartInfo.RedirectStandardError = true;
        process.Start();

The 3rd party tool (2008 H. Carvey) Arguments:

C:\>ripxp -r d:\cases\ntuser.dat -d d:\cases\svi -p userassist

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千纸鹤 2024-10-14 16:28:55

此代码显示如何获取最近创建的 _restore 目录:

    static void Main(string[] args)
    {
        DirectoryInfo di = new DirectoryInfo(@"c:\System Volume Information");
        DirectoryInfo directoryInfo = null;
        foreach (var enumerateDirectories in di.GetDirectories("_restore*"))
        {
            if (directoryInfo == null || enumerateDirectories.CreationTime > directoryInfo.CreationTime)
            {
                directoryInfo = enumerateDirectories;
            }
        }
        if (directoryInfo != null)
        {
            Console.WriteLine(directoryInfo.FullName);
        }
        Console.ReadLine();
    }

This code shows how to get the most recently created _restore directory:

    static void Main(string[] args)
    {
        DirectoryInfo di = new DirectoryInfo(@"c:\System Volume Information");
        DirectoryInfo directoryInfo = null;
        foreach (var enumerateDirectories in di.GetDirectories("_restore*"))
        {
            if (directoryInfo == null || enumerateDirectories.CreationTime > directoryInfo.CreationTime)
            {
                directoryInfo = enumerateDirectories;
            }
        }
        if (directoryInfo != null)
        {
            Console.WriteLine(directoryInfo.FullName);
        }
        Console.ReadLine();
    }
樱花落人离去 2024-10-14 16:28:55

为什么不查询该文件夹位置并循环浏览目录列表以找到以“_restore”开头的文件夹,然后将其插入到您的参数中?

DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\System Volume Information\");
DirectoryInfo restoreFolder = directoryInfo.GetDirectories().FirstOrDefault(d => 
    d.Name.StartsWith("_restore"));

if (restoreFolder == null)
    throw new DirectoryNotFoundException();

然后您应该能够将该文件夹值插入到您的参数中

process.StartInfo.Arguments = string.Format(
    @"-r C:\test\ftk\ntuser.dat -d C:\System Volume Information\{0} -p runmru", 
    restoreFolder.Name);

Why not query that folder location and loop through the list of directories to find the folder that starts with "_restore" and then plug that into your argument?

DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\System Volume Information\");
DirectoryInfo restoreFolder = directoryInfo.GetDirectories().FirstOrDefault(d => 
    d.Name.StartsWith("_restore"));

if (restoreFolder == null)
    throw new DirectoryNotFoundException();

Then you should be able to plug that folder value into your argument

process.StartInfo.Arguments = string.Format(
    @"-r C:\test\ftk\ntuser.dat -d C:\System Volume Information\{0} -p runmru", 
    restoreFolder.Name);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文