AutoHotkey Community

It is currently May 26th, 2012, 10:17 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: January 5th, 2007, 3:12 pm 
Offline

Joined: June 6th, 2006, 3:19 pm
Posts: 1654
Location: Denmark
The GetServiceState function checks the state of a named service, return 1 if stopped and 4 if running.
Code:
SERVICE_STOPPED          = 0x00000001
SERVICE_START_PENDING    = 0x00000002
SERVICE_STOP_PENDING     = 0x00000003
SERVICE_RUNNING          = 0x00000004
SERVICE_CONTINUE_PENDING = 0x00000005
SERVICE_PAUSE_PENDING    = 0x00000006
SERVICE_PAUSED           = 0x00000007

MsgBox % GetServiceState("LanmanWorkstation")

GetServiceState(szDisplayName)
{
  dwCurrentState =
  ; open service manager with sufficient rights
  scManager := DllCall("advapi32\OpenSCManagerA", uint, 0, uint, 0, uint, 0x0002002f)
  if scManager
  {
    ; open the service
    scService := DllCall("advapi32\OpenServiceA", uint, scManager, str, szDisplayName, uint, 0x000200ff)
    if not scService
    {
      szServiceName =
      VarSetCapacity(szServiceName,1024,0)
      VarSetCapacity(dwLen,4,0)
      InsertInteger(1024,dwLen)
      ; try to find the service name from the display name
      DllCall("advapi32\GetServiceKeyNameA", uint, scManager, str, szDisplayName, str, szServiceName, uint, &dwLen)
      scService := DllCall("advapi32\OpenServiceA", uint, scManager, str, szServiceName, uint, 0x000200ff)
    }
    ; is service found
    if scService
    {
      VarSetCapacity(serviceStatus,28,0)
      /*
        typedef struct _SERVICE_STATUS
        {
          DWORD dwServiceType;
          DWORD dwCurrentState;
          DWORD dwControlsAccepted;
          DWORD dwWin32ExitCode;
          DWORD dwServiceSpecificExitCode;
          DWORD dwCheckPoint;
          DWORD dwWaitHint;
        } SERVICE_STATUS, *LPSERVICE_STATUS;
      */
      ; SERVICE_CONTROL_INTERROGATE = 0x00000004
      DllCall("advapi32\ControlService", uint, scService, uint, 0x00000004, str, serviceStatus)
      dwCurrentState := ExtractInteger(serviceStatus, 4)
      ; close the service
      DllCall("advapi32\CloseServiceHandle", int, scService)
    }
  }
  ; close the service manager
  DllCall("advapi32\CloseServiceHandle", int, scManager)

  return dwCurrentState
}

_________________
RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2007, 4:09 pm 
The ExtractInteger and InsertInteger functions are missing. I find them in the help. Then it works very nice!

:D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2007, 1:21 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 774
Location: Texas, USA
This looks like it might have some value. I'm gonna check it out. Thanks for sharing! :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2007, 3:44 pm 
Offline

Joined: November 27th, 2006, 7:41 am
Posts: 222
Location: Queensland, Australia
That self collapsing code window is pretty damn annoying when i try to use my 'execute from web text' script to copy it...every time i try to select the text it deselects it.
and... &dwLen gets converted to &dwLen by the pages' built in 'copy to clipboard' function.... which isn't terribly useful.
At first I thought: cool new forum way to show code... but now it's Very grrr.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2007, 4:05 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
What browser are you using? You can disable code collapsing by typing 'javascript:void(document.cookie = 'codeblock-enabled=0');' in your browser address bar and pressing enter. To turn it on again change the 0 to 1.

BETLOG wrote:
&dwLen gets converted to &dwLen by the pages' built in 'copy to clipboard' function
That's caused by the escape() function which I'll have to fix this later on, thanks. btw. if you have any more queries or suggestions please use the [codebox] command thread.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2007, 5:34 pm 
Quote:
You can disable code collapsing by typing 'javascript:void(document.cookie = 'codeblock-enabled=0');' in your browser address bar and pressing enter.


Maybe a link to do just that could be added to the code-folding?


Report this post
Top
  
Reply with quote  
PostPosted: July 30th, 2008, 4:18 pm 
Offline

Joined: November 18th, 2005, 11:16 pm
Posts: 77
Location: Southern USA
It appears that these functions are no longer in the help documentation. I found some in forum posts and thought I would paste them into this post because some else might come along and not be able to find them.

I pasted them onto the end of the main code above and it seemed to work.

Code:
ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4)
; pSource is a string (buffer) whose memory area contains a raw/binary integer at pOffset.
; The caller should pass true for pSigned to interpret the result as signed vs. unsigned.
; pSize is the size of PSource's integer in bytes (e.g. 4 bytes for a DWORD or Int).
; pSource must be ByRef to avoid corruption during the formal-to-actual copying process
; (since pSource might contain valid data beyond its first binary zero).
{
   Loop %pSize%  ; Build the integer by adding up its bytes.
      result += *(&pSource + pOffset + A_Index-1) << 8*(A_Index-1)
   if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
      return result  ; Signed vs. unsigned doesn't matter in these cases.
   ; Otherwise, convert the value (now known to be 32-bit) to its signed counterpart:
   return -(0xFFFFFFFF - result + 1)
}

InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
; The caller must ensure that pDest has sufficient capacity.  To preserve any existing contents in pDest,
; only pSize number of bytes starting at pOffset are altered in it.
{
   Loop %pSize%  ; Copy each byte in the integer into the structure as raw binary data.
      DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
}


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 31st, 2008, 3:41 pm 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 774
Location: Texas, USA
hurricanedavid wrote:
It appears that these functions are no longer in the help documentation. I found some in forum posts and thought I would paste them into this post because some else might come along and not be able to find them.

FYI. Both of these functions can be replaced with the built-in NumGet and NumPut functions which were introduced in v1.0.47. Documentation for these functions can be found here:
http://www.autohotkey.com/docs/Functions.htm


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2008, 3:47 pm 
Offline

Joined: November 18th, 2005, 11:16 pm
Posts: 77
Location: Southern USA
Oh, okay. I guess that's why they weren't in the documentation.

Well, at least anyone who finds the code at the top of this post will know to use the built-in functions because of your comment.

Thank you.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: xXDarknessXx and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group