Jump to content

Startup Applications


Recommended Posts

Hi, I am trying to create a txt file which will include all startup applications.

I have managed to do so, but it only works in Windows 7.

I get this error while trying to run it in Windows XP:

---------------------------
AutoIt Error
---------------------------
Line 1119  (File "C:\Documents and Settings\user\Desktop\1.exe"):


Error: Subscript used with non-Array variable.
---------------------------
OK   
---------------------------

Any Ideas ?

#include <array.au3>
#include <file.au3>

FileOpen("1.txt", 1)
$StartupInfo = FileOpen("1.txt", 1)

FileWrite($StartupInfo, "Startup Applications:" & @CRLF & @CRLF & @CRLF)
Func _LogStartupItems($_outputFile, $_runKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
    Local $_itemCount = 1
    Local $_itemPath
    Local $_itemName = RegEnumVal($_runKey, $_itemCount)
    While Not @error
        $_itemCount += 1
        $_itemPath = RegRead($_runKey, $_itemName)
        If Not @error Then
            FileWriteLine($_outputFile, $_itemName & "  ---  " & $_itemPath)
        EndIf
        $_itemName = RegEnumVal($_runKey, $_itemCount)
    WEnd
EndFunc
Dim $myStartupKeys[5]
$myStartupKeys[0] = 4
$myStartupKeys[1] = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
$myStartupKeys[2] = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce"
$myStartupKeys[3] = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run"
$myStartupKeys[4] = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce"

For $i = 1 To $myStartupKeys[0]
    _LogStartupItems($StartupInfo, $myStartupKeys[$i])
Next

$Location = @StartupDir
$FileList = _FileListToArray($Location, "*", 1)
If @error Then
Endif
Local $FileOpen = $StartupInfo, $Data
For $i = 1 To $FileList[0]
    $GShortcut = FileGetShortcut($Location & "\" & $FileList[$i])
    $Data &= $FileList[$i] & " - " & $GShortcut[0] & @CRLF
Next
FileWrite($StartupInfo, $Data)
FileClose($FileOpen)
FileClose($StartupInfo)

Thanks in advance!

Link to comment
Share on other sites

From what I gather, this is due to a lack of error checking.

Always check @error after a function.

In this case, you were using FileGetShortcut() without error checking, so when you ran into a file that wasn't a shortcut, it calls an array that doesn't exist.

Added error checking to the FileGetShortcut() area.

#include <array.au3>
#include <file.au3>

FileOpen("1.txt", 1)
$StartupInfo = FileOpen("1.txt", 1)

FileWrite($StartupInfo, "Startup Applications:" & @CRLF & @CRLF & @CRLF)
Func _LogStartupItems($_outputFile, $_runKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
    Local $_itemCount = 1
    Local $_itemPath
    Local $_itemName = RegEnumVal($_runKey, $_itemCount)
    While Not @error
        $_itemCount += 1
        $_itemPath = RegRead($_runKey, $_itemName)
        If Not @error Then
            FileWriteLine($_outputFile, $_itemName & "  ---  " & $_itemPath)
        EndIf
        $_itemName = RegEnumVal($_runKey, $_itemCount)
    WEnd
EndFunc
Dim $myStartupKeys[5]
$myStartupKeys[0] = 4
$myStartupKeys[1] = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
$myStartupKeys[2] = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce"
$myStartupKeys[3] = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run"
$myStartupKeys[4] = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce"

For $i = 1 To $myStartupKeys[0]
    _LogStartupItems($StartupInfo, $myStartupKeys[$i])
Next

$Location = @StartupDir
$FileList = _FileListToArray($Location, "*", 1)
If @error Then
Endif
Local $FileOpen = $StartupInfo, $Data
For $i = 1 To $FileList[0]
    $GShortcut = FileGetShortcut($Location & "\" & $FileList[$i])
    If @error Then
        $Data &= $FileList[$i] & " - <NOT A SHORCUT>" & @CRLF
    Else
        $Data &= $FileList[$i] & " - " & $GShortcut[0] & @CRLF
    EndIf
Next
FileWrite($StartupInfo, $Data)
FileClose($FileOpen)
FileClose($StartupInfo)
Link to comment
Share on other sites

I believe this

For $i = 1 To $myStartupKeys[0]

might work better like

For $i = 1 To Ubound($myStartupKeys)-1

also same with

For $i = 1 To $FileList[0]

you also have

$FileList = _FileListToArray($Location, "*", 1)

If @error Then

Endif

which really does nothing, try

$FileList = _FileListToArray($Location, "*", 1)

If Not @error Then

Local $FileOpen = $StartupInfo, $Data

For $i = 1 To $FileList[0]

$GShortcut = FileGetShortcut($Location & "\" & $FileList[$i])

$Data &= $FileList[$i] & " - " & $GShortcut[0] & @CRLF

Next

Endif

Also you don't need to FileOpen 1.txt 2x

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Another way is to copy all keys and values from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run using regread, store them in an array, and write the same in a notepad file....

This may work for Windows XP as I have the same OS. :)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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...