I double-checked, and then again double-checked my double-check

My Error-MsgBox displays the right number of backslashes, my LastCopy-MsgBox does to, and also ListVars are all correct. The copy just plain fails.
I'm out of ideas. I need to check this at my XP machines too, if it works there, I'm going to blame my brother for messing up his comp
Here's the as-of-now final version:
Code:
; Initial Preferences
#SingleInstance Force
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
; Few global variables
IniFile = %A_ScriptDir%\wpchange.ini
TempWallpaper = %A_MyDocuments%\currentwallpaper.jpg
IniRead, WallPaperFolder, %IniFile%, Settings, WPFolder, NOT_SET ; Read settings from IniFile
If WallPaperFolder = NOT_SET ; If there is no IniFile, or it's set for Reset
{
FileSelectFolder, SetFolder, , 3 ; Show a folder for the wallpapers
if SetFolder =
{
MsgBox, You didn't select a folder, the program will now close. ; We can't function without a folder, if the user didn't select one, exit.
ExitApp
}
else
{
SetFolder := RegExReplace(SetFolder, "\\$") ; Removes the trailing backslash, if present.
WallPaperFolder = %SetFolder%\ ; We need the trailing backslash for our purposes, but removing it first eliminates the possibility of dual slashes.
IniWrite, %WallPaperFolder%, %IniFile%, Settings, WPFolder ; Now that we have all the settings, write them to IniFile so we don't need to ask them again at relaunch
MsgBox Setting saved. To reset, choose the "Reset Folder" item from tray or delete file %IniFile%.`n`nYou can now change your wallpaper at will by pressing "Win+MiddleMouseButton". The program will select a random image from the folder you provided and set it as your wallpaper.
}
}
RefreshWPs()
{
Global
ArrayCount=0
Loop, %WallPaperFolder%*.jpg ; check all jpg images in the WallpaperFolder
{
ArrayCount+=1
Array%ArrayCount% := A_LoopFileName ; Make an array of all the available filenames
}
}
ChangeWP()
{
global
Random, filenum, 1, %ArrayCount%
filecalled := Array%filenum% ; select a random image to be set as the new paper
TrayTip, Wallpaper Changer, Setting "%filecalled%" as your wallpaper,,1
FileCopy, %WallPaperFolder%%filecalled%, %TempWallpaper%, 1 ; copy the file to a temp location
FileCopyError = %ErrorLevel%
If ErrorLevel = 1
{
MsgBox While copying %WallPaperFolder%%filecalled% to a temporary location at %TempWallpaper%, a FileCopy error occured, please contact the developer!
}
DllCall("SystemParametersInfo", UInt, 0x14, UInt, 0, Str, TempWallpaper, UInt, 2)
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, WallPaper, %WallPaperFolder%%filecalled%
Sleep, 500 ; can't change the wallpaper too quickly in succession.
return
}
Traytip, Wallpaper Changer, Refreshing Wallpapers...,,1
RefreshWPs()
TrayTip, Wallpaper Changer, Wallpaper list refreshed! (%ArrayCount% Found),,1
Menu, TRAY, Add
Menu, TRAY, Add, Refresh Wallpapers, RefreshWallpapers ; Manual refresh
Menu, TRAY, Add, Change Wallpaper, ChangeWallpaper ; Add a menu for it too
Menu, TRAY, Add
Menu, TRAY, Add, Reset Folder, RstFolder ; Add menu for resetting folder
Return ; Ends the auto-execute section
RefreshWallpapers: ; does the same job as the auto-execute
Traytip, Wallpaper Changer, Refreshing Wallpapers...,,1
RefreshWPs()
TrayTip, Wallpaper Changer, Wallpaper list refreshed! (%ArrayCount% Found),,1
Return
ChangeWallpaper:
ChangeWP()
Return
RstFolder:
MsgBox, 52, Wallpaper Changer, Resetting folder settings requires program restart. You can choose new folder on next launch. Do you want to reset the settings and close the application now?
IfMsgBox Yes
{
IniWrite, NOT_SET, %IniFile%, Settings, WPFolder ; Set the WPFolder as "NOT_SET" so next launch the user can choose a new folder.
ExitApp
}
Else
{
TrayTip, Wallpaper Changer, Reset cancelled. Nothing done!,,1 ; Inform the user that we did nothing when "No" was clicked.
}
Return
#MButton::ChangeWP()
; Debug Stuff
^!Numpad0::MsgBox IsAdmin: %A_IsAdmin% - My Documents: %A_MyDocuments%
^!Numpad1::ListVars
^!Numpad2::MsgBox Last Copy: "%WallPaperFolder%%filecalled%" to "%A_MyDocuments%\currentwallpaper.jpg"
I made a few more user-friendly modifications to it. And changed a few hard-coded things to variables. for easier modification later.
EDIT: It now works. Beats me how it had happened, but somewhere along the line Windows had decided that the currentwallpaper.jpg file should be given all available flags (+System, +Hidden, +ReadOnly, +Archive) and so the script couldn't overwrite it. Neither did explorer show it, and neither did "dir" at the command prompt. I finally figured it out when I tried to manually make a file called like that in the folder and it asked me if I wanted to overwrite it... so it took a "dir /ah" to finally found the file and a "attrib -s -r -h- a" followed by "del" to finally get rid of the culprit. Now it works perfectly.
Sorry to have bothered you so much in what essentially was nothing you could figure out

Well at least the script is better now
