简体   繁体   English

如何使用用户名和密码在远程计算机上使用 C# 获取文件详细信息

[英]How to get file details using C# on a remote machine with username and password

Tried to search for something similar but could not find.试图搜索类似的东西,但找不到。

I have file on a remote machine which I want to query for it`s details like version, date, etc. How do I do that when I need to enter credentials for that machine?我在远程机器上有文件,我想查询它的详细信息,如版本、日期等。当我需要输入该机器的凭据时,我该怎么做? FileVersionInfo does not give option to do so. FileVersionInfo 没有提供这样做的选项。

Thanks谢谢

Update:更新:

As I said above I checked what FIleVersionInfo gives me (and also tried it) and that will not work for me.正如我上面所说,我检查了 FIleVersionInfo 给我的内容(并尝试了它),但这对我不起作用。 I also tried using WMI and failed with (although it looked like the direction I need) Here is the WMI code I tried - haven`t got much far:我也尝试过使用 WMI 并且失败了(虽然它看起来像我需要的方向)这是我尝试过的 WMI 代码 - 还没有走多远:

var computerName = "IP_ADDRESS";
            ConnectionOptions conn = new ConnectionOptions();
            conn.Username = "username";
            conn.Password = "password";
            conn.Authority = "ntlmdomain:DOMAIN";
            conn.Impersonation = ImpersonationLevel.Impersonate;
            conn.EnablePriviledges = true;
            var scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", computerName), conn);


            scope.Connect();
            string Drive = "c:";
            string Path = "\\\\inetpub\\\\wwwroot\\\\FOLDER\\\BIN\\\File.dll";

            ObjectQuery Query = new ObjectQuery(string.Format("SELECT * FROM CIM_DataFile Where Drive='{0}' AND Path='{1}' ", Drive, Path));

            ManagementObjectSearcher Searcher = new ManagementObjectSearcher(scope, Query);

            foreach (ManagementObject WmiObject in Searcher.Get())
            {
                Console.WriteLine("{0}", (string)WmiObject["Name"]);// String
            }

I mainly need the file properties version and date.我主要需要文件属性版本和日期。

Thanks谢谢

Thanks to @Draken comment above I`ve added missing properties on the ConnectionOptions and also fixed my mistake on the domain name.感谢上面的@Draken 评论,我在 ConnectionOptions 上添加了缺失的属性,并修复了我在域名上的错误。

Here is the code I use to get to the file in the network PC这是我用来访问网络PC中的文件的代码

var computerName = "IP_ADDRESS";
        ConnectionOptions conn = new ConnectionOptions();
        conn.Username = "username";
        conn.Password = "password";
        conn.Authority = "ntlmdomain:DOMAIN";
        conn.Impersonation = ImpersonationLevel.Impersonate;
        conn.EnablePriviledges = true;
        var scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", computerName), conn);


        scope.Connect();
        string Drive = "c:";
        string Path = "\\\\inetpub\\\\wwwroot\\\\FOLDER\\\BIN\\\File.dll";

        ObjectQuery Query = new ObjectQuery(string.Format("SELECT * FROM CIM_DataFile Where Drive='{0}' AND Path='{1}' ", Drive, Path));

        ManagementObjectSearcher Searcher = new ManagementObjectSearcher(scope, Query);

        foreach (ManagementObject WmiObject in Searcher.Get())
        {
            Console.WriteLine("{0}", (string)WmiObject["Name"]);// String
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 C# 获取和设置 DLL 文件的详细信息 - How to get and set DLL file details, using C# C# 中的 API 调用 - 使用用户名和密码获取调用 - API call in C# - Get call using username and password C# Active Directory - 用户名和密码不正确,但详细信息实际上是正确的 - C# Active Directory - Incorrect Username and Password but details are actually correct 如何从文本文件中验证用户名和密码? | Winforms C# - How to validate username and password from text file? | Winforms C# 如何在控制台中创建登录名,在控制台中我使用存储在文件C#中的用户名和密码进行身份验证 - How to create a login in console where I authenticate using an username and password stored in a file c# 如何使用文本文件检查密码是否与 c# 中的用户名匹配? - How to check if password matches username in c# using text files? 如何使用Cookie记住C#中的用户名和密码 - How to remember the username and password in c# using cookie 使用C#下载带密码和用户名的文件 - Download a file with password and username with C# 如何使用“ Interop.Domino.dll”(C#)获取Lotus Notes密码(在本地计算机上)? - How to get Lotus Notes Password (on local machine) using “Interop.Domino.dll” (C#)? 如何在C#中获取远程计算机中文件的数量 - how to get count of files in a remote machine in c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM