Jump to content

Windows Run UDF


AlmarM
 Share

Recommended Posts

Hello,

Mayby you saw the "iRun~" topic I made...

And I tought this would be usefull for some people!

Commands:

  • _AddRun()
  • _DeleteRun()
  • _ReadRun()
  • _ReadAllRun() (Need Fix!)
; #FUNCTION# =================================================================================================
; Name...........: _AddRun()
; Description ...: Adds a registery key to the Run folder
; Syntax.........: _AddRun($n_Name, $n_Path, $n_Option = 0)
; Parameters ....:  $n_Name = The name of the key
;                       $n_Path = The path to the file
;                       $n_Option = When sould the file be started (0 = Only on this user, 1 = On all users)
; Errors ........:  0 = Succes
;                       1 = Keyname already exists
; Return values .: $n_Read
; Author ........: Almar Mulder (AlmarM)
; Modified.......: -
; Remarks .......: -
; Related .......: RegWrite(), _DeleteRun(), _ReadRun()
; Link ..........: -
; Example .......: Yes
;                   _AddRun("Test", "C:\Temp\test.txt", 1)
; #FUNCTION# =================================================================================================
Func _AddRun($n_Name, $n_Path, $n_Option = 0)
    If $n_Option = 0 Then
        $n_HKEY = "HKEY_CURRENT_USER\Software"
    Else
        $n_HKEY = "HKEY_LOCAL_MACHINE\SOFTWARE"
    EndIf
    If RegRead($n_HKEY & "\Microsoft\Windows\CurrentVersion\Run", $n_Name) = True Then
        SetError(1)
    Else
        RegWrite($n_HKEY & "\Microsoft\Windows\CurrentVersion\Run", $n_Name, "REG_SZ", $n_Path)
        SetError(0)
    EndIf
EndFunc     ;==> _AddRun()

; #FUNCTION# =================================================================================================
; Name...........: _DeleteRun()
; Description ...: Deletes a registery key in the Run folder
; Syntax.........: _DeleteRun($n_Name, $n_Option = 0)
; Parameters ....:  $n_Name = The name of the key
;                       $n_Option = Where sould the key be deleted? (0 = Only on this user, 1 = On all users)
; Erros .........:  0 = Succes
;                       1 = Keyname doesnt exists
; Return values .: $n_Read
; Author ........: Almar Mulder (AlmarM)
; Modified.......: -
; Remarks .......: -
; Related .......: RegWrite(), _AddRun(), _ReadRun()
; Link ..........: -
; Example .......: Yes
;                   _DeleteRun("Test", 1)
; #FUNCTION# =================================================================================================
Func _DeleteRun($n_Name, $n_Option = 0)
    If $n_Option = 0 Then
        $n_HKEY = "HKEY_CURRENT_USER\Software"
    Else
        $n_HKEY = "HKEY_LOCAL_MACHINE\SOFTWARE"
    EndIf
    If RegRead($n_HKEY & "\Microsoft\Windows\CurrentVersion\Run", $n_Name) = False Then
        SetError(1)
    Else
        RegDelete($n_HKEY & "\Microsoft\Windows\CurrentVersion\Run", $n_Name)
        SetError(0)
    EndIf
EndFunc     ;==> _DeleteRun()

; #FUNCTION# =================================================================================================
; Name...........: _ReadRun()
; Description ...: Reads a registery key in the Run folder
; Syntax.........: _ReadRun($n_Name, $n_Option = 0)
; Parameters ....:  $n_Name = The name of the key
;                       $n_Option = Where sould the key be read? (0 = Only on this user, 1 = On all users)
; Errors ........:  0 = Succes
;                       1 = Keyname doenst exists
; Return values .: $n_Read
; Author ........: Almar Mulder (AlmarM)
; Modified.......: -
; Remarks .......: -
; Related .......: RegWrite(), _AddRun(), _DeleteRun()
; Link ..........: -
; Example .......: Yes
;                   $ReadRun = _ReadRun("Test", 1)
;                   MsgBox(64, "_ReadRun()", $ReadRun)
; #FUNCTION# =================================================================================================
Func _ReadRun($n_Name, $n_Option = 0)
    If $n_Option = 0 Then
        $n_HKEY = "HKEY_CURRENT_USER\Software"
    Else
        $n_HKEY = "HKEY_LOCAL_MACHINE\SOFTWARE"
    EndIf
    If RegRead($n_HKEY & "\Microsoft\Windows\CurrentVersion\Run", $n_Name) = False Then
        SetError(1)
    Else
        $n_Read = RegRead($n_HKEY & "\Microsoft\Windows\CurrentVersion\Run", $n_Name)
        SetError(0)
    EndIf
    Return $n_Read
EndFunc     ;==> _ReadRun()

; #FUNCTION# =================================================================================================
; Name...........: _ReadAllRun()
; Description ...: Reads all registery keys in the Run folder
; Syntax.........: _ReadAllRun($n_Option = 0)
; Parameters ....: $n_Option = Where sould the key be read? (0 = Only on this user, 1 = On all users)
; Errors ........: -
; Return values .: $n_Read
; Author ........: Almar Mulder (AlmarM)
; Modified.......: -
; Remarks .......: -
; Related .......: RegWrite(), _AddRun(), _DeleteRun()
; Link ..........: -
; Example .......: Yes
;                   $ReadRun = _ReadAllRun(1)
;                   MsgBox(64, "_ReadAllRun()", $ReadRun)
; #FUNCTION# =================================================================================================
Func _ReadAllRun($n_Option = 0)
    If $n_Option = 0 Then
        $n_HKEY = "HKEY_CURRENT_USER\Software"
    Else
        $n_HKEY = "HKEY_LOCAL_MACHINE\SOFTWARE"
    EndIf
    For $i = 1 To 100
    $n_Read = RegEnumVal($n_HKEY & "\Microsoft\Windows\CurrentVersion\Run", $i)
    Next
    Return $n_Read
EndFunc     ;==> _ReadAllRun()

Hope you enjoy! :)

AlmarM

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...