Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. c# program that can be closed by arguments

c# program that can be closed by arguments

Scheduled Pinned Locked Moved C#
csharpquestion
12 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A ayandelhi

    Hi!! i wanted to know if u cud tell me how can i make my program work in this manner.. run-> xyz.exe -start //to start now the my program is running.. now to stop it... run-> xyz.exe -stop //to stop i'm thinking that when i write this last command, i use diagnostic class to kill xyz.exe process.. wat say.. m i thinking right... is there anyother way to do it..

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #2

    I do that with my Windows Services.

    A 1 Reply Last reply
    0
    • P PIEBALDconsult

      I do that with my Windows Services.

      A Offline
      A Offline
      ayandelhi
      wrote on last edited by
      #3

      wat m saying.. is that possible...

      K 1 Reply Last reply
      0
      • A ayandelhi

        wat m saying.. is that possible...

        K Offline
        K Offline
        Keith Barrow
        wrote on last edited by
        #4

        Possible? Yes. Sensible? No. What you are asking for is pretty much a windows service. You could do what you want, but it would be technically much more difficult than a service. Weren't you asking about TSRs earlier? The answer remains a the same, Windows services will do what you are asking, is there some reason you can't use them?

        Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter. Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.

        A 1 Reply Last reply
        0
        • K Keith Barrow

          Possible? Yes. Sensible? No. What you are asking for is pretty much a windows service. You could do what you want, but it would be technically much more difficult than a service. Weren't you asking about TSRs earlier? The answer remains a the same, Windows services will do what you are asking, is there some reason you can't use them?

          Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter. Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.

          A Offline
          A Offline
          ayandelhi
          wrote on last edited by
          #5

          actually.. i dont know how to write window services... and moreover m having just a month to complete my program... my program does 3 works... keylogger for security purposes, watches mentioned files, and kills mentioned processes... now to that i've the knowledge abt all three... but wat i'm lacking is the way i want to integrate them...

          L P 2 Replies Last reply
          0
          • A ayandelhi

            actually.. i dont know how to write window services... and moreover m having just a month to complete my program... my program does 3 works... keylogger for security purposes, watches mentioned files, and kills mentioned processes... now to that i've the knowledge abt all three... but wat i'm lacking is the way i want to integrate them...

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            Search for a beginner's article on services here.

            Join the cool kids - Come fold with us[^]

            A 1 Reply Last reply
            0
            • L Lost User

              Search for a beginner's article on services here.

              Join the cool kids - Come fold with us[^]

              A Offline
              A Offline
              ayandelhi
              wrote on last edited by
              #7

              coudle u plz link me to the best article on services... i've found one.. [^] is this the correct one..

              L 1 Reply Last reply
              0
              • A ayandelhi

                coudle u plz link me to the best article on services... i've found one.. [^] is this the correct one..

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #8

                That's a good one, remember to read the messages at the end. These can contain answers to problems you hit on the way.

                Join the cool kids - Come fold with us[^]

                A 1 Reply Last reply
                0
                • A ayandelhi

                  actually.. i dont know how to write window services... and moreover m having just a month to complete my program... my program does 3 works... keylogger for security purposes, watches mentioned files, and kills mentioned processes... now to that i've the knowledge abt all three... but wat i'm lacking is the way i want to integrate them...

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #9

                  Definitely sounds like you need a Service. They're not difficult. To be able to control a Service from the command line I do something like:

                      private enum Action
                      {
                          None = 0
                      ,
                          Status
                      ,
                          Install
                      ,
                          Uninstall
                      ,
                          Start
                      ,
                          Stop
                      }
                  
                      \[System.STAThreadAttribute()\]
                      public static int
                      Main
                      (
                          string\[\] Args
                      )
                      {
                          int result = 0 ;
                  
                          try
                          {
                              Action action = Action.None ;
                  
                              if ( Args.Length > 0 )
                              {
                                  System.Enum.TryParse<Action> ( Args \[ 0 \] , true , out action ) ;         
                              }
                  
                              switch ( action )
                              {
                                  case Action.None :
                                  {
                                      if ( System.Environment.UserInteractive )
                                      {
                                          System.Console.WriteLine ( "Syntax: JunkService STATUS | INSTALL | UNINSTALL | START | STOP" ) ;
                                      }
                                      else
                                      {
                                          System.ServiceProcess.ServiceBase.Run ( srv ) ;
                                      }
                  
                                      break ;
                                  }
                  
                                  case Action.Status :
                                  {
                                      System.ServiceProcess.ServiceController svc = 
                                          new System.ServiceProcess.ServiceController
                                          (
                                              srv.ServiceName
                                          ,
                                              System.Environment.MachineName
                                          ) ;
                  
                                      try
                                      {
                                          System.Console.WriteLine ( svc.Status ) ;
                                      }
                                      catch ( System.InvalidOperationException err ) 
                                      {
                                          System.Console.WriteLine ( err.Message ) ;
                                      }
                  
                                      break ;
                                  }
                  
                                  case Action.Install :
                                  {
                                      System.Configuration.Install.ManagedInstallerClass.InstallHelper 
                                      ( 
                                          new string\[\] { System.Windows.Forms.Application.ExecutablePath } 
                                      )
                  
                  1 Reply Last reply
                  0
                  • L Lost User

                    That's a good one, remember to read the messages at the end. These can contain answers to problems you hit on the way.

                    Join the cool kids - Come fold with us[^]

                    A Offline
                    A Offline
                    ayandelhi
                    wrote on last edited by
                    #10

                    i'm unable to understand this services from that article.. i understood its using service controller class in c#.. but m confused where should i place my code to be executed in it.. it says that the control should be transfered to os after the service is executed. but i want my program to be kept running otherwise it wont be logging keys, or watching files, or killing mentioned processes.. i hope u got my point..

                    K 1 Reply Last reply
                    0
                    • A ayandelhi

                      i'm unable to understand this services from that article.. i understood its using service controller class in c#.. but m confused where should i place my code to be executed in it.. it says that the control should be transfered to os after the service is executed. but i want my program to be kept running otherwise it wont be logging keys, or watching files, or killing mentioned processes.. i hope u got my point..

                      K Offline
                      K Offline
                      Keith Barrow
                      wrote on last edited by
                      #11

                      You can do this from the command line: http://www.windowsitpro.com/article/registry2/how-can-i-stop-and-start-services-from-the-command-line-.aspx[^] Or you can do this though a gui: http://service1.symantec.com/SUPPORT/tsgeninfo.nsf/docid/2001120709062339[^]

                      Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter. Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.

                      1 Reply Last reply
                      0
                      • A ayandelhi

                        Hi!! i wanted to know if u cud tell me how can i make my program work in this manner.. run-> xyz.exe -start //to start now the my program is running.. now to stop it... run-> xyz.exe -stop //to stop i'm thinking that when i write this last command, i use diagnostic class to kill xyz.exe process.. wat say.. m i thinking right... is there anyother way to do it..

                        R Offline
                        R Offline
                        Ravi Bhavnani
                        wrote on last edited by
                        #12

                        If you don't want to make your app a service and don't want to build a listener that listens for a close message, you can achieve your goal by periodically checking for the presence of an "exit" file (in the same directory as the application).  The -stop command line argument would simply create the "exit" file and exit, causing all normally running instances of your application to exit. Caveat: this is a cheesy hack but may meet your needs at a pinch. /ravi

                        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups