It is currently September 21st, 2020, 12:54 pm

Sending Bangs with Autoit.

Get help with installing and using Rainmeter.
red0fireus
Posts: 5
Joined: December 23rd, 2017, 5:04 pm

Sending Bangs with Autoit.

Post by red0fireus »

Hello, this is my second post and I need some support with Bangs and Autoit.
I found this post from 2011 on the rainmeter forum: https://forum.rainmeter.net/viewtopic.php?f=119&t=9652&sid=1972000a769381f344cf19561dfb534f

I'm having issues with sending bangs through CMD/ShellExecute

I currently have a post on AutoIt but it seems like no one is willing to offer a hand :thumbdown:
Post: https://www.autoitscript.com/forum/topic/203535-running-a-exe-with-variables-rainmeter/

I'm looking to send bangs that execute with a variable attached.

Code: Select all

Global $CmdVar2 = 'Minimalist Weather Standalone\'
Global $CmdVar3 = "Minimalist Weather.ini"

ShellExecute("C:\Program Files\Rainmeter\Rainmeter.exe", "'!DeactivateConfig '" & $CmdVar2 & $CmdVar3)
I have tried multiple ways of doing this and I can't seem to find the correct way. If anyone knows I would really appreciate it.

Thank you!
Last edited by red0fireus on August 5th, 2020, 2:31 am, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 21376
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Sending Bangs with Autoit.

Post by jsmorley »

Try this:

Code: Select all

; Usage: SendBang("[!About]")
#include <SendMessage.au3>

Func SendBang($szBang)
   Local Const $hWnd = WinGetHandle("[CLASS:DummyRainWClass]")
   If $hWnd <> 0 Then
      Local Const $iSize = StringLen($szBang) + 1

      Local Const $pMem = DllStructCreate("wchar[" & $iSize & "]")
      DllStructSetData($pMem, 1, $szBang)

      Local Const $pCds = DllStructCreate("dword;dword;ptr")
      DllStructSetData($pCds, 1, 1)
      DllStructSetData($pCds, 2, ($iSize * 2))
      DllStructSetData($pCds, 3, DllStructGetPtr($pMem))

      Local Const $WM_COPYDATA = 0x004A
      _SendMessage($hWnd, $WM_COPYDATA, 0, DllStructGetPtr($pCds))
   EndIf
EndFunc
That is really preferable, since in theory you can't "know" where Rainmeter.exe is installed on any given user's computer.

Also, !DeactivateConfig does not support a file name as a parameter. Only send it a config name.

To do it with ShellExecute, I would use this:

ShellExecute("C:\Program Files\Rainmeter\Rainmeter.exe", '!DeactivateConfig ' & '"' & $CmdVar2 & '"')

The goal is:

"C:\Program Files\Rainmeter\Rainmeter.exe" !DeactivateConfig "ConfigName"
red0fireus
Posts: 5
Joined: December 23rd, 2017, 5:04 pm

Re: Sending Bangs with Autoit.

Post by red0fireus »

Alright so I'm checking the log file and it's showing this !DeactivateConfig: "'Minimalist" not active. It's not picking up anything past the space.
Quotes usually fixes this kind of issue but I tried them and I there's probably some special spot for them?

Code: Select all

SendBang("[!DeactivateConfig 'Minimalist Weather.ini']")


Func SendBang($szBang)
   Local Const $hWnd = WinGetHandle("[CLASS:DummyRainWClass]")
   If $hWnd <> 0 Then
      Local Const $iSize = StringLen($szBang) + 1

      Local Const $pMem = DllStructCreate("wchar[" & $iSize & "]")
      DllStructSetData($pMem, 1, $szBang)

      Local Const $pCds = DllStructCreate("dword;dword;ptr")
      DllStructSetData($pCds, 1, 1)
      DllStructSetData($pCds, 2, ($iSize * 2))
      DllStructSetData($pCds, 3, DllStructGetPtr($pMem))

      Local Const $WM_COPYDATA = 0x004A
      _SendMessage($hWnd, $WM_COPYDATA, 0, DllStructGetPtr($pCds))
   EndIf
EndFunc
User avatar
jsmorley
Developer
Posts: 21376
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Sending Bangs with Autoit.

Post by jsmorley »

red0fireus wrote: August 5th, 2020, 2:16 am Alright so I'm checking the log file and it's showing this !DeactivateConfig: "'Minimalist" not active. It's not picking up anything past the space.
Quotes usually fixes this kind of issue but I tried them and I there's probably some special spot for them?

Code: Select all

SendBang("[!DeactivateConfig 'Minimalist Weather.ini']")


Func SendBang($szBang)
   Local Const $hWnd = WinGetHandle("[CLASS:DummyRainWClass]")
   If $hWnd <> 0 Then
      Local Const $iSize = StringLen($szBang) + 1

      Local Const $pMem = DllStructCreate("wchar[" & $iSize & "]")
      DllStructSetData($pMem, 1, $szBang)

      Local Const $pCds = DllStructCreate("dword;dword;ptr")
      DllStructSetData($pCds, 1, 1)
      DllStructSetData($pCds, 2, ($iSize * 2))
      DllStructSetData($pCds, 3, DllStructGetPtr($pMem))

      Local Const $WM_COPYDATA = 0x004A
      _SendMessage($hWnd, $WM_COPYDATA, 0, DllStructGetPtr($pCds))
   EndIf
EndFunc
You don't use file names with !DeactivateConfig. You use config names.
red0fireus
Posts: 5
Joined: December 23rd, 2017, 5:04 pm

Re: Sending Bangs with Autoit.

Post by red0fireus »

Nvm I got it!
Thank you so much!!!
User avatar
jsmorley
Developer
Posts: 21376
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Sending Bangs with Autoit.

Post by jsmorley »

User avatar
jsmorley
Developer
Posts: 21376
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Sending Bangs with Autoit.

Post by jsmorley »

Great. Glad to help.