Page 1 of 2

IsUserAnAdmin - IsWow64Process

Posted: Mon Nov 23, 2009 11:35 pm
by RASHAD
Check If You are logged in As Admin Or Not

Code: Select all

If OpenLibrary(0,"shell32.dll")
  *MAlloc = GetFunction(0, "IsUserAnAdmin")
  If CallCFunctionFast(*MAlloc) = 1
    MessageRequester("Info","User is Admin", #MB_ICONINFORMATION)
  Else
    MessageRequester("Info","User is not Admin",#MB_ICONINFORMATION)
  EndIf
CloseLibrary(0)
EndIf

Check If Your program is running under x64 Windows OS Or Not
I think It is much better than kernel32.dll (IsWow64Process) function
Please check And confirm

Code: Select all

lRetVal.i
sRemMachName.s
lTopLevelKey.i
lHKeyhandle.i
sKeyName.s
lhkey.i
sValueName.s
vValue.s
msg.s ;

#ERROR_NONE = 0

Procedure.l QueryValueEx(lhkey.i, szValueName.s)
  Define.i cch, lrc, lType, lValue
  Define.s sValue
  Shared vValue
  cch    = 255
  sValue = Space(255)
  lrc    = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue, @cch)
  If lrc = #ERROR_NONE
    vValue = Left(sValue, cch - 1)
  Else
    vValue = "Empty"
  EndIf
  ProcedureReturn lrc
EndProcedure

lTopLevelKey = #HKEY_LOCAL_MACHINE 
sRemMachName = ""
sKeyName = "Software\Microsoft\Windows\CurrentVersion"
sValueName = "CommonW6432Dir"
lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0,#KEY_READ, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)

If lRetVal = 0
  MessageRequester("Information","Running System is 64 bit", #MB_ICONINFORMATION)
Else
  MessageRequester("Information","Running System is 32 bit", #MB_ICONINFORMATION)
EndIf
Please confirm
Have a good day

Re: IsUserAnAdmin - IsWow64Process

Posted: Wed Dec 09, 2009 11:54 pm
by SFSxOI
How about the PureBasic function:

Code: Select all

Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
But yours seems to work fine, thank you very much. :)

Re: IsUserAnAdmin - IsWow64Process

Posted: Thu Dec 10, 2009 12:04 am
by RASHAD
Hi SFSxOI
Why do't you post your feedback as soon as you can?
More tech. more fun for the guys
Glad to talk to you
Happy new year man

SFSxOI your name makes me mad so difficult to remember

Re: IsUserAnAdmin - IsWow64Process

Posted: Thu Dec 10, 2009 2:36 am
by rsts
SFSxOI wrote:How about the PureBasic function:

Code: Select all

Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
But yours seems to work fine, thank you very much. :)
Rashad's seems to work fine :D , but this returns s86 when, in fact I'm running 64 bit. The PB install is 32 bit however.

cheers

Re: IsUserAnAdmin - IsWow64Process

Posted: Thu Dec 10, 2009 6:27 am
by RASHAD
rsts Happy new year you and North America
I wish 2010 will be much better for all of you
Now rsts give me in detail PB ver ,the running OS and the output to see what we can do

Re: IsUserAnAdmin - IsWow64Process

Posted: Thu Dec 10, 2009 12:39 pm
by SFSxOI
rsts wrote:
SFSxOI wrote:How about the PureBasic function:

Code: Select all

Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
But yours seems to work fine, thank you very much. :)
Rashad's seems to work fine :D , but this returns s86 when, in fact I'm running 64 bit. The PB install is 32 bit however.

cheers
"GetEnvironmentVariable" returns properly here for x86/32 bit and x64/64 bit - several machines checked - all with Windows 7 Ultimate, intel chipsets and processors. Are you using an AMD based system or 32 bit processor?

Re: IsUserAnAdmin - IsWow64Process

Posted: Thu Dec 10, 2009 12:45 pm
by SFSxOI
RASHAD wrote:Hi SFSxOI
Why do't you post your feedback as soon as you can?
More tech. more fun for the guys
Glad to talk to you
Happy new year man

SFSxOI your name makes me mad so difficult to remember
RASHAD, checked it all out and everything works fine here on Windows 7 Ultimate. Tried on several machines and everything works properly. The only possible issue i can see with it is permissions dealing with accessing the registry for users that might have less then admin or super-user permissions.

(My name makes you mad? LoL :), first time i ever had anyone say that. Actually it's a mixture of a contraction of an office title and call sign from a previous career of 26 years in the military from which i have since retired.)

Merry Christmas and a Happy new year to you too.

Re: IsUserAnAdmin - IsWow64Process

Posted: Thu Dec 10, 2009 2:14 pm
by rsts
Hi,

Mr RASHAD's routine correctly returns 64 bit.

Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE"), returns s86.

I'm running 64 bit Windows 7 on AMD AthlonII X2 245 64 bit dual core processor.

