Click here to Skip to main content
15,885,925 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi There....
I am working on visual studio 2005 with c#, i am newbie actually,
I have created an application which create shortcut of an bat file(startup.bat) on the desktop which actually starts tomcat server.and it create successfully, but that shortcut is not working. if i go physically to that batch file and create shortcut from there(rightclick>Sendto>Desktop),and run it, then it executed successfully.
Pls Pls help me out from this, why this batch file is not running or do i have any other procedure to make shortcut of this batch file that run? Sorry for my english :-)
below are the code snipet that i used-

strDesktopPathForStartApache = @"C:\Documents and Settings\All Users\Desktop\DR_Start.lnk";
strForStartApache = @"C:\Program Files\DataRocket Installer\Apache Tomcat Server\bin\startup.bat";

CreateShortcut("Start Apache Tomcat Server", strDesktopPathForStartApache, strForStartApache);


C#
private static void CreateShortcut(string Description,string DesktopPath,string srcTarget)
        {
            try
            {
                WshShell = new WshShellClass();
                IWshRuntimeLibrary.IWshShortcut MyShortcut;
                MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(DesktopPath);
                MyShortcut.TargetPath = srcTarget;
                MyShortcut.Description = Description;
                MyShortcut.Save();
               
            }
            catch { }
        }





Thanx in advance

Regards,
Peter
Posted
Updated 28-Jan-11 17:45pm
v2
Comments
Richard MacCutchan 28-Jan-11 8:25am    
Can you show some of the code and/or the contents of your batch file? I don't think it's easy to guess what your problem is.

1 solution

Open the shortcut properties and look at the settings. Do they point to the correct file? Is the working directory correct?

You need to elaborate on "not working", you mean nothing happens? You get an error saying the target is not found? The batch file runs, but doesn't do what it is supposed to?
 
Share this answer
 
Comments
mdumair.dotnet 28-Jan-11 23:30pm    
Thx for reply Indivara,
Yes, I have checked that property,its is showing the exact target location.
And i suppose it accepts the file too, but when i click on that shortcut, bat file runs and after giving a quick flash it get closed and nothing happen.
Pls help me...thx
Regards,
Peter
Indivara 29-Jan-11 5:20am    
Put "pause" at the end of the batch file, that will keep the console window open so you can see what error occurred.

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