Problem saving to Scripts folder in MM4 due to UAC

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

twinbee
Posts: 180
Joined: Tue May 13, 2008 2:36 am
Location: England
Contact:

Problem saving to Scripts folder in MM4 due to UAC

Post by twinbee » Sun Nov 27, 2011 4:58 am

My script MegaDJ doesn't just read from the Scripts folder, but also saves to it. I use MM's given path "SDB.ScriptsPath". Unfortunately, due to Microsoft's over-cautious and messy policy of not allowing files to be easily written to their own program folder (if inside Program Files), this now throws an error under MM4, at least in Vista/Windows 7:
Error #70 - Microsoft VBScript runtime error
Permission denied
File: "C:\Program Files\MediaMonkey4Demo\Scripts\Auto\MegaDJ.vbs"
So now, I'm wondering which 'magic' location I should save it under, preferably using a reference style command like "SDB.UserSettingsPath" (though obviously that won't work). It should obviously work from WinXP through to Win 7.
MegaDJ v2 - Lightning fast and easy to use search to replace the standard AutoPlaylist. Features include random jukebox style playlists, along with syncing, weighting options, and logic complete querying.

Thanasis
Posts: 84
Joined: Sun Aug 28, 2011 2:53 am

Re: Problem saving to Scripts folder in MM4 due to UAC

Post by Thanasis » Sun Nov 27, 2011 6:45 am

I had the same problem for my script. I really asked some developers here as to how I can resolve this issue....
Unfortunately there is no a magic answer and you need to use some extra code.

If you want to write a Proffessional code then you also have to take seriously 2 things.
1st. To include in your uninstaller the path or names of your created files.
2nd To take into account the possibility that the user chooses a Portable Version of Media Monkey.

No, you will always get problems with simply using SDB.UserSettingsPath / Windows 7 / and MM Full Installation.

I also need a code to do this and if you want you can help me and help you. I can make a start with the layout of the code. There is a "Full Installation" %appdata%\MediaMonkey folder created in case it is NOT potable. Run the following script externally (.vbs)
' ***********Check if MM is portable or full by checking if an %appdata%\MediaMonkey folder is created************
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")
appdatadir = shell.ExpandEnvironmentStrings("%appdata%")
sFilePath = appdatadir & "\MediaMonkey"
' You need to do this for portable version

If oFSO.FolderExists(sFilePath) then
MsgBox "MM is Full and Not Portable"
' **** we can use the %appdata%\MediaMonkey in this case
Else
MsgBox "MM is running Portable (if it is running)"
' ***** we can use the SDB.UserSettingsPath in this case
' ***** but there is a chance that the user installed the code in "program files" folder
' ***** which means that additional code is needed here (not provided)
End If
So in the second case "MM is running Portable (if it is running)" we need to develop some similar extra code that checks if the Portable Version is installed in the SystemDrive (\Program Files) Folder. Otherwise if MM portable is not installed in that folder we can use the SDB.UserSettingsPath command safely. Otherwise if MM is full then we can use the path to the %appdata%\MediaMonkey folder that is illustrated in the code above.

There is a chance that MM portable sets the Write Permissions in some folders within the SystemDrive (\Program Files) so we can safely use the SDB.UserSettingsPath safely in this case. (Somebody needs to check)

