C# 不经过下一步就可以安装应用程序吗?
这个问题不言自明,但。。 我想创建一个程序,当我执行它时,它将下载一些文件,然后安装它们,例如chrome。但是我如何才能通过下一阶段的安装呢?我使用的是C语言或Java语言。我现在有一些代码可以下载这个文件,但是没有:S 我希望它最终做什么: 1) 下载-安装Chrome 2) 输入gmail acc(proly java scrip?) 3) 其余的可能是类似的C# 不经过下一步就可以安装应用程序吗?,c#,performance,file,download,installation,C#,Performance,File,Download,Installation,这个问题不言自明,但。。 我想创建一个程序,当我执行它时,它将下载一些文件,然后安装它们,例如chrome。但是我如何才能通过下一阶段的安装呢?我使用的是C语言或Java语言。我现在有一些代码可以下载这个文件,但是没有:S 我希望它最终做什么: 1) 下载-安装Chrome 2) 输入gmail acc(proly java scrip?) 3) 其余的可能是类似的 private void Download() { WebClient webClient
private void Download()
{
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows; Windows NT 5.1; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4");
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileAsync(new Uri("http://dl.google.com/update2/installers/ChromeSetup.exe"), Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
}
我不知道下载页面是否会因为客户端标题或其他内容而阻止我。。
谢谢大家 使用pinvoke,您可以通过SendKey函数向设置窗口处理程序发送快捷方式
[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
static extern bool PostMessage(
IntPtr hWnd,
uint msg,
int wParam,
int lParam
);
const uint WM_KEYDOWN = 0x100;
const int WM_a = 0x41;
const int WM_b = 0x42;
const int WM_c = 0x43;
static void Main(string[] args)
{
//using Process.GetProcessesByName to get the handle we want
Process[] p = Process.GetProcessesByName("notepad");
IntPtr pHandle = p[0].MainWindowHandle;
//will write "abc" in the open Notepad window
PostMessage(pHandle, WM_KEYDOWN, WM_a, 0);
PostMessage(pHandle, WM_KEYDOWN, WM_b, 0);
PostMessage(pHandle, WM_KEYDOWN, WM_c, 0);
}
下面是来自的示例代码。它使用函数
[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
static extern bool PostMessage(
IntPtr hWnd,
uint msg,
int wParam,
int lParam
);
const uint WM_KEYDOWN = 0x100;
const int WM_a = 0x41;
const int WM_b = 0x42;
const int WM_c = 0x43;
static void Main(string[] args)
{
//using Process.GetProcessesByName to get the handle we want
Process[] p = Process.GetProcessesByName("notepad");
IntPtr pHandle = p[0].MainWindowHandle;
//will write "abc" in the open Notepad window
PostMessage(pHandle, WM_KEYDOWN, WM_a, 0);
PostMessage(pHandle, WM_KEYDOWN, WM_b, 0);
PostMessage(pHandle, WM_KEYDOWN, WM_c, 0);
}