Microsoft Development
--
Questions
--
Followers
Top Experts
I have written a script in Autohotkey that does the reconfig, I now just need the trigger. Â I would prefer a script within Autohotkey, but anything external that would interface will suffice. Â Please help!
http://www.autohotkey.com/
I have tried calling the GetCurrentHwProfile function included in the advapi32 library using the DllCall function in Autohotkey with both str * and UInt * return types. Â Script is copied below, no luck. Â I suspect either I am not calling properly or am not deconstructing the HW_PROFILE_INFO response properly.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getcurrenthwprofile.asp
I am using the ExtractInteger function code supplied in the Autohotkey help for DllCall to dissect the doxking state from the returned structure.
**************************
;This function copied directly for Autohotkey help for DllCall
;Given as a method for extracting an integer from the return of a DLL call
;that has mixed types, accepted as a string
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).
{
      SourceAddress := &pSource + pOffset  ; Get address and apply the caller's offset.
      result := 0  ; Init prior to accumulation in the loop.
      Loop %pSize%  ; For each byte in the integer:
      {
           result := result | (*SourceAddress << 8 * (A_Index - 1))  ; Build the integer from its bytes.
           SourceAddress += 1  ; Move on to the next byte.
      }
      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)
}
;Allocate space for structure
VarSetCapacity(MyStruct, 200, 0)
;Make call to retrieve HW_PROFILE_INFO structure
DllCall("advapi32\GetCurre
;Extract dwDockInfo from returned structure's first 4 bytes (double word type)
dwDockInfo := ExtractInteger(MyStruct, 0, 4)
;Looking for hex 2 (docked) or hex 4 (undocked)
MsgBox, Docking state is %dwDockInfo%
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I am a novice programmer, so I may still have issues implementing this, but if so I'll come back with specific questions. Â I'll still be trying to call from and format the return in AutoHotkey.
I've got an HP nc6230 with a docking station and second monitor. Â When docked, I use the laptop screen as the primary screen, and the external as a secondary monitor. Â
However, I have to manually tell the desktop it has two screens in Windows XP (Display Properties - Settings). Â When undocking, I have to manually set it back to one, else windows on the "phantom" screen are invisible. Â
I am using an Autohotkey script to do this setting toggle to save all the clicking through the settings. Â I have tried using SysGet calls in Autohotkey to detect how many screens are attached, but once the laptop has been docked, it reports how many monitors are currently set instead of how many are actually there.
Hope this helps, I think your previous suggestion is within my abilities, I should get a chance to try it out tonight. Â Thanks!!






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept04/hey0921.mspx
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=imper
Set colChassis = objWMIService.ExecQuery _
  ("Select * from Win32_SystemEnclosure")
For Each objChassis In colChassis
  For Each strChassisType In objChassis.ChassisTypes
    MsgBox (strChassisType)
that I was able to get running. Â It detects my laptop as a type 10. Â
I'll have to wait until I get a chance to try this at work, where my docking station resides, to see if the return code changes to 12 (docking station). Â The notes I have found are unclear as to whether a chassis can be multiple types (e.g. a notebook and a docking station) since the type used is an array. ??
I'll keep you posted...
The script center also has some good examples (practically all in VBScript, sorry) that will allow you to setup an event... Â The event will just sit and wait until there is a change in the Win32_SystemEnclosure class instance. Â Inside the event response code, you figure out what the change was, and if it's an addition/deletion of the docking code in ChassisType, then you launch your part of the application.
I've got a few good examples in VB.Net (if that will help any)
Tried the above (just realized the script I pasted here is missing the last two Next statements) with the laptop docked, but the return was the same - I only got the 10 code, no 12.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Still want a VB.Net WMI Event example?
Yes, please do send the links to the examples. Â I've been surveying the MSDN WMI script sites today looking for another way to resolve my problem, but no inpsiration yet.
Thought maybe detecting switch from battery to AC might have merit, but I still plug in a charger at times without docking. Â No other permanent devices attached to the docking station I could look for, either.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Microsoft Development
--
Questions
--
Followers
Top Experts
Most development for the Microsoft platform is done utilizing the technologies supported by the.NET framework. Other development is done using Visual Basic for Applications (VBA) for programs like Access, Excel, Word and Outlook, with PowerShell for scripting, or with SQL for large databases.