Need help on a System Call - $25 reward! :)

Blitz3D Forums/Blitz3D Programming/Need help on a System Call - $25 reward! :)

Midnight(Posted 2008) [#1]
[Note: solution has been found and posted - scroll down a few posts for download.]


Hi all,

I need a little help converting a C++ system call to Blitz3D. I don't think it should be a big deal, but I'm horrible at these things. If someone were willing to do this, I'd be happy to
a) paypal him/her $25 for games/pizza/beer/etc as a token of appreciation
b) post the resulting code here so that anyone else in the community can use it for free.

The code in question is related to giving Blitz programs full-write access to common user folders (this is almost a requirement for Vista, given that you simply can no longer write to the "Program Files" directory without resulting in files being virtualized and other headaches).

The code itself is used in a BlitzMax version by Grey Alien, and is discussed here:
http://www.blitzbasic.co.nz/Community/posts.php?topic=73305

(and yes, I've asked for Grey's permission to do this before posting here)

Specifically, I need the B3d equivalent of this C++ code (or a way to run this from Blitz3D the way Grey runs it from BlitzMax):


[CODE]
#include <windows.h>
#include <aclapi.h>

extern "C" bool GiveDirectoryUserFullAccess(LPCTSTR lpPath)
{
HANDLE hDir = CreateFile(lpPath,READ_CONTROL|WRITE_DAC,0,NULL,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,NULL);
if(hDir == INVALID_HANDLE_VALUE) return false;

ACL* pOldDACL=NULL;
SECURITY_DESCRIPTOR* pSD = NULL;
GetSecurityInfo(hDir,SE_FILE_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,&pOldDACL,NULL,&pSD);

EXPLICIT_ACCESS ea={0};
ea.grfAccessMode = GRANT_ACCESS;
ea.grfAccessPermissions = GENERIC_ALL;
ea.grfInheritance = CONTAINER_INHERIT_ACE|OBJECT_INHERIT_ACE;
ea.Trustee.TrusteeType = TRUSTEE_IS_GROUP;
ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME;
ea.Trustee.ptstrName = TEXT("Users");

ACL* pNewDACL = NULL;
SetEntriesInAcl(1,&ea,pOldDACL,&pNewDACL);

SetSecurityInfo(hDir,SE_FILE_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,pNewDACL,NULL);

LocalFree(pSD);
LocalFree(pNewDACL);
CloseHandle(hDir);
return true;
}
[/CODE]

The code is designed to set a directory to "full access", which is required for other users to write/modify files originally created on a different user profile.

If you can do this, please let me know (e-mail to midnight@...).

Cheers,
Patrick


Vertigo(Posted 2008) [#2]
Try doing an exec command to call and external command file..

something like this http://support.microsoft.com/kb/318754

Im not entirely sure that works under vista... but im sure you could find some app that will change the folder permissions from the command like... of course the end user will be prompted once for "do you wish to allow" blah blah... after that the folder should be writable by blitz.

May be a lot easier that hacking some other code up.


Kev(Posted 2008) [#3]
check your mail Midnight.

kev


puki(Posted 2008) [#4]
Hey, "Kev" - can I have the prize?

I need the food.

Email in sig.

I'll spend it on pizza.

Thanks.


John Blackledge(Posted 2008) [#5]
Puki, you didn't do anything!


Midnight(Posted 2008) [#6]
Alright, Kev was able to solve this for me. As promised, here is the code to enable write access (also includes a function to find special folder locations), for anyone else to use.

Many thanks!

http://www.midnightsynergy.com/other/blitz3d_folder_access.zip

Cheers,
Patrick


Ross C(Posted 2008) [#7]
Thanks for sharing this. Very generous :o)


Kev(Posted 2008) [#8]
I got my reward and a tip :) very generous patrick


Who was John Galt?(Posted 2008) [#9]
I like your style, Midnight. If only more people offered cash rewards!!!


nrasool(Posted 2008) [#10]
Hi Midnight, Thanks for that, but just a question please, How comes you didn't use the following to get the folder in Vista and My document.

I used it and it works fine in Blitz3d:
http://www.blitzbasic.com/Community/posts.php?topic=69963#783368

Just pondering really :)


Midnight(Posted 2008) [#11]
nrasool - the code I needed was to make that folder write-accessible to all users. Kev was kind enough to add the other part (getting the folder location) into the same dll.


nrasool(Posted 2008) [#12]
Ahhh that is really useful!, Many thanks for explaining that :)