小编Mik*_*uno的帖子

检查 Active Directory 域控制器是否已启动并运行的 C# 方法

我想增强我正在编写的 C# 程序,以便在其中一个或多个离线时它可以利用全局目录 DC 列表中的任何一个。我想编写一个方法,根据 ADDS 是否在目标服务器上运行(而不仅仅是服务器是否可 ping 通)来返回 bool 值:

public bool DC_is_Alive(string DomainControllerFQDN) 
{
...
}
Run Code Online (Sandbox Code Playgroud)

c# active-directory

5
推荐指数
1
解决办法
4766
查看次数

让RichTextBox在添加内容时自动滚动到底部

我有一个 WPF 用户控件,其中包含BindableRichTextBox

xmlns:controls="clr-namespace:SysadminsLV.WPF.OfficeTheme.Controls;assembly=Wpf.OfficeTheme"
.
.
.
<controls:BindableRichTextBox Background="Black"
                              Foreground="White"
                              FontFamily="Consolas"
                              FontSize="12"
                              IsReadOnly="True"
                              IsReadOnlyCaretVisible="True"
                              VerticalScrollBarVisibility="Auto"
                              IsUndoEnabled="False"
                              Document="{Binding Contents}"/>
Run Code Online (Sandbox Code Playgroud)

内容由 ViewModel 属性控制Document

using System.Windows.Documents;

class MyViewModel : ILogServerContract 
{
    readonly Paragraph _paragraph;

    public MyViewModel() 
    {
        _paragraph = new Paragraph();
        Contents = new FlowDocument(_paragraph);
    }

    public FlowDocument Contents { get; }

    //Log Server Contract Write method (accessed via NetPipe)
    public void WriteLine(string text, int debugLevel) 
    {
        //figure out formatting stuff based on debug level. not important
        _paragraph.Inlines.Add(new Run(text) …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

5
推荐指数
1
解决办法
433
查看次数

Powershell - 从远程机器上运行 exe 的 Invoke-Command 捕获输出

我需要在一组远程服务器上配置审计策略。我正在尝试使用 Invoke-Command commandlet 在每台服务器上运行 auditpol.exe。问题是我似乎无法从 auditpol 命令中捕获任何输出。

我尝试了显而易见的(将 Invoke-Command 的结果分配给一个字符串):

> $command =  "Start-Process -FilePath `"auditpol.exe`" -ArgumentList `"/set`", `"/subcategory`", `"```"File System```"`", `"/success:enable`""
> $command
"auditpol.exe" -ArgumentList "/set", "/subcategory", "`"File System`"", "/success:enable"

> $out = Invoke-Command -ComputerName MyServer -ScriptBlock {$command}
> $out
>
Run Code Online (Sandbox Code Playgroud)

但是 $out 是空的。

我还使用 Wait-Job 和 Receive-Job尝试了此 MSDN 博客中详述的方法。结果有些令人鼓舞,但尚无定论:

> $command =  "Start-Process -FilePath `"auditpol.exe`" -ArgumentList `"/set`", `"/subcategory`", `"```"File System```"`", `"/success:enable`""
> $command
"auditpol.exe" -ArgumentList "/set", "/subcategory", "`"File System`"", "/success:enable"
> $job = Invoke-Command -ComputerName MyServer …
Run Code Online (Sandbox Code Playgroud)

powershell invoke-command

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

BouncyCastle - 将 X509CrlEntry.SerialNumber 转换为“CAPI 样式”十六进制字符串

我正在尝试使用 Org.BouncyCastle.X509 转储证书吊销列表(CRL)的内容。在此用例中,我需要获取“十六进制”字符串表示形式的证书序列号列表,正如它们出现在证书 MMC 管理单元中一样(示例值为16a03c2c000000000594)。

\n\n

我能够达到这样的程度:我有一个 X509CRLEntry 对象的集合可供迭代,但SerialNumber属性的类型为Org.BouncyCastle.Math.BigInteger这种类型有一个ToString()的实现,但是,返回的值对我来说不可用:

\n\n
public CRLProc(string CRLFile)\n        {\n            X509CrlParser Parser = new X509CrlParser();\n            X509Crl CRL = Parser.ReadCrl(File.ReadAllBytes(CRLFile));\n            NextUpdate = CRL.NextUpdate.Value;\n            var RevokedCerts = CRL.GetRevokedCertificates();\n\n            foreach(X509CrlEntry entry in RevokedCerts)\n            {\n                //Target value (first SN in CRL): 16a03c2c000000000594\n\n                string serialNumber = entry.SerialNumber.ToString();\n                //serialNumber = "106847877515466973906324" (Nope)\n\n                string serialFromBytes = Encoding.Default.GetString(entry.SerialNumber.ToByteArray());\n                //serialFromBytes = "\\u0016\xc2\xa0<,\\0\\0\\0\\0\\u0005\xe2\x80\x9d" (That\'s a hard NO)\n\n                string serialFromBigInt = entry.SerialNumber.LongValue.ToString("X");\n                //serialFromBigInt = "3C2C000000000594" (OK, now we\'re getting …
Run Code Online (Sandbox Code Playgroud)

c# bouncycastle

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

C# - 在 x 分钟后自动关闭表单

情况:我编写了一个用户通过 RDP 访问的 WinForms 应用程序。应用程序的性质是两个用户不能同时运行该应用程序。我们遇到的问题是人们会忘记关闭应用程序,基本上将其他用户锁定在外面。

我想要做的是添加功能以在 x 分钟后自动关闭应用程序。我意识到我需要为此使用线程,因为在主线程中标记时间会冻结应用程序。我没有检测活动/不活动的关键需求,但如果这很简单,我肯定想知道。

在此先感谢您的帮助!

c# multithreading

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