Accessing shared network drives prevents standby mode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JT

    Accessing shared network drives prevents standby mode

    Hi,

    I've realized that my good fortune of not having my computer go into
    standby mode was the result of my application accessing a file on a
    shared network drive. Not going into standby is a very good thing for
    my application, but I don't want users to be required to share a drive
    and file just to accomplish this.

    I've read in old posts in various places stating that by importing
    kernel32.dll I could access a function called
    SetThreadExecut ionState(...) with a value of ES_SYSTEM_REQUI RED,
    potentially ORed with ES_CONTINUOUS (or the equivalent DWORD values),
    would accomplish what I need. I'm guessing this is not managed code
    and would have to be marshalled in and used as unsafe code (please
    forgive me for not knowing anything about marshalling or unmanaged
    code).

    Is there a managed code way to accomplish this? Does anyone have any
    suggestions?

    Thanks,

    JT
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Accessing shared network drives prevents standby mode

    JT,

    You ^might^ be able to do this through the WMI provider for windows,
    which means you would access the System.Manageme nt namespace, but to be
    honest, doing it through the P/Invoke layer is ^not^ that big of a deal.
    The declaration for the function is at:

    SetThreadExecutionState is used to stop the machine timing out and entering standby/switching the display device off.


    Also, you don't need unsafe code to call this. But a call through the
    P/Invoke layer is required. In this case though, it's trivial. Some
    sections of the .NET framework are completely reliant on the P/Invoke layer
    (pretty much everything in the System.Windows. Forms namespace).

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "JT" <jt@onemain.com wrote in message
    news:a6cee46c-e7d6-4c19-bc33-a479e3bbf782@e6 g2000prf.google groups.com...
    Hi,
    >
    I've realized that my good fortune of not having my computer go into
    standby mode was the result of my application accessing a file on a
    shared network drive. Not going into standby is a very good thing for
    my application, but I don't want users to be required to share a drive
    and file just to accomplish this.
    >
    I've read in old posts in various places stating that by importing
    kernel32.dll I could access a function called
    SetThreadExecut ionState(...) with a value of ES_SYSTEM_REQUI RED,
    potentially ORed with ES_CONTINUOUS (or the equivalent DWORD values),
    would accomplish what I need. I'm guessing this is not managed code
    and would have to be marshalled in and used as unsafe code (please
    forgive me for not knowing anything about marshalling or unmanaged
    code).
    >
    Is there a managed code way to accomplish this? Does anyone have any
    suggestions?
    >
    Thanks,
    >
    JT

    Comment

    • JT

      #3
      Re: Accessing shared network drives prevents standby mode

      Thanks Nicholas,

      Before my first post I did a quick scan through WMI, and quickly got
      lost, never having looked at it before, but I didn't see anything
      relating to what I need. I will go look at your link and investigate
      P/Invoke. I've never dealt with that either.

      JT

      On Feb 18, 11:48 am, "Nicholas Paldino [.NET/C# MVP]"
      <m...@spam.guar d.caspershouse. comwrote:
      JT,
      >
          You ^might^ be able to do this through the WMI provider for windows,
      which means you would access the System.Manageme nt namespace, but to be
      honest, doing it through the P/Invoke layer is ^not^ that big of a deal.
      The declaration for the function is at:
      >
      http://www.pinvoke.net/default.aspx/...ExecutionState....
      >
          Also, you don't need unsafe code to call this.  But a call through the
      P/Invoke layer is required.  In this case though, it's trivial.  Some
      sections of the .NET framework are completely reliant on the P/Invoke layer
      (pretty much everything in the System.Windows. Forms namespace).
      >
      --
                - Nicholas Paldino [.NET/C# MVP]
                - m...@spam.guard .caspershouse.c om
      >
      "JT" <j...@onemain.c omwrote in message
      >
      news:a6cee46c-e7d6-4c19-bc33-a479e3bbf782@e6 g2000prf.google groups.com...
      >
      >
      >
      Hi,
      >
      I've realized that my good fortune of not having my computer go into
      standby mode was the result of my application accessing a file on a
      shared network drive.  Not going into standby is a very good thing for
      my application, but I don't want users to be required to share a drive
      and file just to accomplish this.
      >
      I've read in old posts in various places stating that by importing
      kernel32.dll I could access a function called
      SetThreadExecut ionState(...) with a value of ES_SYSTEM_REQUI RED,
      potentially ORed with ES_CONTINUOUS (or the equivalent DWORD values),
      would accomplish what I need.  I'm guessing this is not managed code
      and would have to be marshalled in and used as unsafe code (please
      forgive me for not knowing anything about marshalling or unmanaged
      code).
      >
      Is there a managed code way to accomplish this?  Does anyone have any
      suggestions?
      >
      Thanks,
      >
      JT- Hide quoted text -
      >
      - Show quoted text -

      Comment

      • JT

        #4
        Re: Accessing shared network drives prevents standby mode

        Nicholas,

        I just did my first P/Invoke and it works like a champ (on preliminary
        evaluation)! Are there any caveats about P/Invokes?

        Thanks,

        JT

        On Feb 18, 12:07 pm, JT <j...@onemain.c omwrote:
        Thanks Nicholas,
        >
        Before my first post I did a quick scan through WMI, and quickly got
        lost, never having looked at it before, but I didn't see anything
        relating to what I need.  I will go look at your link and investigate
        P/Invoke.  I've never dealt with that either.
        >
        JT
        >
        On Feb 18, 11:48 am, "Nicholas Paldino [.NET/C# MVP]"
        >
        >
        >
        <m...@spam.guar d.caspershouse. comwrote:
        JT,
        >
            You ^might^ be able to do this through the WMI provider for windows,
        which means you would access the System.Manageme nt namespace, but to be
        honest, doing it through the P/Invoke layer is ^not^ that big of a deal.
        The declaration for the function is at:
        >>
            Also, you don't need unsafe code to call this.  But a call through the
        P/Invoke layer is required.  In this case though, it's trivial.  Some
        sections of the .NET framework are completely reliant on the P/Invoke layer
        (pretty much everything in the System.Windows. Forms namespace).
        >
        --
                  - Nicholas Paldino [.NET/C# MVP]
                  - m...@spam.guard .caspershouse.c om
        >
        "JT" <j...@onemain.c omwrote in message
        >
        news:a6cee46c-e7d6-4c19-bc33-a479e3bbf782@e6 g2000prf.google groups.com...
        >
        Hi,
        >
        I've realized that my good fortune of not having my computer go into
        standby mode was the result of my application accessing a file on a
        shared network drive.  Not going into standby is a very good thing for
        my application, but I don't want users to be required to share a drive
        and file just to accomplish this.
        >
        I've read in old posts in various places stating that by importing
        kernel32.dll I could access a function called
        SetThreadExecut ionState(...) with a value of ES_SYSTEM_REQUI RED,
        potentially ORed with ES_CONTINUOUS (or the equivalent DWORD values),
        would accomplish what I need.  I'm guessing this is not managed code
        and would have to be marshalled in and used as unsafe code (please
        forgive me for not knowing anything about marshalling or unmanaged
        code).
        >
        Is there a managed code way to accomplish this?  Does anyone have any
        suggestions?
        >
        Thanks,
        >
        JT- Hide quoted text -
        >
        - Show quoted text -- Hide quoted text -
        >
        - Show quoted text -

        Comment

        • Willy Denoyette [MVP]

          #5
          Re: Accessing shared network drives prevents standby mode

          Keep in mind that calling this API doesn't prevent a *user* to put the
          system in Sleep state.

          Willy.


          "JT" <jt@onemain.com wrote in message
          news:94aa214e-ccc4-42de-b225-4a775e268d22@d4 g2000prg.google groups.com...
          Nicholas,

          I just did my first P/Invoke and it works like a champ (on preliminary
          evaluation)! Are there any caveats about P/Invokes?

          Thanks,

          JT

          On Feb 18, 12:07 pm, JT <j...@onemain.c omwrote:
          Thanks Nicholas,
          >
          Before my first post I did a quick scan through WMI, and quickly got
          lost, never having looked at it before, but I didn't see anything
          relating to what I need. I will go look at your link and investigate
          P/Invoke. I've never dealt with that either.
          >
          JT
          >
          On Feb 18, 11:48 am, "Nicholas Paldino [.NET/C# MVP]"
          >
          >
          >
          <m...@spam.guar d.caspershouse. comwrote:
          JT,
          >
          You ^might^ be able to do this through the WMI provider for windows,
          which means you would access the System.Manageme nt namespace, but to be
          honest, doing it through the P/Invoke layer is ^not^ that big of a deal.
          The declaration for the function is at:
          >>
          Also, you don't need unsafe code to call this. But a call through the
          P/Invoke layer is required. In this case though, it's trivial. Some
          sections of the .NET framework are completely reliant on the P/Invoke
          layer
          (pretty much everything in the System.Windows. Forms namespace).
          >
          --
          - Nicholas Paldino [.NET/C# MVP]
          - m...@spam.guard .caspershouse.c om
          >
          "JT" <j...@onemain.c omwrote in message
          >
          news:a6cee46c-e7d6-4c19-bc33-a479e3bbf782@e6 g2000prf.google groups.com...
          >
          Hi,
          >
          I've realized that my good fortune of not having my computer go into
          standby mode was the result of my application accessing a file on a
          shared network drive. Not going into standby is a very good thing for
          my application, but I don't want users to be required to share a drive
          and file just to accomplish this.
          >
          I've read in old posts in various places stating that by importing
          kernel32.dll I could access a function called
          SetThreadExecut ionState(...) with a value of ES_SYSTEM_REQUI RED,
          potentially ORed with ES_CONTINUOUS (or the equivalent DWORD values),
          would accomplish what I need. I'm guessing this is not managed code
          and would have to be marshalled in and used as unsafe code (please
          forgive me for not knowing anything about marshalling or unmanaged
          code).
          >
          Is there a managed code way to accomplish this? Does anyone have any
          suggestions?
          >
          Thanks,
          >
          JT- Hide quoted text -
          >
          - Show quoted text -- Hide quoted text -
          >
          - Show quoted text -


          Comment

          • JT

            #6
            Re: Accessing shared network drives prevents standby mode

            Hey Willy,

            I've given the user a preference setting to let him decide how he
            wants the application to behave. I figure if he's set it so that it
            will not go into full standby, then if he purposely places it in that
            mode, he has a reason for it. The application doesn't crash if it's
            in standby.

            So what would a user do to cause standby mode when the application
            setting has indicated otherwise?

            JT

            On Feb 18, 2:00 pm, "Willy Denoyette [MVP]"
            <willy.denoye.. .@telenet.bewro te:
            Keep in mind that calling this API doesn't prevent a *user* to put the
            system in Sleep state.
            >
            Willy.
            >
            "JT" <j...@onemain.c omwrote in message
            >
            news:94aa214e-ccc4-42de-b225-4a775e268d22@d4 g2000prg.google groups.com...
            Nicholas,
            >
            I just did my first P/Invoke and it works like a champ (on preliminary
            evaluation)!  Are there any caveats about P/Invokes?
            >
            Thanks,
            >
            JT
            >
            On Feb 18, 12:07 pm, JT <j...@onemain.c omwrote:
            >
            >
            >
            Thanks Nicholas,
            >
            Before my first post I did a quick scan through WMI, and quickly got
            lost, never having looked at it before, but I didn't see anything
            relating to what I need. I will go look at your link and investigate
            P/Invoke. I've never dealt with that either.
            >
            JT
            >
            On Feb 18, 11:48 am, "Nicholas Paldino [.NET/C# MVP]"
            >
            <m...@spam.guar d.caspershouse. comwrote:
            JT,
            >
            You ^might^ be able to do this through the WMI provider for windows,
            which means you would access the System.Manageme nt namespace, but to be
            honest, doing it through the P/Invoke layer is ^not^ that big of a deal.
            The declaration for the function is at:
            >>
            Also, you don't need unsafe code to call this. But a call through the
            P/Invoke layer is required. In this case though, it's trivial. Some
            sections of the .NET framework are completely reliant on the P/Invoke
            layer
            (pretty much everything in the System.Windows. Forms namespace).
            >
            --
            - Nicholas Paldino [.NET/C# MVP]
            - m...@spam.guard .caspershouse.c om
            >
            "JT" <j...@onemain.c omwrote in message
            >
            >news:a6cee46 c-e7d6-4c19-bc33-a479e3bbf782@e6 g2000prf.google groups.com....
            >
            Hi,
            >
            I've realized that my good fortune of not having my computer go into
            standby mode was the result of my application accessing a file on a
            shared network drive. Not going into standby is a very good thing for
            my application, but I don't want users to be required to share a drive
            and file just to accomplish this.
            >
            I've read in old posts in various places stating that by importing
            kernel32.dll I could access a function called
            SetThreadExecut ionState(...) with a value of ES_SYSTEM_REQUI RED,
            potentially ORed with ES_CONTINUOUS (or the equivalent DWORD values),
            would accomplish what I need. I'm guessing this is not managed code
            and would have to be marshalled in and used as unsafe code (please
            forgive me for not knowing anything about marshalling or unmanaged
            code).
            >
            Is there a managed code way to accomplish this? Does anyone have any
            suggestions?
            >
            Thanks,
            >
            JT- Hide quoted text -
            >
            - Show quoted text -- Hide quoted text -
            >
            - Show quoted text -- Hide quoted text -
            >
            - Show quoted text -

            Comment

            • Willy Denoyette [MVP]

              #7
              Re: Accessing shared network drives prevents standby mode

              "JT" <jt@onemain.com wrote in message
              news:b5a7604e-a229-465d-9a4a-111c69974a62@i2 9g2000prf.googl egroups.com...
              Hey Willy,

              I've given the user a preference setting to let him decide how he
              wants the application to behave. I figure if he's set it so that it
              will not go into full standby, then if he purposely places it in that
              mode, he has a reason for it. The application doesn't crash if it's
              in standby.
              The API only prevents the system to go into standby mode or turn the monitor
              off when triggered by the "power mode policy" settings. This doesn't prevent
              the user from manually putting the system in standby mode.

              So what would a user do to cause standby mode when the application
              setting has indicated otherwise?

              Start menu - Sleep or Press the Sleep or the Power button when configured
              to put the system in Sleep state.

              JT

              On Feb 18, 2:00 pm, "Willy Denoyette [MVP]"
              <willy.denoye.. .@telenet.bewro te:
              Keep in mind that calling this API doesn't prevent a *user* to put the
              system in Sleep state.
              >
              Willy.
              >
              "JT" <j...@onemain.c omwrote in message
              >
              news:94aa214e-ccc4-42de-b225-4a775e268d22@d4 g2000prg.google groups.com...
              Nicholas,
              >
              I just did my first P/Invoke and it works like a champ (on preliminary
              evaluation)! Are there any caveats about P/Invokes?
              >
              Thanks,
              >
              JT
              >
              On Feb 18, 12:07 pm, JT <j...@onemain.c omwrote:
              >
              >
              >
              Thanks Nicholas,
              >
              Before my first post I did a quick scan through WMI, and quickly got
              lost, never having looked at it before, but I didn't see anything
              relating to what I need. I will go look at your link and investigate
              P/Invoke. I've never dealt with that either.
              >
              JT
              >
              On Feb 18, 11:48 am, "Nicholas Paldino [.NET/C# MVP]"
              >
              <m...@spam.guar d.caspershouse. comwrote:
              JT,
              >
              You ^might^ be able to do this through the WMI provider for windows,
              which means you would access the System.Manageme nt namespace, but to
              be
              honest, doing it through the P/Invoke layer is ^not^ that big of a
              deal.
              The declaration for the function is at:
              >>
              Also, you don't need unsafe code to call this. But a call through the
              P/Invoke layer is required. In this case though, it's trivial. Some
              sections of the .NET framework are completely reliant on the P/Invoke
              layer
              (pretty much everything in the System.Windows. Forms namespace).
              >
              --
              - Nicholas Paldino [.NET/C# MVP]
              - m...@spam.guard .caspershouse.c om
              >
              "JT" <j...@onemain.c omwrote in message
              >
              >news:a6cee46 c-e7d6-4c19-bc33-a479e3bbf782@e6 g2000prf.google groups.com...
              >
              Hi,
              >
              I've realized that my good fortune of not having my computer go into
              standby mode was the result of my application accessing a file on a
              shared network drive. Not going into standby is a very good thing
              for
              my application, but I don't want users to be required to share a
              drive
              and file just to accomplish this.
              >
              I've read in old posts in various places stating that by importing
              kernel32.dll I could access a function called
              SetThreadExecut ionState(...) with a value of ES_SYSTEM_REQUI RED,
              potentially ORed with ES_CONTINUOUS (or the equivalent DWORD
              values),
              would accomplish what I need. I'm guessing this is not managed code
              and would have to be marshalled in and used as unsafe code (please
              forgive me for not knowing anything about marshalling or unmanaged
              code).
              >
              Is there a managed code way to accomplish this? Does anyone have any
              suggestions?
              >
              Thanks,
              >
              JT- Hide quoted text -
              >
              - Show quoted text -- Hide quoted text -
              >
              - Show quoted text -- Hide quoted text -
              >
              - Show quoted text -


              Comment

              Working...