小编pur*_*ang的帖子

以管理员身份运行cmd和命令?

这是我的代码:

try
{
    ProcessStartInfo procStartInfo = new ProcessStartInfo(
                                            "cmd.exe", 
                                            "/c " + command);
    procStartInfo.UseShellExecute = true;
    procStartInfo.CreateNoWindow = true;
    procStartInfo.Verb = "runas";
    procStartInfo.Arguments = "/env /user:" + "Administrator" + " cmd" + command;

    ///command contains the command to be executed in cmd
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.StartInfo = procStartInfo;
    proc.Start();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
Run Code Online (Sandbox Code Playgroud)

我想保留

procStartInfo.UseShellExecute = true 
procStartInfo.RedirectStandardInput = false;
Run Code Online (Sandbox Code Playgroud)

是否可以在不使用的情况下执行命令process.standardinput?我尝试执行命令我已经传入参数,但命令没有执行.

.net c# privileges command-line process

8
推荐指数
2
解决办法
4万
查看次数

如何获得特定商店的证书CN?

我想获取存储在MY商店中的证书的CN,因为我想验证商店是否存在证书.

我不知道应该使用哪种方法来执行此任务.

我尝试使用下面的代码,但它不起作用

X509Certificate2Collection cers =  store.Certificates.Find(X509FindType.FindBySubjectName,"Root_Certificate",false);

if(cers.Count>0)
{

//certificate present

}

else
{

//certificate not present

}
Run Code Online (Sandbox Code Playgroud)

subjectName是否给CN

还有其他方法吗?

请建议我如何检查特定证书是否存在,我想用CN来做.

.net c# ssl ssl-certificate x509certificate

6
推荐指数
1
解决办法
1万
查看次数

如何将流写入内存流?

public void doprocess(TcpClient client)
{    
    MemoryStream ms = new MemoryStream();

    Stream clStream = client.GetStream();

    byte[] buffer_1 = new byte[8192];

    int count = clStream.Read(buffer_1, 0, buffer_1.Length);

    while (count > 0)
    {
        ms.Write(buffer_1, 0, count);

        //the below line doesn't gives response and code hangs here 
        count = clStream.Read(buffer_1, 0, buffer_1.Length);         
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有其他方法可以将一个流写入另一个流?我想用Stream两次,这就是为什么我需要把它写到MemoryStream.

.net c#

3
推荐指数
1
解决办法
1911
查看次数

如何以正确的字符串形式获取httpWebresponse的内容?

有时我会从几个网站得到一些乱码回复.

这是我的代码:

Stream responseStream = response.GetResponseStream();
buffer = new Byte[256];//
int bytesRead;
while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
{
   outStream.Write(buffer, 0, bytesRead);
   //resp=resp+ .UTF8.GetString(buffer, 0, bytesRead);
   resp=resp + Encoding.ASCII.GetString(buffer); //resp is string
}
Run Code Online (Sandbox Code Playgroud)

当我从www.google.co.in请求时,我在resp字符串中得到以下字符:

?\ B\0\0\0\0\0ερ}ÿ·F ?????????Ž?????? {7米??? OX吗?\ r?ÿ??? 33 ?? d; Y ???? N 0?

我该如何克服这个问题?它与编码有关吗?

c# character-encoding httpwebresponse responsestream

0
推荐指数
1
解决办法
2万
查看次数