2013-04-29 47 views
0

我想運行一個網頁,當用戶登錄到他們的用戶帳戶..。在我的C#應用​​程序..如何在Windows登錄時打開網頁?

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

那麼,什麼問題?你能詳細說一下嗎? – Dietz 2013-04-29 06:15:57

+0

@ChristianDietz有沒有問題我wana轉到www.google.ca當用戶登錄到Windows ... – IceDawg 2013-04-29 06:20:59

回答

1

您可以創建一個批處理文件,並安排其運行時,每次用戶登錄

該批處理文件將只有一行。

start <url> 

例如

start http://www.google.ca 

這個腳本會在用戶的默認Web瀏覽器打開<網址>。

+0

theghostofc:所以我只是讓.bat文件,並把它放在啓動文件夾? – IceDawg 2013-04-29 16:55:06

+0

@ user2309648,您可以**將其安排爲任務,並在用戶每次登錄時運行它** - 這是您打算執行的操作,對吧?請記住**採取適當的安全措施,以避免此批處理文件被任何惡意軟件或病毒誤用以危及您的系統**。 – 2013-04-30 06:27:50

+0

我該怎麼辦?隱藏文件? – IceDawg 2013-04-30 14:45:07

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

卡爾上述funaction如下:

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

我不知道我明白了一切。但是,這裏有一個代碼示例,一旦用戶登錄,將打開存儲在應用程序中的(*。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"); 
} 
相關問題