Sign in to follow this  
Followers 0
kees

*.BAT to *.AU3

24 posts in this topic

Hallo forum members,

I try to convert a BAT file to AutoIt-script

Content DISPOSE.bat:

@echo off
if "%LOCALAPPDATA%" == "" set LOCALAPPDATA=%USERPROFILE%\Local Settings\Application Data

echo ----------------------------------------------------
echo                SpotLite DISPOSE Lijst
echo  Verwijder SPAM/REQUEST/VIRUS spots uit de database
echo ----------------------------------------------------
echo.
echo Database [%LOCALAPPDATA%\SpotLite\SpotLite\spots.db]
echo.
echo Bijwerken...

chdir /d %~dp0
sqlite3.exe "%LOCALAPPDATA%\SpotLite\SpotLite\spots.db" < dispose_lijst.sql

echo KLAAR
echo.

pause

covert to Autoit:

#include <SQLite.au3>
#NoTrayIcon
#RequireAdmin
#include <SQLite.dll.au3>
#include <file.au3>

$UserLocal = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Local AppData")
$sliteDataBase = $UserLocal & "\SpotLite\SpotLite\spots.db"
$dispose = @ScriptDir & "\dispose_lijst.sql"

Run(@ScriptDir & "\sqlite3.exe", $sliteDataBase  < $dispose)

dispose_lijst.sql will be updated every week from different sources, so it has to be external

I don't know the "<" sign in Autoit to place

THX in Advance

Kees

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi kees,

try:

