C# 如何在桌面上创建网络拨号程序快捷方式
C# howto Create Network Dialer shortcut on desktop
我使用 DOTRAS 库在 Visual C# 中创建了一个代码,它在网络连接中创建了 pppoe 拨号程序。但我无法弄清楚如何在桌面上创建拨号程序快捷方式。我通常知道如何在 C# 中创建应用程序快捷方式,但无法获取网络连接快捷方式代码。如有任何建议,我们将不胜感激。
这是我所知道的最好的:
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);
将 "Example" 替换为您的连接名称
我使用 DOTRAS 库在 Visual C# 中创建了一个代码,它在网络连接中创建了 pppoe 拨号程序。但我无法弄清楚如何在桌面上创建拨号程序快捷方式。我通常知道如何在 C# 中创建应用程序快捷方式,但无法获取网络连接快捷方式代码。如有任何建议,我们将不胜感激。
这是我所知道的最好的:
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);
将 "Example" 替换为您的连接名称