C#howto在桌面上创建网络拨号器快捷方式

时间:2017-03-16 06:32:14

标签: c# visual-studio pppoe

我使用DOTRAS库在Visual C#中创建了一个代码,它在网络连接中创建了pppoe拨号程序。但我无法弄清楚如何在桌面上创建拨号器快捷方式。我一般都知道如何在c#中创建应用程序快捷方式但无法获取网络连接快捷方式代码。任何建议都会很明显。

1 个答案:

答案 0 :(得分: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);

替换"示例"使用您的连接名称