Run((@ComSpec & " /c " & @ScriptDir & "\sqlite3.exe " & $sliteDataBase & " < " & $dispose)
Edited by Hannes123

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Other answers make these obsolete and are more complete.

I think you are looking for

Run(@ScriptDir & "\sqlite3.exe " & $sliteDataBase & " < " & $dispose)

Putting "<" between quotes makes it a string that can be passed as an argument, while having it without quotes would pass the result of "is $sliteDataBase smaller than $dispose?" as the argument.

Also something to consider:

EnvGet("LOCALAPPDATA")

Edit:syntax fail.

Edited by Tvern

Share this post


Link to post
Share on other sites

Instead of reading from the registry, you could get local app data by doing something like:

EnvGet("LOCALAPPDATA")

chdir can be replaced with FileChangeDir, and running the sqlite3.exe command could be done with run, or with sqlite as you are intending I think.

What does the '<' do do you know? I have tried to rad up pn the command line parameters of sqlite3.exe but can't find much info.

Share this post


Link to post
Share on other sites

@kees:

Just one thing: you do not need to include "sqlite.dll.au3" if you are using the sqlite.exe.

@Mat:

"<" is a DOS syntax like ">", ">>" or "|". It means sth. like "use as input".


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

Instead of reading from the registry, you could get local app data by doing something like:

EnvGet("LOCALAPPDATA")
see:

the script has to work on XP, Vista and Win7

What does the '<' do do you know? I have tried to rad up pn the command line parameters of sqlite3.exe but can't find much info.

the '<' has noting to do with sqlite3.exe it's a part of the bat file witch refers to "dispose_lijst.sql"

part of dispose_lijst.sql

/* 
  SpotLite DISPOSE Lijst, 03-05-2011
*/

DELETE FROM erospots WHERE CAST(msgid AS text) IN (
"002abdf7d4e84e3bb76e00613959dcdf39",
"01a20fed4510474d88fcbc56de127f2c29",
"0RWyuM1uXWkpRSjTQAYy4@spot.net",
"19d38639f7974b589de930577e9d906055",
"1rmay7JBVjgBZptTQAKEA@spot.net",
"2572efc6454a4e68a9d5a88147869ca946",
"2cfdba61609c4ced9a927d41ee875d4d13",
"2ed1e51dfc78437dbb65dd2a7ae330df3",
"2LGAzfK6hb8YU2pTQADX9@spot.net",
"349104fea7744ddd8e499a8eb907248c44",
"47ff113d16344312811a5d872867eb685",
"65972677fbea4b11b40f36b5da42353051",
"6B4yvBOqeNkeJi2TQAAUp@spot.net",
"6e2c399d38164b0bb5ed09c3c476cc7415",
"8Ahh1HXvvuwSYWrTQABf8@spot.net",
"97a0bf096dfc4fff89b4ab4740ee8a775",
"9c43922f8f0d4676a60f93688a6b05bd50",
"AoVXLpMOVT0z5pTTQAQVt@spot.net",
"de0065d6823248b08eb6ecade3a2879647",
"DVl1N6Oqcas0Q2jTQBcNs@spot.net",
"e3713d5021a24c20ad68ce1adbc571ca39",
"F12bMhzlIO0g3KYTQAWUd@spot.net",
"f2739dc95fd14ea79ed77e464e2cdfa70",
"f3c6f80afa3841a39c07cc617eb7dc2622",
"fsAHnJvKWJgavOVTQAR5h@spot.net",
"J3BQToGqHNMxBhpTQADid@spot.net",
"JETelaBXvwIFIGpTQAZVW@spot.net",
"JGn8upPsMqwtuCaTQAGRP@spot.net",
"JtfiXI4uKVsJ5WHTQAEYi@spot.net",
"JV8UD5uE43MsIqkTQALjk@spot.net",
"KDxohcB8DXoVwSrTQAKOk@spot.net",
"O4tXYXpWv6M0eupTQAImf@spot.net",
"OicptBLpTn8C3Z9TQAOeS@spot.net",
"pf1PAsbn2xkEQSkTQATfj@spot.net",
"r5EfpttSDQkhCiaTQAGjG@spot.net",
"RmWsTWkVQb83Kx9TQADsM@spot.net",
"S285lwmbcsMcEulTQAC7k@spot.net",
"tYWbU3X0ta4ppCETQAPdl@spot.net",
"u3L0ONtNbl8rupUTQAJFJ@spot.net",
"VWK1AoRI5GcanSsTQAHTz@spot.net",
"wbuJaKj43G0MVCGTQALrd@spot.net",
"wkNnWxFsOkEtHaKTQAEln@spot.net",
"yDJHAtjNAjQwoiETQAqfN@spot.net"
);

DELETE FROM spots WHERE CAST(msgid AS text) IN (
"000dfa13550f45a3a93f7cf741646e9658",
"01831e2b64ec4ec69ca75f0c403f290d47",
"01Vb5yw7faExLG5TQACxT@spot.net",
"0207eb9a0e884882bfa89fcada6684ed34",
"027fe1c32228443896dbb7eb75283e7023",
"0493a2d1f3df48a3ae3399d800b04edc47",
"04fef0af36ae4ea9840c9999606a4fb225",
"05dafb11c9414ba9a889ac9629f749ec32",
"07ad33f1daeb4054ae7db1611e923de454",
"07pIxf5HPukqTyVTQAA8G@spot.net",
"08kVsvJquRExbiQTQAakT@spot.net",
"09929997b5c640d5a0c48af165d60fd318",
"09a7322396304782b63f5d9981cbad6441",
);

dispose_lijst.zip

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi kees,

try:

Run((@ComSpec & " /c " & @ScriptDir & "\sqlite3.exe " & $sliteDataBase & " < " & $dispose)

: ERROR: syntax error

I've tried this with one "(" see below

Run(@ComSpec & " /c " & @ScriptDir & "\sqlite3.exe " & $sliteDataBase & " < " & $dispose)

no syntax error, I see a little black screen for 1 second, but with no result

Edited by kees

Share this post


Link to post
Share on other sites

Replace /c with /k and start again. The new CMD box will stay open and you can check what's going on in the box.

Btw, try this:

Run(@ComSpec & ' /c ' & '"' & @ScriptDir & '\sqlite3.exe" ' & '"' & $sliteDataBase & '"' & ' < ' & '"' & $dispose & '"')

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

Replace /c with /k and start again. The new CMD box will stay open and you can check what's going on in the box.

Btw, try this:

Run(@ComSpec & ' /c ' & '"' & @ScriptDir & '\sqlite3.exe" ' & '"' & $sliteDataBase & '"' & ' < ' & '"' & $dispose & '"')

Br,

UEZ

Thx for the /k tip

errors (Hannes123)

Run(@ComSpec & " /k " & @ScriptDir & "\sqlite3.exe " & $sliteDataBase & "< "  & $dispose)

E:\DISPOSE\sqlite3.exe:

Error: too many options: "Settings\User\Local"

Use -help for a list of options.

errors (UEZ)

Run(@ComSpec & ' /c ' & '"' & @ScriptDir & '\sqlite3.exe" ' & '"' & $sliteDataBase & '"' & ' < ' & '"' & $dispose & '"')

The syntax of the filename, directory name or volume label is incorrect.

I've made a extra check

If Not FileExists($sliteDataBase) Then
            MsgBox(0, "DataBase", "No 'spots.db' found!")
            Exit
        EndIf

If Not FileExists($dispose) Then
            MsgBox(0, "Dispose lijst", "No 'dispose_lijst.sql' found!")
            Exit
        EndIf

so all files are there

it must be something to do with the quotes " ' ?

Share this post


Link to post
Share on other sites

#10 ·  Posted

Can you post what is written to the console?

$sql =  '"' & @ScriptDir & '\sqlite3.exe" '
$sliteDataBase = '"' &  EnvGet("LOCALAPPDATA") & "\SpotLite\SpotLite\spots.db" & '"'
$dispose = '"' & @ScriptDir & "\dispose_lijst.sql"  & '"'
ConsoleWrite(@ComSpec & ' /k ' & $sql & $sliteDataBase & ' < ' & $dispose & @CRLF)
Run(@ComSpec & ' /k ' & $sql & $sliteDataBase & ' < ' & $dispose)

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

#11 ·  Posted

@UEZ

first of all thank you for looking at the script

(Dutch)

De syntaxis van de bestandsnaam, mapnaam of volumenaam is onjuist.

E:\DISPOSE>

means:

The syntax of the filename, directory name or volume label is incorrect.

btw I'm working now on Win xp

EnvGet("LOCALAPPDATA") won't work with Win xp thats why i used:

RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Local AppData")
see link

Share this post


Link to post
Share on other sites

#12 ·  Posted

No, I mean the output from this line ConsoleWrite(@ComSpec & ' /k ' & $sql & $sliteDataBase & ' < ' & $dispose & @CRLF) in the console of SciTE!

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

#13 ·  Posted

btw I'm working now on Win xp

EnvGet("LOCALAPPDATA") won't work with Win xp thats why i used:

RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Local AppData")
see link

If you're using this on XP, you can substiture EnvGet("LOCALAPPDATA") with EnvGet("APPDATA"). If you wanted a more universal script, you could have different commands to run depending upon what the return value from the macro @OSVERSION gives you. This way it would run on XP, VISTA, and Win7.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#14 ·  Posted

Hallo UEZ,

you mean this?

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "E:\DISPOSE\sqlite.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams

+>16:04:24 Starting AutoIt3Wrapper v.2.0.1.24 Environment(Language:0413 Keyboard:00020409 OS:WIN_XP/Service Pack 3 CPU:X86 OS:X86)

>Running AU3Check (1.54.19.0) from:C:\Program Files\AutoIt3

+>16:04:24 AU3Check ended.rc:0

>Running:(3.3.6.1):C:\Program Files\AutoIt3\autoit3.exe "E:\DISPOSE\sqlite.au3"

C:\WINDOWS\system32\cmd.exe /k "E:\DISPOSE\sqlite3.exe" "\SpotLite\SpotLite\spots.db" < "E:\DISPOSE\dispose_lijst.sql"

+>16:05:30 AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 65.941

Share this post


Link to post
Share on other sites

#15 ·  Posted

Yes. Your commandline is: C:\WINDOWS\system32\cmd.exe /k "E:\DISPOSE\sqlite3.exe" "\SpotLite\SpotLite\spots.db" < "E:\DISPOSE\dispose_lijst.sql" and it is not working because of "\SpotLite\SpotLite\spots.db".

Try this:

$sql =  '"' & @ScriptDir & '\sqlite3.exe" '
$sliteDataBase = '"' &  RegRead('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', 'Local AppData') & "\SpotLite\SpotLite\spots.db" & '"'
$dispose = '"' & @ScriptDir & "\dispose_lijst.sql"  & '"'
ConsoleWrite(@ComSpec & ' /k ' & $sql & $sliteDataBase & ' < ' & $dispose & @CRLF)
Run(@ComSpec & ' /k ' & $sql & $sliteDataBase & ' < ' & $dispose)

And post the output once again (commandline is enough).

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

#16 ·  Posted (edited)

thx again UEZ

C:\WINDOWS\system32\cmd.exe /k "E:\DISPOSE\sqlite3.exe" "C:\Documents and Settings\User\Local Settings\Application Data\SpotLite\SpotLite\spots.db" < "E:\DISPOSE\dispose_lijst.sql"

Looks ok, but still it won't work

The syntax of the filename, directory name or volume label is incorrect

I've tried also this one:

$dispose = '' & @ScriptDir & "\dispose_lijst.sql"  & ''

(without ") but no luck

C:\WINDOWS\system32\cmd.exe /k "E:\DISPOSE\sqlite3.exe" "C:\Documents and Settings\User\Local Settings\Application Data\SpotLite\SpotLite\spots.db" < E:\DISPOSE\dispose_lijst.sql

almost...

mmmm must be close :unsure:

if I look at the DISPOSE.bat

chdir /d %~dp0

sqlite3.exe "%LOCALAPPDATA%\SpotLite\SpotLite\spots.db" < dispose_lijst.sql

Edited by kees

Share this post


Link to post
Share on other sites

#17 ·  Posted

Have you tried setting the WorkingDir parameter of the Run command to the "E:\Dispose" location? I see that the batch file changes to that Drive\Directory before running the command. I have no idea if that makes a difference as you're calling the programs with the full path, but it might have something to do with it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#18 ·  Posted

Yes, I've tried WorkingDir parameter but no luck

pffff get a little wacko here

tomorrow with fresh energy

maybe I see the light

THX for all the help

greetings,

Kees

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

How about this method to remove the command shell and its redirection switch out of the equation?

Now Tested after downloading all the files (which I should have done from the beginning) and can confirm that it works from the standpoint that output retrieved is the same as command shell output for sqlite3.exe

Edited

$sliteDataBase = @AppDataDir & "\SpotLite\SpotLite\spots.db"
$dispose = @SCRIPTDIR &"\dispose_lijst.sql"
;
$_ = FileOpen($dispose)
IF $_ = -1 THEN
    MsgBox(16,@SCRIPTNAME,'Failed to open '& $dispose &' for reading!')
    EXIT 2
ENDIF
$disposeDAT = FileRead($_)
FileClose($_)
;
$OUT = _
"----------------------------------------------------"& @CRLF & _
"               SpotLite DISPOSE Lijst"& @CRLF & _
"  Verwijder SPAM/REQUEST/VIRUS spots uit de database"& @CRLF & _
"----------------------------------------------------"& @CRLF & _
"Database ["& $dispose &"]"& @CRLF & @CRLF &"Bijwerken..."& @CRLF
$PID = Run('"'& @SCRIPTDIR &'\sqlite3.exe" "'& $sliteDataBase &'"',@SCRIPTDIR,@SW_HIDE,7)
IF $PID THEN
  StdinWrite($PID,$disposeDAT &@CRLF)
  StdinWrite($PID)
  WHILE 1
    $OUT &= StdOutRead($PID)
    IF @ERROR THEN EXITLOOP
  WEND
  WHILE 1
    $OUT &= StdErrRead($PID)
    IF @ERROR THEN EXITLOOP
  WEND
  ConsoleWrite($OUT & @LF)
  ;MsgBox(64,@SCRIPTNAME,$OUT)
ELSE
  MsgBox(16,@SCRIPTNAME,"failed to execute sqlite3")
  EXIT 3
ENDIF
EXIT

Ed: removed the registry read since the @AppDataDir macro should handle cross OS.

Also in the batch file the use of "chdir /d %~dp0" was simply so the full path to the sql file did not have to be entered.

Edited by Mobius

Share this post


Link to post
Share on other sites

#20 ·  Posted

Wow Mobius, above my head this script,

Tested it and here are the results of the output

----------------------------------------------------

SpotLite DISPOSE Lijst

Verwijder SPAM/REQUEST/VIRUS spots uit de database

----------------------------------------------------

Database [E:\DISPOSE\dispose_lijst.sql]

Bijwerken...

Error: unable to open database "C:\Documents and Settings\User\Application Data\SpotLite\SpotLite\spots.db": unable to open database file

it has to be:

C:\Documents and Settings\User\Local Settings\Application Data\SpotLite\SpotLite

so I changed this line:

$UserLocal = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Local AppData")
If $UserLocal = "" Then
    MsgBox(16,@ScriptName,"RegRead Error!")
   Exit
EndIf

$sliteDataBase = $UserLocal & "\SpotLite\SpotLite\spots.db"

the output:

----------------------------------------------------

SpotLite DISPOSE Lijst

Verwijder SPAM/REQUEST/VIRUS spots uit de database

----------------------------------------------------

Database [E:\DISPOSE\dispose_lijst.sql]

Bijwerken...

+>09:04:32 AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 3.514

Never thought so much scripting for a simple bat file...

Thx for leaving the option for output

WEND
  ConsoleWrite($OUT & @LF)
  ;[b]MsgBox(64,@SCRIPTNAME,$OUT)[/b]

Greetings and Thank You All!

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