Sign in to follow this  
Followers 0
coucou

Convert a batch file commands into AutoIt?

5 posts in this topic

Hi,

Anyone can help me converting the following batch file commands into AutoIt commands?

Regards

file .bat

attrib -R "%userprofile%\AppData\Local\Microsoft\Windows Sidebar\Settings.ini" /S /D
COPY /Y "%~dp0Settings.ini" "%userprofile%\AppData\Local\Microsoft\Windows Sidebar\"

SET KEY=HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
REG ADD %KEY%\001 /V 1 /D "%systemdrive%\Program Files\Windows Sidebar\sidebar.exe" /f

file.au3

$path = "userprofile%\AppData\Local\Microsoft\Windows Sidebar"
If Not FileSetAttrib($path & "\Settings.ini", "-R", 1) Then
FileCopy($path & "\Settings.ini", "%userprofile%\AppData\Local\Microsoft\Windows Sidebar\")
EndIf

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce", "1", "REG_SZ", "%systemdrive%\Program Files\Windows Sidebar\sidebar.exe")

Share this post


Link to post
Share on other sites



The first line of your code, you forgot to put a '%' before 'userprofile'. It should look like:

$path = "%userprofile%\AppData\Local\Microsoft\Windows Sidebar"

I have a question about the second line. You are doing an IF statement, which makes me think you are trying to read the attribute and based on the results, you will do one thing or another (you would use FileGetAttrib in that case). If that's not the case, then get rid of the IF statement and just run the FileSetAttrib command.


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

Also, I just noticed that you are copying the file to the location it already is at. What is the purpose of that?


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi coucou,

Using "%userprofile%" in a string may not expand into a path with FileCopy() in the above code. You may need to use Opt() to set expand environmental variables or use EnvGet() to expand them.

This is my untested attempt at conversion

$path = EnvGet("userprofile") & "\AppData\Local\Microsoft\Windows Sidebar"

;attrib -R "%userprofile%\AppData\Local\Microsoft\Windows Sidebar\Settings.ini" /S /D
FileSetAttrib($path & "\Settings.ini", "-R")

;COPY /Y "%~dp0Settings.ini" "%userprofile%\AppData\Local\Microsoft\Windows Sidebar\"
FileCopy(@ScriptDir & "\Settings.ini", EnvGet("userprofile") & "\AppData\Local\Microsoft\Windows Sidebar\")

;SET KEY=HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
$key = "HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce"

;REG ADD %KEY%\001 /V 1 /D "%systemdrive%\Program Files\Windows Sidebar\sidebar.exe" /f
RegWrite($key & "\001", "1", "REG_EXPAND_SZ", '"%systemdrive%\Program Files\Windows Sidebar\sidebar.exe"')

"%%" are removed from the environmental variable when you use EnvGet(). "%~dp0" is where the CMD script exists and @ScriptDir is where the AutoIt script exists, so use @ScriptDir to replace the use of "%~dp0" in the AutoIt script. "REG_EXPAND_SZ" is used though it is perhaps not required to expand "%systemdrive%" in the current usage. Added quotes to the RegWrite() data string as you have some whitespace with in the string.

I notice that you do not reverse the read only attribute on the settings file after the file is copied. Something for you to consider. :unsure:

Edited by MHz

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

TNX sleepydvdr and my savior MHZ :unsure:

@MHZ that script is a tweak for Windows 7: gadgets customize then sidebar restart

The only test be done during Win 7 installation. I'll give a try later.

Regards

Edited by coucou

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  
Followers 0