Other than that I don't find any better way to do this job.
(Man by the way do you have any idea on my problem here? http://www.mediamonkey.com/forum/viewto ... 19&t=62318 Thanks )

Thanasis
Posts: 84
Joined: Sun Aug 28, 2011 2:53 am

Re: Problem saving to Scripts folder in MM4 due to UAC

Post by Thanasis » Sun Nov 27, 2011 6:53 am

Ohhh I forgot to say that the Magic Location for Full installation is %appdata%\MediaMonkey\Scripts\Auto\MegaDJ.vbs

And I also forgot to say is that if you don't read and write on files within your code you can use Installation method presented here:

http://www.mediamonkey.com/wiki/index.p ... n_Packages

Thanasis
Posts: 84
Joined: Sun Aug 28, 2011 2:53 am

Re: Problem saving to Scripts folder in MM4 due to UAC

Post by Thanasis » Sun Nov 27, 2011 3:18 pm

Well, I am coming with a "sure" way of finding out which folder to use. This method is introduced in MM4. So no more compatibilities with previous versions!

Code: Select all

SDB.CurrentAddonInstallRoot 
If you use an installer you will not even need the code I have just suggested above. But for "settings" files etc be aware that paths change between normal and Portable MM installations....

The method SDB.CurrentAddonInstallRoot returns exactly the same path as {app} used in the installation method.

Take care

twinbee
Posts: 180
Joined: Tue May 13, 2008 2:36 am
Location: England
Contact:

Re: Problem saving to Scripts folder in MM4 due to UAC

Post by twinbee » Mon Nov 28, 2011 11:12 am

Hi Thanasis,

Thanks a lot for those. The CurrentAddonInstallRoot function looks great. However, I'd like my script to work with Mediamonkey v3 as well, so I may use your previous recommendation, even though the code is a bit longer. What do you think?

Anthony came up with an idea here too:
http://mediamonkey.com/forum/viewtopic. ... 40#p320540
MegaDJ v2 - Lightning fast and easy to use search to replace the standard AutoPlaylist. Features include random jukebox style playlists, along with syncing, weighting options, and logic complete querying.

Thanasis
Posts: 84
Joined: Sun Aug 28, 2011 2:53 am

Re: Problem saving to Scripts folder in MM4 due to UAC

Post by Thanasis » Mon Nov 28, 2011 1:57 pm

Hi friend.

I have seen Anthony's idea, which is great. His idea ( just like the CurrentAddonInstallRoot function) will work on both Full and Portable versions. In portable versions MM will report a different folder within the "portable" folder.

My idea above is safe but a bit too bulky. Just check in wiki if functions in ANthony;s idea work on MM 3....

Take care

twinbee
Posts: 180
Joined: Tue May 13, 2008 2:36 am
Location: England
Contact:

Re: Problem saving to Scripts folder in MM4 due to UAC

Post by twinbee » Tue Nov 29, 2011 10:16 am

This was trickier than I expected.

For (non-portable) MediaMonkey 3, the MM.DB database path was:
C:/Users/<user>/AppData/Local/MediaMonkey

However, it contained no Scripts folder inside that. Instead the scripts path is located:
<MM3 standard installation path>/Scripts

Obviously, Anthony's code will predict:
C:/Users/<user>/AppData/Local/MediaMonkey/Scripts



The portable version of MediaMonkey 4 was different too. Here the database path was:
<MM4 portable installation path>/Portable/

The actual scripts path is:
<MM4 portable installation path>/Scripts

And Anthony's code will instead predict this:
<MM4 portable installation path>/Portable/Scripts



Unfortunately, the only one which works is the standard non-portable MM4 installation:

Database path:
C:/Users/<user>/AppData/Roaming/MediaMonkey

The actual scripts path is:
C:/Users/<user>/AppData/Roaming/MediaMonkey/Scripts

And Anthony's code will predict this:
C:/Users/<user>/AppData/Roaming/MediaMonkey/Scripts

...which is of course the same as the actual script path, which is why MM4 non-portable works fine.




Okay this is tricky...

One plan is to simply save where the database is, and then create my own folder along with MM.DB in there. However, this could change in future, and if people upgrade from MM3 or portable, then my program's data will be lost again for the new version.

I'm beginning to think I should step out of Mediamonkey's location of where it's 'supposed to go', and instead just rely on my own independent location (I think your former longer code with %appdata% is a good direction here). Apart from avoiding the need to specialize for each case of Mediamonkey (3, 4, 4-portable), it also means I'll be safe if Mediamonkey decides to change paths again ;)
Last edited by twinbee on Wed Nov 30, 2011 3:02 am, edited 1 time in total.
MegaDJ v2 - Lightning fast and easy to use search to replace the standard AutoPlaylist. Features include random jukebox style playlists, along with syncing, weighting options, and logic complete querying.

twinbee
Posts: 180
Joined: Tue May 13, 2008 2:36 am
Location: England
Contact:

Re: Problem saving to Scripts folder in MM4 due to UAC

Post by twinbee » Wed Nov 30, 2011 2:45 am

Okay this is probably what I'll be using. It seems to work fine so far with MM3, MM4, and MM4 portable.

If it's portable, it will save under the SDB.ScriptsPath. If it isn't portable, it will create a new folder under %appdata%, a location completely independent of Mediamonkey, and is therefore I think a much safer way, limiting possible 'surprises' :) . Let me know what you think, and thanks again for your help!

