我一直在谷歌和stackoverflow搜索2小时.必须有一些我只是俯瞰.有没有一种简单的方法可以在消息框中选择文本?就在我现在调用MessageBox.Show()时,我无法复制显示的文本.为什么不?我如何设置文本可复制?
我的代码:
//catch all exceptions
catch (Exception ex)
{
MessageBox.Show(ex.Message);
//throw;
}
Run Code Online (Sandbox Code Playgroud)
我希望能够选择出现的错误消息,以便用户将其发送给我,我可以解决他们的问题.任何帮助是极大的赞赏.
编辑:不能使用crtl-c方法.我的用户无法掌握这个概念.需要用鼠标突出显示并右键单击以选择选项.谢谢!
编辑:作为参考我最终做的是使用答案的混合.我创建了一个带有单个按钮的弹出窗口,并在按钮操作后复制到剪贴板.它不完美,但有正确的标签,它现在运作良好.谢谢大家的建议!
//catch all exceptions
catch (Exception ex)
{
//MessageBox.Show(ex.Message);
MessageBoxButtons buttons = MessageBoxButtons.OK;
DialogResult result;
// Displays the MessageBox.
result = MessageBox.Show(ex.Message + "\n\nClick OK button to copy to clipboard", "Error", buttons);
if (result == System.Windows.Forms.DialogResult.OK)
{
Clipboard.SetText(ex.Message);
//throw;
}
}
Run Code Online (Sandbox Code Playgroud) 我一直在寻找一段时间来弄清楚如何确认字符串以数字开头.我遇到了一个正则表达式'/ ^\d /',我可以确认如果以数字开头.但是我似乎无法在下面的代码中使用它.我在声明中哪里出错了if(Regex.Match(info,"/^\d/"))?
//String attachbody is the attachment body from an email C read into a string
string[] data = Regex.Split(attachbody, "\n");
foreach (String info in data)
{
if (Regex.Match(info,"/^\d/"))
{
string[] tabbedHeaderData = Regex.Split(info, "\t");
TicketID = tabbedHeaderData[0].ToString();
Status = tabbedHeaderData[1].ToString();
URL = tabbedHeaderData[2].ToString();
InitCats = tabbedHeaderData[3].ToString();
PostRevCats = tabbedHeaderData[4].ToString();
ListNumClosed = tabbedHeaderData[5].ToString();
Console.WriteLine(TicketID);
Console.WriteLine(Status);
Console.WriteLine(URL);
Console.WriteLine(InitCats);
Console.WriteLine(PostRevCats);
Console.WriteLine(ListNumClosed);
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)
示例数据(制表符分隔):
TicketID状态URL InitCats PostRevCats ListNumClosed 555555已关闭 http://5555555.com/searcho 恶意站点55555
目标
我想按下GUI上的按钮并从远程计算机读取seclog.log文件(symantec AV日志),并将日志内容显示在我的应用程序中的富文本框中.
有用的东西
一切,但阅读日志文件
错误信息
System.IO.IOException was unhandled
Message=The process cannot access the file '\\HOSTNAME\C$\Program Files (x86)\Symantec\Symantec Endpoint Protection\seclog.log' because it is being used by another process.
Source=mscorlib
Run Code Online (Sandbox Code Playgroud)
码
//possible seclog paths
String seclogPath1 = @"\\\\" + target + "\\C$\\Program Files (x86)\\Symantec\\Symantec Endpoint Protection\\seclog.log";
String seclogPath2 = @"\\\\" + target + "\\C$\\Program Files\\Symantec\\Symantec Endpoint Protection\\seclog.log";
//if seclog exists
if (File.Exists(seclogPath1))
{
//output.AppendText("file exists at " + seclogPath1);
//var seclogContent = File.Open(seclogPath1, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
Stream stream = File.OpenRead(seclogPath1);
StreamReader …Run Code Online (Sandbox Code Playgroud) 摘要:
完整问题:
我需要找到一种在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) 问题:
无法找到一种一致的方法来替换具有我想要的特定字符串的引号之间的随机字符串.任何帮助将不胜感激.
例:
String str1 = "test=\"-1\"";
Run Code Online (Sandbox Code Playgroud)
应该成为
String str2 = "test=\"31\"";
Run Code Online (Sandbox Code Playgroud)
但也为之努力
String str3 = "test=\"foobar\"";
Run Code Online (Sandbox Code Playgroud)
基本上我想转此
String str4 = "test=\"antyhingCanGoHere\"";
Run Code Online (Sandbox Code Playgroud)
进入这个
String str4 = "test=\"31\"";
Run Code Online (Sandbox Code Playgroud)
试过:
不使用RegexOptions枚举的不区分大小写的正则表达式
使用Regex将空字符串替换为AnyText:和<usernameredacted@example.com>之间的任何字符?
当前代码:
Regex RemoveName = new Regex("(?VARIABLE=\").*(?=\")", RegexOptions.IgnoreCase);
String convertSeccons = RemoveName.Replace(ruleFixed, "31");
Run Code Online (Sandbox Code Playgroud)
返回错误:
System.ArgumentException was caught
Message=parsing "(?VARIABLE=").*(?=")" - Unrecognized grouping construct.
Source=System
StackTrace:
at System.Text.RegularExpressions.RegexParser.ScanGroupOpen()
at System.Text.RegularExpressions.RegexParser.ScanRegex()
at System.Text.RegularExpressions.RegexParser.Parse(String re, RegexOptions op)
at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, Boolean useCache)
at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options)
at application.application.insertGroupID(String …Run Code Online (Sandbox Code Playgroud) 我需要在Ruby脚本中执行Bash命令.根据Nate Murray和其他一些谷歌来源的"6种方式在Ruby中运行Shell命令",大约有6种方法可以做到这一点.
print "enter myid: "
myID = gets
myID = myID.downcase
myID = myID.chomp
print "enter host: "
host = gets
host = host.downcase
host = host.chomp
print "winexe to host: ",host,"\n"
command = "winexe -U domain\\\\",ID," //",host," \"cmd\""
exec command
Run Code Online (Sandbox Code Playgroud) 摘要
我需要能够找到注册表项的DWORD值并为其设置一个变量以对其运行if语句.
我怎样才能抓住一个reg查询的双关语,以便我可以在其余的脚本中使用它?
reg查询
reg query HKLM\System\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile /v EnableFirewall
Run Code Online (Sandbox Code Playgroud)
req查询输出
EnableFirewall REG_DWORD 0x1
Run Code Online (Sandbox Code Playgroud)
我需要抓住什么
0x1
伪代码
query firewall reg value
regex out DWORD value and set to variable var1
if var1 == 0x1 then do blah
else do other blah
Run Code Online (Sandbox Code Playgroud) 我正在运行Visual Studio 2010.我只是将项目的框架工作从4.0更改为3.5.我删除了它要求我删除然后尝试编译的参考Microsoft.Framework.我现在得到错误:
错误1无法加载文件或程序集'System.Drawing,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.该系统找不到指定的文件.第123行,第5位.C:\ Users \\ Documents\Visual Studio 2010\Projects \\\ Properties\Resources.resx 123 5
我知道它指的是我的resources.resx文件中的代码:
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="pix-300x300" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\pix-300x300.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="pix2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\pix2.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="pix4" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\pix4.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="pix3" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\pix3.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, …Run Code Online (Sandbox Code Playgroud) 任何人都知道一个很好的方法来找出我的代码中有额外的#region或#endregion的位置?我有大约5000行c#代码,我现在正尝试手动执行.任何帮助表示赞赏.
我正在尝试将此 ssh 命令转换为我的 ssh_config。ssh_config 中 -L 的等效项是什么?我以为它是 localForward 但从我得到的结果来看它看起来并不是那样。
SSH命令
sudo ssh -i ~/.ssh/mySSHkey -L 81:<IP1>:81 -L 9200:<IP1>:9200 user@myhost.domain.com
Run Code Online (Sandbox Code Playgroud)
ssh_config 条目
Host logstash
Hostname <IP1>
Port 81
# ForwardX11 yes
LocalForward 81 <IP1>:81
LocalForward 9200 <IP1>:9200
User username
IdentityFile ~/.ssh/mySSHkey
ServerAliveInterval 30
ServerAliveCountMax 120
# LogLevel DEBUG3
Run Code Online (Sandbox Code Playgroud) c# ×7
regex ×3
.net ×2
command ×2
registry ×2
string ×2
bash ×1
batch-file ×1
capture ×1
compilation ×1
digits ×1
dword ×1
file ×1
frameworks ×1
linux ×1
messagebox ×1
noncopyable ×1
region ×1
replace ×1
ruby ×1
ssh ×1
ssh-keys ×1
text ×1
windows ×1