AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

irrational behaviour on two similar computers (change wp)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Mon Aug 24, 2009 1:01 pm    Post subject: irrational behaviour on two similar computers (change wp) Reply with quote

A script made by ashef which I got from here and then edited to it's current form:
Code:

#SingleInstance Force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
IniRead, WallPaperFolder, %A_ScriptDir%\wpchange.ini, Settings, WPFolder, NOT_SET

If WallPaperFolder = NOT_SET
{
   FileSelectFolder, SetFolder, , 3
   if SetFolder =
   {
      MsgBox, You didn't select a folder, the program will now close.   
      ExitApp
   }
   else
   {
      SetFolder := RegExReplace(SetFolder, "\\$")  ; Removes the trailing backslash, if present.   
      WallPaperFolder = %SetFolder%\
      IniWrite, %WallPaperFolder%, %A_ScriptDir%\wpchange.ini, Settings, WPFolder
      MsgBox Setting saved, to reset choose the "Reset Folder" item from tray, or delete file %A_ScriptDir%\wpchange.ini.
   }
}   

RefreshWPs() ; Make a function of it and call that whenever you need to cut down redundant writing.
{
   Global
   ArrayCount=0
   Loop, D:\Stuff\Images\Walls\*.jpg ; wherever you store your wallpapers
   {
   ArrayCount+=1
   Array%ArrayCount% := A_LoopFileName
   }
}

