Sign in to follow this  
Followers 0
Necromorph

$var = %infinity%

6 posts in this topic

okay, this is most likely been answered, i did look around for a bit with nothing usefull but is there an easy way to asign a varable to infiniy?

basically this is what i want

$instance = "MSSQLSERVER"
$infinity = {here is where the method to get infinity would go}
For $x = 1 to $infiniy
    $var = RegEnumVal("HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL", $x)
If $instance = $var Then
    MsgBox(0, "instance already exists", $var)
EndIf
Next

i know that people problably won't have more then two instances of SQL, so i could just say $x - 1 to 5, and it would most likely be fine, but still, i would just like to know how to "wildcard" a number, so to speak, thanks for any help.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try something like this.

Global $iNum = 0

While Sleep(100)
    ConsoleWrite("| ------> $iNum        : " & $iNum & @CRLF)
    $iNum += 1

    If ($iNum == 10) Then Exit ; just to make sure the script exits
WEnd

EDIT:

HotKeySet("{ESC}", "_Exit")

Global $sInstance = "MSSQLSERVER"
Global $iNum = 1

While Sleep(25) ; prevent lots of CPU usage
    $sVar = RegEnumVal("HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL", $iNum)

    If ($sVar == $sInstance) Then
        MsgBox(0, "", "Instance already exists." & @CRLF & $sVar)
    EndIf

    $iNum += 1
WEnd

Func _Exit()
    Exit
EndFunc
Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Try to do a loop and exit until you found the value or exitloop when there is error

Share this post


Link to post
Share on other sites

Infinity is approximately 97231. I tried counting further, but couldn't.

$instance = "MSSQLSERVER"
$infinity = 97231
For $x = 1 to $infiniy
    $var = RegEnumVal("HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL", $x)
If $instance = $var Then
    MsgBox(0, "instance already exists", $var)
EndIf
Next

Share this post


Link to post
Share on other sites

thanks for all the help everyone, here is how i ended up doing it

$instance = "MSSQLSERVER"
$x = 1

Do
    $instances = RegEnumVal("HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL", $x)
    If $instance <> $instances Then
        $x += 1
    ElseIf $instance = $instances Then
        MsgBox(0, "", "Instance already exists." & @CRLF & $instance)
        ExitLoop
    EndIf
Until @error = -1

may not be the best, but it is working. and Manadar, i agree with you, and like i said, i could have said " For $x = 1 to 5" and been fine with sql instances, but i want a better way to get to "infinity", which i still didn't answer. thanks.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This is a proper way to write

This is to find a value, exit when value is found

$instance = "MSSQLSERVER"
$x = 0
Do
    $x += 1
    $instances = RegEnumVal("HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL", $x)
Until @error = -1 Or $instances = $instance
;msgbox...

Use exitloop when it's really necessary ;)

Edited by trung0407

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