C# 这些行向我抛出编译时错误,表示无法识别转义序列。这可能是由于反斜杠造成的,您可以尝试使用要传递的命令的原始格式,而不是使用“@”方法。@user3655102更新了我的答案,以便正确使用反斜杠,因此避免了这个问题。我尝试了,但命令没有得到正确执行:(但当我

C# 这些行向我抛出编译时错误,表示无法识别转义序列。这可能是由于反斜杠造成的,您可以尝试使用要传递的命令的原始格式,而不是使用“@”方法。@user3655102更新了我的答案,以便正确使用反斜杠,因此避免了这个问题。我尝试了,但命令没有得到正确执行:(但当我,c#,command-line,C#,Command Line,这些行向我抛出编译时错误,表示无法识别转义序列。这可能是由于反斜杠造成的,您可以尝试使用要传递的命令的原始格式,而不是使用“@”方法。@user3655102更新了我的答案,以便正确使用反斜杠,因此避免了这个问题。我尝试了,但命令没有得到正确执行:(但当我将这些命令放入批处理文件中时,它们的工作方式类似于charm.p.Start();p.StandardInput.WriteLine(@“cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319”);


这些行向我抛出编译时错误,表示无法识别转义序列。这可能是由于反斜杠造成的,您可以尝试使用要传递的命令的原始格式,而不是使用“@”方法。@user3655102更新了我的答案,以便正确使用反斜杠,因此避免了这个问题。我尝试了,但命令没有得到正确执行:(但当我将这些命令放入批处理文件中时,它们的工作方式类似于charm.p.Start();p.StandardInput.WriteLine(@“cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319”);p.StandardInput.WriteLine(“aspnet\u regiis-pi\”CustomKeys2\“\”C:\\Users\\cnandy\\Desktop\\Encryption\u keys\\CustomEncryptionKeys.xml\);……有什么可以做的吗?@user3655102我认为最有可能的是命令的格式可能,我个人无法尝试您的命令,但我知道第二种方法中的代码的其他部分可以很好地工作,不包括使用的命令。下面是我自己使用的示例:
 Process cmdprocess = new Process();
        ProcessStartInfo startinfo = new ProcessStartInfo();
        Environment.SetEnvironmentVariable("filename", FileName);
        startinfo.FileName = @"C:\Users\cnandy\Desktop\St\2nd Sep\New_CN\New folder\Encrypt web.config_RSAWebFarm\Decrypt Connection String.bat";

        startinfo.WindowStyle = ProcessWindowStyle.Hidden;
        startinfo.CreateNoWindow = true;
        startinfo.RedirectStandardInput = true;
        startinfo.RedirectStandardOutput = true;
        startinfo.UseShellExecute = false;
        cmdprocess.StartInfo = startinfo;
        cmdprocess.Start();
cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319

aspnet_regiis -pi "CustomKeys2" "C:\Users\cnandy\Desktop\Encryption_keys\CustomEncryptionKeys.xml"

aspnet_regiis -pa "CustomKeys2" "NT AUTHORITY\NETWORK SERVICE"

aspnet_regiis -pdf "connectionStrings" %filename%
"C:\Users\cnandy\Desktop\Test\Websites\AccountDeduplicationWeb"
Process p = new Process()  
{
    StartInfo = new ProcessStartInfo("cmd.exe")
    {
       RedirectStandardInput = true,
       RedirectStandardOutput = true,
       UseShellExecute = false,
       CreateNoWindow = true
    }
};

p.Start();

using (StreamWriter sw = p.StandardInput)
{
    sw.WriteLine("First command here");
    sw.WriteLine("Second command here");
}

p.StandardInput.WriteLine("exit");
string strEntry = ""; // Let the user assign to this string, for example like "C:\Users\cnandy\Desktop\Test\Websites\AccountDeduplicationWeb"

Process p = new Process()  
{
    StartInfo = new ProcessStartInfo("cmd.exe")
    {
       RedirectStandardInput = true,
       RedirectStandardOutput = true,
       UseShellExecute = false,
       CreateNoWindow = true
    }
};

p.Start();

p.StandardInput.WriteLine("cd C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319");
p.StandardInput.WriteLine("aspnet_regiis -pi \"CustomKeys2\" \"C:\\Users\\cnandy\\Desktop\\Encryption_keys\\CustomEncryptionKeys.xml\"");
p.StandardInput.WriteLine("aspnet_regiis -pa \"CustomKeys2\" \"NT AUTHORITY\\NETWORK SERVICE\"");
p.StandardInput.WriteLine("aspnet_regiis -pdf \"connectionStrings\" " +  strEntry);

p.StandardInput.WriteLine("exit"); //or even p.Close();
Environment.SetEnvironmentVariable("searchString","*.txt")
dir %searchString%
System.Diagnostics.Process.Start("path\commands.bat");
System.Environment.SetEnvironmentVariable("fileName", "test.txt");
System.Diagnostics.Process.Start(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/commands.bat");
Console.ReadLine();
@echo "staring note pad"
notepad %fileName%
 CallYourBatch.bat "MyFileName"
SET fileName=%~1
aspnet_regiis -pdf "connectionStrings" %fileName%