ChangeWP() ; Make a function of it
{
   global
   Random, filenum, 1, %ArrayCount%
   filecalled := Array%filenum%
   TrayTip,, Setting "%filecalled%" as your wallpaper,,1
   FileCopy, %WallPaperFolder%%filecalled%, %A_MyDocuments%\currentwallpaper.jpg, 1
   DllCall("SystemParametersInfo", UInt, 0x14, UInt, 0, Str, A_MyDocuments . "\currentwallpaper.jpg", 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, Refreshing..., Refreshing Wallpapers...,,1
RefreshWPs()
TrayTip,, Wallpaper list refreshed!,,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, Refreshing..., Refreshing Wallpapers...,,1
   RefreshWPs()
   TrayTip,, Wallpaper list refreshed!,,1
   Return

ChangeWallpaper:
   ChangeWP()
   Return

RstFolder:
   IniWrite, NOT_SET, %A_ScriptDir%\wpchange.ini, Settings, WPFolder
   MsgBox Folder settings reset, please restart app to redefine.
   Return

#MButton::ChangeWP()


The weird thing is, it works perfectly on my computer (running Win7 RC), it reads the list ok and changes wallpaper just fine. read/writes ini ok.

Then, I compiled it (and it still works on my computer, I'm using the compiled one myself.) and gave it to my brother (running Win7 RC). He ran it and it created the ini file just fine. BUT, when he tries to change the wallpaper, nothing happens.

well, when it should display a traytip
Code:
TrayTip,, Setting "%filecalled%" as your wallpaper,,1

I got "Setting "filename" as your wallpaper" and my brother gets "Setting "" as your wallpaper"

My path to the images is "D:\Stuff\Images\Walls" and his is "D:\Kuvat\Muut\Wallpapers". So even the paths are similar (no spaces or funny characters). Only real difference is, I have AHK installed and he doesn't, but I don't think it *should* at least matter.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
engunneer



Joined: 30 Aug 2005
Posts: 7698
Location: Germany (but I only speak English)

PostPosted: Mon Aug 24, 2009 1:05 pm    Post subject: Reply with quote

Change
Code:

TrayTip,, Wallpaper list refreshed!,,1
;To
TrayTip,, Wallpaper list refreshed! (%ArrayCount% Found),,1

to see if his finds any pictures.

The fastest solution might be to connect with him over something like CrossLoop or VNC to see if you can debug it on his machine.
_________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me.
Back to top
View user's profile Send private message Visit poster's website
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Mon Aug 24, 2009 1:13 pm    Post subject: Reply with quote

I don't need VNCs or the like, his computer is like 30cm away from mine Very Happy
I added a "debug button" (listvars) to the script and I'm going to see just that, if it finds any wallpapers.

If it doesn't then I'm f***ed, since I have no idea why it wouldn't find any. Smile
But he's busy right now so I can't test it at the moment. Well, busy playing WoW, but try telling him AHK scripting is way more fun than playing wow Razz
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
engunneer



Joined: 30 Aug 2005
Posts: 7698
Location: Germany (but I only speak English)

PostPosted: Mon Aug 24, 2009 1:14 pm    Post subject: Reply with quote

VNC can still be a fun trick...
_________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me.
Back to top
View user's profile Send private message Visit poster's website
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Mon Aug 24, 2009 1:15 pm    Post subject: Reply with quote

HAHA Very Happy Yes, indeed. Razz
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Mon Aug 24, 2009 1:49 pm    Post subject: Reply with quote

Tested there, the script just doesn't find any wallpapers what so ever.

ListVars from mine

Code:

Global Variables (alphabetical)
--------------------------------------------------
0[1 of 3]: 0
;Array1-Array193 the individual wallpapers
ArrayCount[3 of 3]: 193
ErrorLevel[1 of 3]: 0
filecalled[12 of 63]: Car (84).jpg
filenum[2 of 3]: 73
SetFolder[0 of 0]: 
Str[0 of 0]: 
UInt[0 of 0]: 
WallPaperFolder[22 of 63]: D:\Stuff\Images\walls\


His:
Code:

Global Variables (alphabetical)
--------------------------------------------------
0[1 of 3]: 0
ArrayCount[1 of 3]: 0
ErrorLevel[1 of 3]: 0
filecalled[0 of 0]: 
filenum[0 of 0]: 
SetFolder[0 of 0]: 
Str[0 of 0]: 
UInt[0 of 0]: 
WallPaperFolder[25 of 63]: D:\Kuvat\Muut\Wallpapers\


No idea anymore.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Mon Aug 24, 2009 1:51 pm    Post subject: Reply with quote

ARGH! nevermind, I'm being so stupid I hate to admit it Very Happy Very Happy Very Happy
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
engunneer



Joined: 30 Aug 2005
Posts: 7698
Location: Germany (but I only speak English)

PostPosted: Mon Aug 24, 2009 1:53 pm    Post subject: Reply with quote

My guess is that you forgot to turn this line to a variable reference?
Code:
Loop, D:\Stuff\Images\Walls\*.jpg ; wherever you store your wallpapers

_________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me.
Back to top
View user's profile Send private message Visit poster's website
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Mon Aug 24, 2009 2:02 pm    Post subject: Reply with quote

Yes, you're right Very Happy oh geez, I feel stupid.

But, there's a slight problem yet again... Now it seemingly works ok. It finds 85 pictures, lists them ok (ListVars), sets the reg key correctly (when I check what wallpaper is currently selected in Personalize.) But it just doesn't really change the wallpaper. I guess the FileCopy isn't doing it's just, but running the compiled script as admin didn't change anything.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
engunneer



Joined: 30 Aug 2005
Posts: 7698
Location: Germany (but I only speak English)

PostPosted: Mon Aug 24, 2009 2:04 pm    Post subject: Reply with quote

Is the jpg being replaced?

If you delete the jpg, can the script rewrite it?

A_IsAdmin is 1?
_________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me.
Back to top
View user's profile Send private message Visit poster's website
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Mon Aug 24, 2009 2:11 pm    Post subject: Reply with quote

A_IsAdmin is 1 yes.
But, the currentwallpaper.jpg file isn't being created in the first place. And I don't get it why?

After stupid variable corrections and typo fixes, here's the current version of the script:
Code:

#SingleInstance Force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
IniRead, WallPaperFolder, %A_ScriptDir%\wpchange.ini, Settings, WPFolder, NOT_SET

If WallPaperFolder = NOT_SET
{
   FileSelectFolder, SetFolder, , 3
   if SetFolder =
   {
      MsgBox, You didn't select a folder, the program will now close.   
      ExitApp
   }
   else
   {
      SetFolder := RegExReplace(SetFolder, "\\$")  ; Removes the trailing backslash, if present.   
      WallPaperFolder = %SetFolder%\
      IniWrite, %WallPaperFolder%, %A_ScriptDir%\wpchange.ini, Settings, WPFolder
      MsgBox Setting saved. To reset, choose the "Reset Folder" item from tray or delete file %A_ScriptDir%\wpchange.ini.`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() ; Make a function of it and call that whenever you need to cut down redundant writing.
{
   Global
   ArrayCount=0
   Loop, %WallPaperFolder%*.jpg ; wherever you store your wallpapers
   {
   ArrayCount+=1
   Array%ArrayCount% := A_LoopFileName
   }
}

ChangeWP() ; Make a function of it
{
   global
   Random, filenum, 1, %ArrayCount%
   filecalled := Array%filenum%
   TrayTip,, Setting "%filecalled%" as your wallpaper,,1
   FileCopy, %WallPaperFolder%%filecalled%, %A_MyDocuments%\currentwallpaper.jpg, 1
   DllCall("SystemParametersInfo", UInt, 0x14, UInt, 0, Str, A_MyDocuments . "\currentwallpaper.jpg", 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, Refreshing..., Refreshing Wallpapers...,,1
RefreshWPs()
TrayTip,, 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, Refreshing..., Refreshing Wallpapers...,,1
   RefreshWPs()
   TrayTip,, Wallpaper list refreshed! (%ArrayCount% Found),,1
   Return

ChangeWallpaper:
   ChangeWP()
   Return

RstFolder:
   IniWrite, NOT_SET, %A_ScriptDir%\wpchange.ini, Settings, WPFolder
   MsgBox, 52, Wallpaper Changer, Folder settings reset to defaults. To choose a new folder`, the program must be restarted. Do you want to close the application now?
   IfMsgBox Yes
      ExitApp
   Return

#MButton::ChangeWP()
^!Numpad0::MsgBox %A_IsAdmin%
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
engunneer



Joined: 30 Aug 2005
Posts: 7698
Location: Germany (but I only speak English)

PostPosted: Mon Aug 24, 2009 2:14 pm    Post subject: Reply with quote

try setting to a different wallpaper then back to the jpg, and see if it sticks.

Refresh the desktop with F5?
_________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me.
Back to top
View user's profile Send private message Visit poster's website
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Mon Aug 24, 2009 2:25 pm    Post subject: Reply with quote

The thing is, the FileCopy line doesn't create the jpg at all. the currentwallpaper.jpg file is nowhere to be found at any time. I checked the A_MyDocuments variable if Win7's default path is some curious path, but its just a normal "C.\Users\username\Documents" and his username is just one word, no spaces. So its a perfectly legal path from any angle.

As the DllCall line sets the wallpaper ok (you can see the new wallpaper if you right-click desktop, choose personalize and check the lower part of the appearing window - this in Win7). It's just that the FileCopy apparently fails, and I have no idea why. It's running as admin (and it's the user's own documents folder in the first place), so I really don't think it's a case of limited permissions.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
engunneer



Joined: 30 Aug 2005
Posts: 7698
Location: Germany (but I only speak English)

PostPosted: Mon Aug 24, 2009 2:27 pm    Post subject: Reply with quote

ErrorLevel?
_________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me.
Back to top
View user's profile Send private message Visit poster's website
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Mon Aug 24, 2009 2:34 pm    Post subject: Reply with quote

Yep, FileCopy returns ErrorLevel 1, so it apparently is that what fails. But why? Why can't it copy the file?

EDIT: the documents folder in question has Full Access for SYSTEM, Administrators-group and the Owner in question (user).


Last edited by AnttiV on Mon Aug 24, 2009 2:39 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group