cheers

Re: IsUserAnAdmin - IsWow64Process

Posted: Thu Dec 10, 2009 2:43 pm
by doctorized
I tried the code under Win XP x64 SP2 with both PB 4.31 x64 and x86.
In both cases returns: "Running System is 32 bit".

I am using a better code, found in this forum:

Code: Select all

Import ""
  GetNativeSystemInfo(*info)
EndImport

Procedure IsWin64(); is the OS 64;
  Protected Info.SYSTEM_INFO
  GetNativeSystemInfo(Info)
  If info\wProcessorArchitecture
    ProcedureReturn #True
  EndIf
EndProcedure 

Debug IsWin64()
If returned values is 0 then we have x86 OS, else we have x64 OS.

Re: IsUserAnAdmin - IsWow64Process

Posted: Thu Dec 10, 2009 5:45 pm
by RASHAD
Hi doctorized
Sorry I do't have XP 64 bit for test
So please test the next snippet it is much shorter and clear (the SYSTEM_INFO structure is about( The Processor
Architecture not the running OS )

Code: Select all

#KEY_WOW64_64KEY=$100

KeyName.s = "Software\Wow6432Node" 
KeyHandle.l = 0 
If RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, @KeyName, 0,#KEY_READ|#KEY_WOW64_64KEY, @KeyHandle) = #ERROR_SUCCESS 
MessageRequester("Information","Running System is 64 bit", #MB_ICONINFORMATION)
Else
MessageRequester("Information","Running System is 32 bit", #MB_ICONINFORMATION)
EndIf
Happy new year

Re: IsUserAnAdmin - IsWow64Process

Posted: Thu Dec 10, 2009 8:13 pm
by doctorized
Yes. This code returns "Running System is 64 bit".

Happy new year? From now? 10th of December? 21 days earlier?

Re: IsUserAnAdmin - IsWow64Process

Posted: Fri Dec 11, 2009 12:01 am
by SFSxOI
This is what i've been using for a while to determine if a user is an admin or not:

Code: Select all

Procedure IsUserAdmin()
  isadmin = OpenSCManager_(#Null,#Null,#SC_MANAGER_ALL_ACCESS) 
  If isadmin 
    CloseServiceHandle_(isadmin) 
  EndIf 
  If isadmin > 0 : isadmin = #True : Else : isadmin = #False : EndIf
  ProcedureReturn isadmin 
EndProcedure

If IsUserAdmin() = #True
  MessageRequester("Information","Is an Admin")
Else
  MessageRequester("Information","Is not an Admin")
EndIf


Re: IsUserAnAdmin - IsWow64Process

Posted: Fri Dec 11, 2009 12:15 am
by ts-soft
SFSxOI wrote:This is what i've been using for a while to determine if a user is an admin or not:

Code: Select all

Procedure IsUserAdmin()
  isadmin = OpenSCManager_(#Null,#Null,#SC_MANAGER_ALL_ACCESS) 
  If isadmin 
    CloseServiceHandle_(isadmin) 
  EndIf 
  If isadmin > 0 : isadmin = #True : Else : isadmin = #False : EndIf
  ProcedureReturn isadmin 
EndProcedure

If IsUserAdmin() = #True
  MessageRequester("Information","Is an Admin")
Else
  MessageRequester("Information","Is not an Admin")
EndIf

Why not simple:

Code: Select all

If IsUserAnAdmin_() = #True
  MessageRequester("Information","Is an Admin")
Else
  MessageRequester("Information","Is not an Admin")
EndIf
?

Re: IsUserAnAdmin - IsWow64Process

Posted: Fri Dec 11, 2009 2:35 am
by RASHAD
I thought it is very simple topic but you made it somthing else
So my new year strted allready
SFSxOI,rsts,doctorized and Tomas
Happy new year boys from now on till 15 of the next Jan I will keep saying it to the forum members

Re: IsUserAnAdmin - IsWow64Process

Posted: Fri Dec 11, 2009 12:55 pm
by SFSxOI
ts-soft wrote:
SFSxOI wrote:This is what i've been using for a while to determine if a user is an admin or not:

Code: Select all

Procedure IsUserAdmin()
  isadmin = OpenSCManager_(#Null,#Null,#SC_MANAGER_ALL_ACCESS) 
  If isadmin 
    CloseServiceHandle_(isadmin) 
  EndIf 
  If isadmin > 0 : isadmin = #True : Else : isadmin = #False : EndIf
  ProcedureReturn isadmin 
EndProcedure

If IsUserAdmin() = #True
  MessageRequester("Information","Is an Admin")
Else
  MessageRequester("Information","Is not an Admin")
EndIf

Why not simple:

Code: Select all

If IsUserAnAdmin_() = #True
  MessageRequester("Information","Is an Admin")
Else
  MessageRequester("Information","Is not an Admin")
EndIf
?
Well, yeah your right. :)