Run GadGet

1 post in this topic

well. Reading in msdn I found an interface to run a Gadget. So I wrote it. 


#include <Array.au3>
#include <File.au3>

Global Const $sCLSID_DesktopGadget = "{924CCC1B-6562-4C85-8657-D177925222B6}"
Global Const $sIID_IDesktopGadget = "{C1646BC4-F298-4F91-A204-EB2DD1709D1A}"
Global Const $sTagIDesktopGadget = "RunGadget hresult(wstr);"

Global Enum $eNoShared = 1, $eShared, $eAll

Local $aGadGets = _GetGadget($eAll)

If IsArray($aGadGets) Then
    For $i = 1 To $aGadGets[0]
        If StringInStr($aGadGets[$i], "CPU") Then ;Run CPU GadGet


Func RunGadget($sGadGetPath)
Local $oDesktopGadget = ObjCreateInterface($sCLSID_DesktopGadget, $sIID_IDesktopGadget, $sTagIDesktopGadget)
if not IsObj($oDesktopGadget) then Return False
return SUCCEEDED($oDesktopGadget.RunGadget($sGadGetPath))
EndFunc   ;==>RunGadget

Func _GetGadget($GadgetType = $eNoShared)
    Local $aNoSharedGadGets = 0
    Local $aSharedGadGets = 0
    Local $aGadGets = 0
    Local $Size = 0
    Local Const $sSharedGadget = @ProgramFilesDir & "\Windows Sidebar\Shared Gadgets"
    Local Const $sNoShared = @ProgramFilesDir & "\Windows Sidebar\Gadgets"
    If $GadgetType < $eNoShared Or $GadgetType > $eAll Then Return 0

    If BitAND($GadgetType, $eNoShared) Then $aNoSharedGadGets = _FileListToArray($sNoShared, Default, Default, True)

    If BitAND($GadgetType, $eShared) Then $aSharedGadGets = _FileListToArray($sSharedGadget, Default, Default, True)

    If IsArray($aSharedGadGets) And IsArray($aNoSharedGadGets) Then
        $Size = UBound($aNoSharedGadGets) - 1 + (UBound($aSharedGadGets) - 1)
        _ArrayConcatenate($aNoSharedGadGets, $aSharedGadGets, 1)
        $aGadGets = $aNoSharedGadGets
        $aGadGets[0] = $Size
        If IsArray($aSharedGadGets) Then $aGadGets = $aSharedGadGets
        If IsArray($aNoSharedGadGets) Then $aGadGets = $aNoSharedGadGets
    $aSharedGadGets = 0;Free
    $aNoSharedGadGets = 0 ;Free

    Return $aGadGets

EndFunc   ;==>_GetGadget

    Return ($hr >= 0)
EndFunc   ;==>SUCCEEDED





1 person likes this

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • BlazerV60
      By BlazerV60
      Hello all,
      I've written the code below which launches chrome in incognito mode and then proceeds to go to the autoit website.
      From my understanding, the Run() command is also supposed to output the PID number related to the application that got launched from the Run command.
      However when I run the below lines, it outputs a PID number that is different from the newly launched chrome browser's PID number, does anyone know why and possibly explain how I could retrieve the accurate PID number associated with the newly launched browser?
      Global $iPid = Run(@ComSpec & ' /c start chrome.exe https://www.autoitscript.com/forum/ -incognito' ,"", "") msgbox(0,"",$iPid) Thank you,
    • rootx
      By rootx
      I need help to understand why the run function does not work, but if i use it directly inside cmd shell the command works. $where is the name of the jpg file
      ShellExecute(@ComSpec ," /k C:\Users\root\Desktop\test\exiftool.exe -p $FileName "&'"'&$where&'"'&" > "&'"'&@ScriptDir&"\out.txt"&'"',@ScriptDir);<----- work Run("C:\Users\root\Desktop\test\exiftool.exe -p $FileName "&$where&" > "&@ScriptDir&"\out.txt",@ScriptDir);<--- doesn't work I would use the run command!
    • nacerbaaziz
      By nacerbaaziz
      How are you
      I have a question, please.
      I've created a window and i need
      when i run the script if it detect an other copy from the same script was runing
       the script close the first copy Automatically and run a new copy
      I want an example to understand it
    • kawliga751
      By kawliga751
      I am attempting to run an Autoit.exe with schtasks every weekday @ 9:05 am.
      I have the below
      C:\>SchTasks /Create /TN "P10Run" /TR "O:\AUTOIT\P40 Run.au3" /SC WEEKLY /D MON, TUE,WED,THU,FRI /ST 09:05:00 SUCCESS: The scheduled task "P10Run" has successfully been created. I also did a "test" run :
      C:\>Schtasks /Run /TN "P10Run SUCCESS: Attempted to run the scheduled task "P10Run". But when I run my query to verify success my "Last Result" seems to indicate that the script did not run:
      C:\>SCHTASKS /QUERY /FO LIST /V /TN "P10RUN" Folder: \ HostName: xxxxxxxxxxxxxxxx TaskName: \P10RUN Next Run Time: N/A Status: Could not start Logon Mode: Interactive only Last Run Time: 6/14/2017 9:08:56 AM Last Result: -2147024894 Author: xxxxxxx Task To Run: O:\AUTOIT\P40 Run.au3 Start In: N/A Comment: N/A Scheduled Task State: Enabled Idle Time: Disabled Power Management: Stop On Battery Mode, No Start On Batterie s Run As User: xxxxxxxxx\xxxxxxxx Delete Task If Not Rescheduled: Enabled Stop Task If Runs X Hours and X Mins: 72:00:00 Schedule: Scheduling data is not available in this f ormat. Schedule Type: Weekly Start Time: 9:05:00 AM Start Date: 6/14/2017 End Date: N/A Days: MON, TUE, WED, THU, FRI Months: Every 1 week(s) Repeat: Every: Disabled Repeat: Until: Time: Disabled Repeat: Until: Duration: Disabled Repeat: Stop If Still Running: Disabled C:\> Is there something missing in my command? Also is there a better way to make sure that the script does in fact sun successfully?
      Thanks In Advance! 
    • AnonymousX
      By AnonymousX
      What command would I use to open the following folder directories for:
      Computer/This PC (windows 7/Windows 10)
      I know:
       Run("Explorer.exe " & $filepath) ShellExecute($filepath) can be used to open folder locations when you type in the full directory such as "C:\Users\%username%\Documents" but I'm trying to figure out how to use these windows short paths.