Jump to content
Sign in to follow this  
ffdshow

vbs to AutoIt

Recommended Posts

ffdshow

I have this script that auto-hide the taskbar and I want to convert it to AutoIt:

Option Explicit
Const HKCU = &H80000001

Dim objReg
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}root\default:StdRegProv")
Dim objWMI
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}root\cimv2")

' Adjust the first bit of the taskbar settings
Dim arrVal()
objReg.GetBinaryValue HKCU, "Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2", "Settings", arrVal
arrVal(8) = (arrVal(8) AND &h07) OR &h01
objReg.SetBinaryValue HKCU, "Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2", "Settings", arrVal
' Restart Explorer for the settings to take effect.
Dim objProcess, colProcesses
Set colProcesses = objWMI.ExecQuery("Select * from Win32_Process Where Name='explorer.exe'")
For Each objProcess In colProcesses
objProcess.Terminate()
Next

I have problems with BitAND and BitOR commands.

The last part (close and restart explorer is simple).

Share this post


Link to post
Share on other sites
UEZ

Try this:

;arrVal(8) = (arrVal(8) AND &h07) OR &h01

$arrVal[8] = BitOR(BitAND($arrVal[8], 0x07), 0x01)

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
ffdshow

OK, sorry for delay, but can you convert this entire code:

Dim arrVal()
objReg.GetBinaryValue HKCU, "SoftwareMicrosoftWindowsCurrentVersionExplorerStuckRects2", "Settings", arrVal
arrVal(8) = (arrVal(8) AND &h07) OR &h01
objReg.SetBinaryValue HKCU, "SoftwareMicrosoftWindowsCurrentVersionExplorerStuckRects2", "Settings", arrVal

Share this post


Link to post
Share on other sites
UEZ

Btw, why don't you use the built-in Reg commands?

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
ffdshow

Strange, but that reg value looks untouched after vb script was executed, but the setting is done (taskbar autohide).

Share this post


Link to post
Share on other sites
UEZ

Try this:

#include <Array.au3>
Opt("MustDeclareVars", 1) ;Option Explicit
Const $HKCU = 0x80000001 ;Const HKCU = &H80000001

Dim $objReg ;Dim objReg
$objReg = ObjGet("winmgmts:{impersonationLevel=impersonate}rootdefault:StdRegProv") ;Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}rootdefault:StdRegProv")
Dim $objWMI ;Dim objWMI
$objWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}rootcimv2") ;Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}rootcimv2")

;' Adjust the first bit of the taskbar settings
Dim $arrVal[1] ;Dim arrVal()
$objReg.GetBinaryValue($HKCU, "SoftwareMicrosoftWindowsCurrentVersionExplorerStuckRects2", "Settings", $arrVal) ;objReg.GetBinaryValue HKCU, "SoftwareMicrosoftWindowsCurrentVersionExplorerStuckRects2", "Settings", arrVal
$arrVal[8] = BitOR(BitAND($arrVal[8], 0x07), 0x01) ;arrVal(8) = (arrVal(8) AND &h07) OR &h01
_ArrayDisplay($arrVal)
;$objReg.SetBinaryValue($HKCU, "SoftwareMicrosoftWindowsCurrentVersionExplorerStuckRects2", "Settings", $arrVal) ;objReg.SetBinaryValue HKCU, "SoftwareMicrosoftWindowsCurrentVersionExplorerStuckRects2", "Settings", arrVal

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
ffdshow

Thanks! Now it works.

This will check "Taskbar and Start Menu Properties->Taskbar->Auto-hide the taskbar" option in Windows (if it's not already checked):

Opt("TrayIconDebug", 1)
Opt("TrayAutoPause", 0)
Opt("MustDeclareVars", 1)

_TaskbarHidden()

Func _TaskbarHidden() ; 0 = Shown Or 1 = Hidden
   ; Check if the registry involved in this tweak exist
   Dim $StuckRects2
   $StuckRects2 = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2", "Settings")
   If @error Then
      ; Probably the registry key/value name does not exist, so we will import the default from Windows 8
      RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2", "Settings", "REG_BINARY", "0x28000000ffffffff02000000030000003e0000002800000000000000d80200000004000000030000")
   ElseIf $StuckRects2 = "" Then ; The value data is blank and this will not set @error, so we will import the default from Windows 8
      RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2", "Settings", "REG_BINARY", "0x28000000ffffffff02000000030000003e0000002800000000000000d80200000004000000030000")
   EndIf

   ; Check if the taskbar is set to Auto-hide or not
   Local Const $ABM_GETSTATE = 0x00000004
   Local $aReturn
   $aReturn = DllCall('shell32.dll', 'uint', 'SHAppBarMessage', 'dword', $ABM_GETSTATE, 'ptr*', 0)
   If @error Then
      Return SetError(1, 0, 0)
   EndIf
   If BitAND($aReturn[0], 0x01) = 0 Then ; If "Taskbar Properties->Taskbar->Auto-hide the taskbar" is unchecked Then
      ; Set the taskbar to Auto-hide
      Const $HKCU = 0x80000001
      Dim $objReg
      $objReg = ObjGet("winmgmts:{impersonationLevel=impersonate}root\default:StdRegProv")
      Dim $objWMI
      $objWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}root\cimv2")
      ; Adjust the first bit of the taskbar settings
      Dim $arrVal[1]
      $objReg.GetBinaryValue($HKCU, "Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2", "Settings", $arrVal)
      $arrVal[8] = BitOR(BitAND($arrVal[8], 0x07), 0x01)
      $objReg.SetBinaryValue($HKCU, "Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2", "Settings", $arrVal)

      ; Restart Windows Explorer process (explorer.exe) so the settings to take effect
      RunWait('"' & @ComSpec & '"' & " /c " & 'taskkill /f /im ' & "explorer.exe", "", @SW_HIDE)
      RunWait('"' & @ComSpec & '"' & " /c " & 'start ' & @WindowsDir & "\explorer.exe", "", @SW_HIDE)
      Sleep(500)
   EndIf
EndFunc   ;==>_TaskbarHidden
Edited by ffdshow

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
Sign in to follow this  

×