简体   繁体   English

如何在Windows登录时打开网页?

[英]How to open a webpage on windows logon?

I want to run a webpage when a user logs onto their user account.. . 我想在用户登录其用户帐户时运行一个网页。 in my C# App.. 在我的C#应用​​中

string startup = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

You may create a batch file and schedule it to run every time when user logs in . 您可以创建一个批处理文件并将其安排为在用户登录时每次运行

The batch file will have only one line. 批处理文件将只有一行。

start <url>

eg 例如

start http://www.google.ca

This script would open the <url> in user's default web browser . 该脚本将在用户的默认Web浏览器中打开<url>。

private void CreateUrlShortcut(string linkName, string linkUrl)
{
    string dir = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

    using (StreamWriter writer = new StreamWriter(dir + "\\" + linkName + ".url"))
    {
        writer.WriteLine("[InternetShortcut]");
        writer.WriteLine("URL=" + linkUrl);
        writer.Flush();
    }
}

Cal the above funaction as follows: 校准上述功能如下:

CreateUrlShortcut("google link", "http://www.google.ca/");

I'm not sure I understood everything. 我不确定我是否了解一切。 But here's an example of code that opens (*. Html) web page stored in your application once the user logged. 但是,这是一个示例代码,一旦用户登录,该代码就会打开存储在应用程序中的(* .HTML)网页。

bool isLoged = //...
//Get the absolute path of the application
DirectoryInfo myPathWork = new DirectoryInfo(Environment.CurrentDirectory);
//if the use is loged
if(isLoged)
{
   //Open web page stored in the directory of the application with the default web browser.
   Process.Start(myPathWork.FullName+"myWebPage.html");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM