* 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,