Search code examples
c#rundll32

Need to run a c# dll from the command line


I have a c# dll defined like this:

namespace SMSNotificationDll
{
    public class smsSender
    {
        public void SendMessage(String number, String message)
        {
            ProcessStartInfo info = new ProcessStartInfo();
            info.FileName = "c:\\Program Files\\Java\\jdk1.6.0_24\\bin\\java";
            info.WorkingDirectory = "c:\\";
            info.Arguments = "-jar SendSms.jar "+number + " "+message;
            info.UseShellExecute = false;
            Process.Start(info);
        }
    }
}

and i need to execute it from the commandline.

Is there any way I can run it through rundll32?

When I run it with this :

rundll32 SMSNotificationDll.dll, SendMessage 0749965244 hello

I get missing entry: SendMessage.


Solution

  • Why don't you just create a simple console application which refers to the DLL as a class library?

    namespace SMSNotificationDll
    {
        public class SmsSenderProgram
        {
            public static void Main(string[] args)
            {
                // TODO: Argument validation
                new smsSender().SendMessage(args[0], args[1]);
            }
        }
    }
    

    Btw, I'd rename smsSender to something like SmsSender.