2017-03-16 68 views
1

我在Visual C#中使用DOTRAS庫創建了一個代碼,該程序在網絡連接中創建pppoe撥號程序。但我無法弄清楚如何在桌面上創建撥號程序快捷方式。我一般知道如何在c#中創建應用程序快捷方式,但無法獲取網絡連接快捷方式代碼。任何建議都是可觀的。C#howto在桌面上創建網絡撥號程序快捷方式

回答

1

這是最好的,我知道:

string destDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); 
string destFileName = @"Connect To Example.lnk"; 

// Create .lnk file 
string path = System.IO.Path.Combine(destDir, destFileName); 
FileStream fs = File.Create(path); 
fs.Close(); 

// Instantiate a ShellLinkObject that references the .lnk we created 
Shell32.Shell shell = new Shell32.Shell(); 
Shell32.Folder shellFolder = shell.NameSpace(destDir); 
Shell32.FolderItem shellFolderItem = shellFolder.Items().Item(destFileName); 
Shell32.ShellLinkObject shellLinkObject = (Shell32.ShellLinkObject)shellFolderItem.GetLink; 

// Set .lnk properties 
shellLinkObject.Arguments = "-d Example"; 
shellLinkObject.Description = "Example Connection"; 
shellLinkObject.Path = @"%windir%\System32\rasphone.exe"; 
shellLinkObject.WorkingDirectory = "%windir%"; 

shellLinkObject.Save(path); 

替換 「示例」 與您的連接名稱

+0

GR8。 使用一些mods,它工作正常,現在在當前用戶的桌面上創建撥號程序快捷方式。如何爲此桌面快捷方式添加任何ICON? 我也有用戶名密碼文本框在我的應用程序撥號連接。是否有任何方式,如果用戶在框中輸入用戶名密碼,他們應該保存到註冊表中,下次應用程序加載時,它應該從註冊表中獲得ID傳遞? –

+0

我不在我的電腦上。使用SetIconLocation – Dorad

+0

好的,在我的C#WPF中,我撥號撥號特定的PPPoE撥號程序,如何添加檢查此撥號程序是否已連接,如果是,則顯示已連接的消息,否則繼續連接它? –

相關問題