是否可以安装应用程序而无需进行下一步?

时间:2012-03-07 00:23:19

标签: c# performance file download install

这个问题非常自我解释但是...... 我想创建一个程序,当我执行它时,它将下载一些文件,然后安装它们,例如chrome。但是,我将如何通过下一阶段的安装?我使用的是C sharp或Java。我现在有一些代码来下载不存在的文件:S

我最终想要它做什么: 1)下载 - 安装Chrome 2)输入gmail acc(proly java scrip?) 3)其余的可能类似。

        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));
    }

我不知道下载页面是否阻止了客户端标头或其他任何内容。 先谢谢你!

1 个答案:

答案 0 :(得分:1)

使用pinvoke,您可以通过SendKey函数向设置窗口处理程序发送快捷方式。

以下是codeguru的示例代码。它使用PostMessage函数。

[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);
    }
相关问题