Code: Select all

	Dim settingsPath
	isPortable = instr(SDB.Database.Path, SDB.ApplicationPath)	' Checks if the Application path string is contained inside the DataBase path string
	if(isPortable=false) Then
		MsgBox("not portable")
		Set oFSO = CreateObject("Scripting.FileSystemObject")
		Set shell = CreateObject("WScript.Shell")
		settingsPath = shell.ExpandEnvironmentStrings("%appdata%") & "\<YOURSOFTWARENAME>\"
		set objFSO = createobject("Scripting.FileSystemObject")
		If objFSO.FolderExists(settingsPath) = False then
			objFSO.CreateFolder(settingsPath)
		end if
	Else
		MsgBox("portable")
		settingsPath = SDB.ScriptsPath & "Auto\"
	End if
	MsgBox("final settings path: "+settingsPath)
MegaDJ v2 - Lightning fast and easy to use search to replace the standard AutoPlaylist. Features include random jukebox style playlists, along with syncing, weighting options, and logic complete querying.

Thanasis
Posts: 84
Joined: Sun Aug 28, 2011 2:53 am

Re: Problem saving to Scripts folder in MM4 due to UAC

Post by Thanasis » Tue Dec 06, 2011 3:52 am

Good thinking mate but I have my doubts.

There is one problem. The Database path is user customizable. This means that if the user changes the path in .ini file your script will no longer be solid.
This is why I recommend the ungly but working solid shell %appdata% method.

I guess the only locked place is c:/program files/ in windows 7.... If you check against system program folder then you are safe.....

My 2 euro cents.....

Thanasis
Posts: 84
Joined: Sun Aug 28, 2011 2:53 am

Re: Problem saving to Scripts folder in MM4 due to UAC

Post by Thanasis » Tue Dec 06, 2011 4:00 am

Well another idea that just came in my mind and it looks the best of all.

Check for the folder SDB.ApplicationPath & "Portable".

The portable version makes this folder..... But also look for System/Program Files folder because in case portable is installed in this file, you will still get the UAC problems !!!

My 2 x 2 Euro Cents

twinbee
Posts: 180
Joined: Tue May 13, 2008 2:36 am
Location: England
Contact:

Re: Problem saving to Scripts folder in MM4 due to UAC

Post by twinbee » Wed Dec 07, 2011 5:01 am

Thanks for the extra info. Am I right in saying that your idea is just to determine whether MM is portable or not, and therefore is the rest of my code okay?

Would my code potentially break for non-portable users, portable, or both?

I doubt many people would install the portable version in the Program Files folder, so if it just breaks for people, that would only be a tiny perecentage of users....
MegaDJ v2 - Lightning fast and easy to use search to replace the standard AutoPlaylist. Features include random jukebox style playlists, along with syncing, weighting options, and logic complete querying.

Thanasis
Posts: 84
Joined: Sun Aug 28, 2011 2:53 am

Re: Problem saving to Scripts folder in MM4 due to UAC

Post by Thanasis » Wed Feb 22, 2012 11:34 am

No it won't break. But make sure that you define the right path to any supportive to your main code files.

The line

Code: Select all

SDB.ScriptsPath 
reports the path of the currently running script. So it will report the path of the installed script in any portable MM path.

It is the best and easiest way to day to get the path of your files. So the method I first presented in this thread, is not necessarily the best.

If you zip your code into an MM installer (.mmip) Media Monkey 4 will install your code into a folder that is not limitted to UAC.

Then you can get that path using "SDB.ScriptsPath"

So, this is simpler than the method I exhibited above...

Take care all

Thanasis
Posts: 84
Joined: Sun Aug 28, 2011 2:53 am

Re: Problem saving to Scripts folder in MM4 due to UAC

Post by Thanasis » Thu Apr 19, 2012 3:06 am

Today I have got a glitch on the behaviour of MM4.03

Same command SDB.ScriptsPath is used between C# and vbScript (MediaMonkey's auto folder) and:

The output in C# is:______ “C:\Program Files\MediaMonkey\Scripts”
The output in vbScript is: “C:\Documents and Settings\Administrator\Application Data\MediaMonkey\Scripts”.

MM Ver.4.0.3.1476

Thanks

(OK. For some reason, now it has fixed itself. STRANGE....."

Post Reply