Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
var wsh = new IWshShell_Class();
IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
    Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\shorcut2.lnk") as IWshRuntimeLibrary.IWshShortcut;
shortcut.TargetPath = @"C:\Users\Zimin\Desktop\test folder";            
shortcut.Save();

i want to create shortcut file of task scheduler using c#.
and also add TargetPath = C:\Windows\System32\schtasks.exe /RUN /TN myapplicaion .

What I have tried:

var wsh = new IWshShell_Class();
IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\shorcut2.lnk") as IWshRuntimeLibrary.IWshShortcut;
shortcut.TargetPath = @"C:\Users\Zimin\Desktop\test folder";
shortcut.Save();
Posted
Updated 7-Sep-16 23:22pm
v2
Comments
Karthik_Mahalingam 8-Sep-16 3:27am    
what is the issue?
OriginalGriff 8-Sep-16 3:40am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work from, with no context beyond that.
Use the "Improve question" widget to edit your question and provide better information.
Wastedtalent 8-Sep-16 5:00am    
Why would you need to? Windows doesn't distinguish between the 2 when it comes to shortcuts.
Member 10342650 8-Sep-16 5:10am    
i want to create shortcut file of task scheduler using c#.
and also add TargetPath = C:\Windows\System32\schtasks.exe /RUN /TN myapplicaion .
Karthik_Mahalingam 9-Sep-16 1:26am    
this should work

1 solution

Just type the forward slash in your code "/" and it will accept it.
e.g.

string myString = @"C:\Windows\System32\schtasks.exe /RUN /TN myapplication";
 
Share this answer
 
Comments
Member 10342650 8-Sep-16 5:39am    
hello sir that code not working ..
njammy 8-Sep-16 5:40am    
Elaborate
Member 10342650 19-Sep-16 3:00am    
i added @"C:\Windows\System32\schtasks.exe /RUN /TN myapplication" in shortcut.TargetPath
but automatically manage C:\Windows\System32\schtasks.exe \RUN \TN myapplication
njammy 19-Sep-16 5:40am    
what?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900