I have created a code in Visual C# using DOTRAS library, which creates pppoe dialer in network connection. But I am unable to figure out how to create the dialer shortcut on the desktop. I know in general howto create application shortcut in c# but unable to get the network connection shortcut code. Any suggestions would be appreciable.
Asked
Active
Viewed 236 times
1 Answers
1
This is the best i know:
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);
Replace "Example" with your connection name

Dorad
- 3,413
- 2
- 44
- 71
-
Gr8. With some mods, it works fine and the dialer shortcut is now created on Desktop of current user. How can I add any ICON for this Desktop Shortcut? I have also username password textbox in my application which dials the connection. is there any way if user enters username password in boxes, they should be saved to registry, and next time when the app load, it should get id pass from the registry? – Syed Jahanzaib Mar 19 '17 at 08:14
-
I am not on my pc. Use SetIconLocation – Dorad Mar 19 '17 at 08:30
-
ok , In my C# WPF, i have dial button which dials specific pppoe dialer, How can i add check if this dialer is already connected , if yes then show message already connected, otherwise proceed connect it? – Syed Jahanzaib Mar 19 '17 at 09:58
-
It's sound like a new question. Open a new one. Tell me if you havn't got a answer. I am still not on my computer. – Dorad Mar 19 '17 at 12:01
-
network connection shortcut is working with your provided code. I have accepted it as answer. thank you for your time :) just wanted to add dialer already connected check. – Syed Jahanzaib Mar 19 '17 at 14:17
-
http://stackoverflow.com/questions/42887851/c-sharp-dotras-check-if-dialer-is-already-connected – Syed Jahanzaib Mar 19 '17 at 14:40
-
You said you use DotRas. Have you tried: RasConnection.GetActiveConnections() Or RasDialer instance's DialCompleted Event? – Dorad Mar 19 '17 at 20:01