摘要:
完整问题:
我需要找到一种在csharp中运行命令行命令并捕获其输出的方法.我知道如何在Perl中执行此操作,下面是我将在Perl中使用的代码.
#machine to check
my $pc = $_[0];
#create location of registry query
my $machine = "\\\\".$pc."\\HKEY_USERS";
#run registry query
my @regQuery= `REG QUERY $machine`;
Run Code Online (Sandbox Code Playgroud)
有关如何在csharp中执行此操作的任何建议都将受到欢迎.到目前为止,我已经尝试使用RegistryKey OurKey = Registry.Users方法,它工作得很好但我无法在远程计算机上查询注册表.
如果您需要更多信息,请与我们联系.
解决方案:(谢谢@Robaticus)
private void reg(string host)
{
string build = "QUERY \\\\" + host + "\\HKEY_USERS";
string parms = @build;
string output = "";
string error = string.Empty;
ProcessStartInfo psi = new ProcessStartInfo("reg.exe", parms);
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
psi.UseShellExecute …
Run Code Online (Sandbox Code Playgroud) 我有点困在SSH私钥问题和LibGit2Sharp-Ssh.
我有一个.Net/C#应用程序,它使用LibGit2Sharp-Ssh来克隆Git存储库.
我需要使用SSH(https,用户/密码不是一个选项),我也有一个有效的密钥,已经在使用Teamcity.
我的代码看起来像这样:
CloneOptions options = new CloneOptions
{
Checkout = false,
CredentialsProvider = (url, user, cred) => new SshUserKeyCredentials()
{
PrivateKey = privateKey,
Passphrase = passphrase,
PublicKey = publicKey,
Username = "git"
}
};
var clone = LibGit2Sharp.Repository.Clone(remoteUrl, localPath, options);
Run Code Online (Sandbox Code Playgroud)
privateKey
指向"OpenSSH"格式的私钥文件.
什么时候Clone
执行我得到:
LibGit2Sharp.LibGit2SharpException: "Failed to authenticate SSH session: Invalid key data, not base64 encoded"
Run Code Online (Sandbox Code Playgroud)
我已经尝试了使用PuttyGen创建的所有私钥格式,但我总是得到相同的结果.
我可能需要创建私钥文件的问题或格式是什么?
我的OpenSSH格式键看起来像(截断的):
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,27A4E70608469318
<Key-Data, like "sdhsdcQEHBg3uzfb...">
-----END RSA PRIVATE KEY-----
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用DownloadFile
该类的方法System.Net.WebClient
从 GitHub 下载文件。我尝试.txt
从这里下载文件,结果是这样的。这显然是页面的 HTML 代码,而不是文件。尝试谷歌搜索一些解决方案,但没有一个有效。这是代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
namespace download_file_test
{
class Program
{
static void Main(string[] args)
{
using (WebClient wc = new WebClient())
{
wc.Headers.Add("a", "a");
try
{
wc.DownloadFile("https://github.com/github/platform-samples/blob/master/LICENSE.txt", @"C:/Users/User/Desktop/test/test.txt");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadKey();
Console.ReadLine();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)