Sign in to follow this  
Followers 0
arcticpup

SQL Script

5 posts in this topic

Hi,

I'm still very new to AutoIT and am struggling with the following.

OK, here's what I want to do.

Read a registry key (this is actually the SQL server and instance name eg: mycomputer\sqlexpress) into a variable. I'm OK with this bit.

Now, I want to connect to the SQL server using the above variable and a trusted connection (so in dos it would look like osql -Smycomputer\sqlexpress -E)

How do I pass the variable created into the middle of a DOS string? I've tried _rundos() without much luck.

Once I've overcome that hurdle, I want to retrieve a certain value from a certain table. (Which in SQL I'm fine with)

CODE
Use MYDB

Select accesspassword from ib21

where staffnumber = 1

go

Ideally, I would like the result to be returned as a dialog box or failing that as a text file.

Amy I asking the impossible here? Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites



OK, I've made some progress and consolidated it into 1 CMD file without the need for a seperate SQL file.

Now I have just 2 questions.

1)How do I pass the registry variable into the DOS command

2)Can I use _runDOS without the quotes as it is messing up my SQL string (Or can I just pass the SQL file direct to dos via autoit?)

Share this post


Link to post
Share on other sites

1)

$var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")
Run(@ComSpec & " /k " & 'echo ' & $var)

2)

I guess you can't. You can either escape quotes by quoting them or use single quotes to enclose the statement if $var contains double quotes or the other way around.

MsgBox(0,"Test"," "" ")
MsgBox(0,'Test',' '' ')
MsgBox(0,"Test"," ' ")
MsgBox(0,'Test',' " ')

Share this post


Link to post
Share on other sites

1)

$var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")
Run(@ComSpec & " /k " & 'echo ' & $var)

2)

I guess you can't. You can either escape quotes by quoting them or use single quotes to enclose the statement if $var contains double quotes or the other way around.

MsgBox(0,"Test"," "" ")
MsgBox(0,'Test',' '' ')
MsgBox(0,"Test"," ' ")
MsgBox(0,'Test',' " ')
Great stuff! Have now got it creating a text file.... Is it possible to take the output from the DOS box and have this display in a message box.

Thanks for all your help so far though!

Share this post


Link to post
Share on other sites

Great stuff! Have now got it creating a text file.... Is it possible to take the output from the DOS box and have this display in a message box.

Thanks for all your help so far though!

Yet another dog eats yet another help file...

Look up StdOutRead().

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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