Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Vista kills app
Message
De
09/07/2007 17:19:33
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Vista
Database:
Visual FoxPro
Divers
Thread ID:
01192452
Message ID:
01238729
Vues:
15
Hi Vidar, No, I ended up modifying my app to allow the data location to be specified by the user, and I don't allow them to install it under "Program Files". It wasn't as much work as I thought it would be, and it added some benefit since now users can specify a location for the data, on the network or even a USB memory device, if they wish. I created a small routine that checks for Windows Administrator level privs which is called before each function in my app that either writes to the registry HKLM or updates any files in the app install folder. If the level is not sufficient it displays a message telling the user how to run "As Admin" and that this is required to proceed.
Also, I had to decide where the default location for the data should be, I decided to make it "C:\Data\[app name]\", since the data needs to be shareable by any user on the machine and I wanted to avoid burying it way down in a Docs and Settings folder tree. So, I do create a new folder, - called C:\Data or wherever the user chooses to store the data upon app install. Also, since I have many customers who already had previous versions of the app with the data located in \program files\ I needed to add an option under the File menu to "Change Database Location". This was a little work to get it working flawlessly, but I'm happy I went this route. If you have a distributed app to the masses, I would suggest the effort, as users expect to install their apps into Program Files. Otherwise, you might want to take the easy route and change your app install location to something like "C:\Programs\".
I've included my "admin level check" routine here that works with Vista, XP and hopefully Win2K. I haven't been able to test this on Win2000, that part of the code was taken from another thread noted in the comments. If anyone can test this on Win2000 please let me know. -Mark
* UserIsAdmin.prg
* Check if user is running 'As Administrator'.
* pass:
*	m.tcFunc =		Optional Function name to display in msg if don't have admin priv.
* return:
*	1=user is admin. 0=not admin (message is displayed). -1=error occured

LPARAMETERS m.tcFunc

LOCAL m.lnRet, m.lcBufPtr, m.lcUserName, m.lnLevel, m.lcBuffer

IF OS(3) + OS(4) < "51"			&& if before winXP (win2000, nt, me or 95)
	* taken from ut thread 825698: http://www.levelextreme.com/wconnect/wc.dll?2,15,825698
	* hmmm. i tested it on vista non admin level and it wrongly returned 1. maybe works on win2000?
	#define USER_PRIV_GUEST     0
	#define USER_PRIV_USER      1
	#define USER_PRIV_ADMIN     2

	DECLARE Long NetUserGetInfo IN Netapi32.dll ;
	  	String servername, String username, ;
	    Long level, String @ bufptr
	DECLARE Long NetApiBufferFree IN Netapi32.dll String @ Buffer

	lcBufPtr = REPLICATE(CHR(0), 4)
	* Convert user name to Unicode
	lcUserName = STRCONV(SUBSTR(SYS(0), ATC("#", SYS(0)) + 2), 5) + CHR(0)
	lnLevel = 1

	IF NetUserGetInfo(0, lcUserName, lnLevel, @lcBufPtr) <> 0
		* Error
		= MESSAGEBOX("Please contact support. Cannot determine Admin privilege")
		RETURN -1
	ENDIF
	* Retrieve USER_INFO_1 buffer into string
	lcBuffer = SYS(2600, Long2Num(lcBufPtr), 32)
	* Check privileges

	IF BITAND(ASC(SUBSTR(lcBuffer, 13, 1)), USER_PRIV_ADMIN) > 0 
		m.lnRet= 1
	ELSE
		m.lnRet= 0
	ENDIF	
	* Free buffer
	= NetApiBufferFree(@lcBufPtr)

ELSE		&& WinXP or later OS
	m.lnRet= -1
	TRY 
		DECLARE INTEGER IsUserAnAdmin IN shell32
		m.lnRet= 1
	CATCH
	ENDTRY

	IF m.lnRet = 1
		m.lnRet= -1
		TRY 
			IF IsUserAnAdmin() = 1
				m.lnRet= 1
			ELSE 
				m.lnRet= 0
			ENDIF
		CATCH
		ENDTRY
	ENDIF 

ENDIF

DO case
CASE m.lnRet = -1		&& got err
	= MESSAGEBOX("Please contact support. Cannot test for Admin privilege." +;
		CHR(13) + CHR(13) + MESSAGE())
CASE m.lnRet = 0		&& not admin
	= MESSAGEBOX(IIF(EMPTY(m.tcFunc), "", m.tcFunc + CHR(13) + CHR(13)) +;
		"This function requires Windows elevated privilege." + CHR(13) + CHR(13) +;
		"Please re-run the application using 'Administrator' level privilege in order to proceed." + CHR(13) + CHR(13) +;
		"To do this, Right-click the application shortcut and select " +;
		"'Run as Administrator'", 48, "Notice")
ENDCASE 

RETURN m.lnRet

************
FUNCTION Long2Num(tcLong)
DECLARE RtlMoveMemory IN WIN32API Long @Dest, ;
		String @Source, Long Length
LOCAL lnNum
lnNum = 0
= RtlMoveMemory(@lnNum, tcLong, 4)
RETURN lnNum
>Hi Mark,
>
>>Anyway, I'm about to change my app's install folder to a new root, called "Programs", and get on with life, knowing that my app runs solid again as it did on XP, if it's installed outside of Program Files.
>
>Did you do this and do you have some experience you want to share?
>
>Maybe this is a viable shortcut to Vista-enable all legacy apps? Does anybody want to strongly advice against it?
>
>Vidar
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform