windows service detect usb

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • racheli10
    New Member
    • Dec 2009
    • 8

    windows service detect usb

    hi,
    I found a lot of programs that detect usb devices in c#.
    but i need to make windows service program that detect usb.
    can someone help me???
  • NitinSawant
    Contributor
    • Oct 2007
    • 271

    #2
    just create new windows service project in visual studio..

    thats it

    Comment

    • racheli10
      New Member
      • Dec 2009
      • 8

      #3
      it dosen't help me. all the programs I now are with forms that catching messages from windows.
      forms are not abled in sindows service

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        You can probably use WMI classes.
        Win32_DeviceCha ngeEvent triggers when devices are added or removed.
        You could probably key off that event to check to see if the device you wanted exists


        Tie it in with PnPDevice:
        [code=c#]
        try
        {
        ManagementObjec tSearcher searcher =
        new ManagementObjec tSearcher("root \\CIMV2",
        "SELECT * FROM Win32_PnPEntity ");

        foreach (ManagementObje ct queryObj in searcher.Get())
        {
        Console.WriteLi ne("-----------------------------------");
        Console.WriteLi ne("Win32_PnPEn tity instance");
        Console.WriteLi ne("-----------------------------------");
        Console.WriteLi ne("Caption: {0}", queryObj["Caption"]);
        Console.WriteLi ne("ClassGuid: {0}", queryObj["ClassGuid"]);
        Console.WriteLi ne("Description : {0}", queryObj["Descriptio n"]);
        Console.WriteLi ne("DeviceID: {0}", queryObj["DeviceID"]);
        Console.WriteLi ne("Name: {0}", queryObj["Name"]);
        Console.WriteLi ne("PNPDeviceID : {0}", queryObj["PNPDeviceI D"]);
        Console.WriteLi ne("Service: {0}", queryObj["Service"]);
        Console.WriteLi ne("Status: {0}", queryObj["Status"]);
        }
        }
        catch (ManagementExce ption e)
        {
        MessageBox.Show ("An error occurred while querying for WMI data: " + e.Message);
        }
        [/code]

        Comment

        • racheli10
          New Member
          • Dec 2009
          • 8

          #5
          Plater,
          Do you have the whole windows service project that detect usb?

          Comment

          • Dheeraj Joshi
            Recognized Expert Top Contributor
            • Jul 2009
            • 1129

            #6
            Use WMI to achieve this.

            This link may help WMI and USB

            Regards
            Dheeraj Joshi

            Comment

            • racheli10
              New Member
              • Dec 2009
              • 8

              #7
              I used the code that in the link above.
              but it doesn't work.
              do someone have widows service project that detect USD devic?
              ( or at least code that works well)

              Comment

              • Dheeraj Joshi
                Recognized Expert Top Contributor
                • Jul 2009
                • 1129

                #8
                The link was to give an idea. You need to write your own code(I did not tried to execute the code in that link. But i wrote my own code which detected USB connection/Disconnections) .

                Regards
                Dheeraj Joshi

                Comment

                • racheli10
                  New Member
                  • Dec 2009
                  • 8

                  #9
                  Can you bring me the cide you wrote?

                  Comment

                  • Dheeraj Joshi
                    Recognized Expert Top Contributor
                    • Jul 2009
                    • 1129

                    #10
                    You can also use Temporary or permanent even consumers to do this job.

                    Regards
                    Dheeraj Joshi

                    Comment

                    • racheli10
                      New Member
                      • Dec 2009
                      • 8

                      #11
                      soryy, i meen code not cide

                      Comment

                      • Dheeraj Joshi
                        Recognized Expert Top Contributor
                        • Jul 2009
                        • 1129

                        #12
                        Na.... I can not the post here... It belong to some organization...

                        Regards
                        Dheeraj Joshi

                        Note: Its easy to write the code. Give a try :-)

                        Comment

                        • racheli10
                          New Member
                          • Dec 2009
                          • 8

                          #13
                          Can you give me an idea?
                          I am new programer. and i nedd it very necessary.
                          thanx

                          Comment

                          • Plater
                            Recognized Expert Expert
                            • Apr 2007
                            • 7872

                            #14
                            Best advice to give a new programmer:
                            Start reading up APIs and function calls and working things out for yourself. Give it a try.

                            Comment

                            • racheli10
                              New Member
                              • Dec 2009
                              • 8

                              #15
                              If someone anyway can bring me project it will be very good.
                              I need this ASAP

                              Comment

                              Working...