我有一个C#控制台程序,它启动计算器并模拟按键.我如何以编程方式按Enter?
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName,
string lpWindowName);
// Activate an application window.
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
// Send a series of key presses to the Calculator application.
private void StartCalculator()
{
Process.Start("calc.exe");
IntPtr calculatorHandle = FindWindow("CalcFrame","Calculator");
if (calculatorHandle == IntPtr.Zero)
{
return;
}
SetForegroundWindow(calculatorHandle);
SendKeys.SendWait("111");
SendKeys.SendWait("*");
SendKeys.SendWait("11");
SendKeys.SendWait("=");
SendKeys.SendWait(" ");//how press enter?
}
Run Code Online (Sandbox Code Playgroud) 我有本地 tfs 2012。在 Visual Studio 2012 上,使用 c#,我编写了以编程方式连接到 tfs 服务器的程序。但我有错误:
{"TF30063: 您无权访问http://server:8080/tfs。"} System.Exception {Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException}
我的代码:
Uri collectionUri = new Uri("http://server:8080/tfs");
NetworkCredential netCred = new NetworkCredential("login","password");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;
TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(collectionUri, netCred);
teamProjectCollection.EnsureAuthenticated();//throw error here
Run Code Online (Sandbox Code Playgroud)
你能帮我解决这个错误吗?
PS我尝试以这种方式连接,但我有同样的错误:
var projectCollection = new TfsTeamProjectCollection(
new Uri("http://myserver:8080/tfs/DefaultCollection"),
new NetworkCredential("youruser", "yourpassword"));
projectCollection.Connect(ConnectOptions.IncludeServices);
Run Code Online (Sandbox Code Playgroud)
这样:
Uri collectionUri = new Uri("http://server:8080/tfs/DefaultCollection");
NetworkCredential netCred = new NetworkCredential("login","password","Server.local");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred …
Run Code Online (Sandbox Code Playgroud)