HotPocky

Translate batch to AutoIt?

5 posts in this topic

#1 ·  Posted

I use a batch file to toggle showing/hiding hidden files, folders, etc, and I have recently begun using AutoIt for more flexibility. The idea was to use a .lnk to keybind the process, but I read that getting a batch file to press F5 isn't exactly 'easy'. Currently I use AutoIt to run the batch file and then press F5 after a short period. I have an issue; I have gotten the compiled script to work via a .lnk with a keyboard shortcut, however the focus is on the CMD that pops up for a fraction of a second. My question is how do I express the commands in batch file in AutoIt?

show_hide_files.txt

Share this post


Link to post
Share on other sites



#2 ·  Posted

@HotPocky welcome to the forum. You will find that batch files translate very easily to AutoIt, no need to run both. Below is the beginning of translating your batch file to an AutoIt script. The help file will help you easily create the If statement to RegWrite the appropriate values.

Local $sRegPath = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
Local $sValue = "Hidden"
Local $iDate = 2

$sResult = RegRead($sRegPath, $sValue)

;look at regwrite in the help file

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted

@HotPocky, you may find this useful:

you can see the registry implementation in there, as well as a function to refresh all Windows Explorer windows, instead of sending F5.

Share this post


Link to post
Share on other sites

#4 ·  Posted

Another method:

Local $sRegPath = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
Local $iRegValue = RegRead($sRegPath, "Hidden")
Switch $iRegValue
    Case 1
    ;~ Hidden = 1 - Show hidden files and folders
        RegWrite($sRegPath, "Hidden", "REG_DWORD", 2)
        RegWrite($sRegPath, "HideFileExt", "REG_DWORD", 1)
        RegWrite($sRegPath, "ShowSuperHidden", "REG_DWORD", 0)
    Case Else
    ;~ Hidden = 2 - Don't show hidden files and folders
        RegWrite($sRegPath, "Hidden", "REG_DWORD", 1)
        RegWrite($sRegPath, "HideFileExt", "REG_DWORD", 0)
        RegWrite($sRegPath, "ShowSuperHidden", "REG_DWORD", 1)
EndSwitch

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

And when you get a bit more comfortable with the language you can cut your script in half:

Local $sRegPath = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
Local $iRegValue = RegRead($sRegPath, "Hidden")
    RegWrite($sRegPath, "Hidden", "REG_DWORD", (($iRegValue = 1) ? 2 : 1))
    RegWrite($sRegPath, "HideFileExt", "REG_DWORD", (($iRegValue = 1) ? 1 : 0))
    RegWrite($sRegPath, "ShowSuperHidden", "REG_DWORD", (($iRegValue = 1) ? 0 : 1))

 


√-1 2^3 ∑ π, and it was delicious!

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