|
Dave,
I see how that can work for the logged in user:
'****************************************************************************
Dim userPrincipal As IPrincipal = System.Threading.Thread.CurrentPrincipal
userPrincipal = Thread.CurrentPrincipal
Dim result As Boolean = userPrincipal.IsInRole("DOMAIN\Group1")
msgbox(result)
'****************************************************************************
Is there any way I can specify the NAME I want it to check? The below code will not work because the property NAME is readonly:
'****************************************************************************
Dim userPrincipal As IPrincipal = System.Threading.Thread.CurrentPrincipal
userPrincipal.Identity.Name = "DOMAIN\"& strUserName
Dim result As Boolean = userPrincipal.IsInRole("DOMAIN\Group1")
msgbox(result)
'****************************************************************************
Is there any way I can change the NAME I want it to check? At this point in the process, the strUserName I want to check against I get from a text field on a form the user has filled out.
|
|
|
|
|
The onyl way to do that would be to log the person in, requiring you get the users password and create a security token impersonating them. You can't just pass a username and a group and call it done.
Personally, I avoid such checks as it requires the users to, yet again, type another username and password, even if it's the same as their login account. It's far easier to check the Principal object that's currently running the code.
|
|
|
|
|
Actually they need to enter in their credentials. I'm creating this small .exe for a non-secure application. This application is installed on workstations that are located in an open area. The account these machines are logged into with is a "common" account. Since the software does not do domain authentication or ask for a log in, we are trying this to get it secure.
We want people to run this small .exe as a "login" for the app. They enter their network userid and password. I want to run the admin rights check we've been discussing. Once they pass the check, I execute a "Run As" statement that uses their entered credentials. Since I need to collect the userid and password for the Run As, this security token you are referring to may help. How do you create a security token for impersonating them?
|
|
|
|
|
So why not just ask for the cred's, launch the app RunAs, and if that fails, you know the cred's were bad, and in the Admin app, do the check for Admin rights?
|
|
|
|
|
Thats just it - ANYONE can run the vendor application right now. If you log into the workstation as the local administrator or a guest user, you can get into the application. We initially started this .exe as a way to log who is accessing the program, then someone asked to add a check to see if the network account belonged to a domain group as a form of security.
|
|
|
|
|
OK. I thought you were writing this other app.
This is NOT easy to do. You also will not shell out to RunAs to launch the other process. Use the Process and ProcessStartInfo classes. You have to supply the username, password, and domain name that the user is in to ProcessStartInfo so it can launch the process under the correct account.
But, to find out if the person is using the correct credentials and is in the Administrators group:
Imports System.Security.Principal
Imports System.Security.Permissions
Imports System.Runtime.InteropServices
Imports System.ComponentModel
.
.
.
Private Const LOGON32_PROVIDER_DEFAULT As Integer = 0
Private Const LOGON32_LOGON_INTERACTIVE As Integer = 2
Private Declare Auto Function LogonUser Lib "advapi32.dll" ( _
ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, _
ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, _
ByRef phToken As IntPtr) _
As Boolean
Private Declare Auto Function CloseHandle Lib "kernel32.dll" ( _
ByVal handle As IntPtr) _
As Boolean
Private Function IsUserAnAdmin(ByVal username As String, ByVal password As String, ByVal domain As String) As Boolean
Dim returnValue As Boolean = False
Dim tokenHandle As New IntPtr(0)
' Call the Win32 LogonUser function to get a security token.
' If the call succeeds, LogonReturn will be True. In the credentials supplied
' are bad, this will return False.
Dim LogonReturn As Boolean
LogonReturn = LogonUser(username, domain, password, LOGON32_LOGON_INTERACTIVE, _
LOGON32_PROVIDER_DEFAULT, tokenHandle)
Try
If False = LogonReturn Then
' If the Logon failed, you can either throw an exception back to the caller
' or just set returnValue to False. This code does both for no good reason.
Dim errorCode As Integer = Marshal.GetLastWin32Error()
Throw New Win32Exception(errorCode)
returnValue = False
Else
' LogonUser worked! User the returned security token to create a new
' WindowsIdentity object...
Dim newIdentity As New WindowsIdentity(tokenHandle)
' Then create an impersonation context out of that so we can revert
' back to being our normal logged in user...
Dim impersonatedUser As WindowsImpersonationContext = newIdentity.Impersonate()
' The create a new Principal object so we can check role membership...
Dim newPrincipal As New WindowsPrincipal(newIdentity)
' Is the new user an Admin???
returnValue = newPrincipal.IsInRole("Administrators")
' Forget we logged in as this new person and revert back to
' the original user.
impersonatedUser.Undo()
CloseHandle(tokenHandle)
End If
End Try
' Tell the caller what happened...
Return returnValue
End Function
|
|
|
|
|
That worked perfectly! Thank you for all your help.
|
|
|
|
|
plz tell me how to access data from access or sql database and show in the vb form not just as table rather in the form of a windows "form".
---
-- modified at 11:10 Thursday 27th September, 2007
|
|
|
|
|
Please don't post you'r question twice, it will only result in being ignored.
if you want to modify you'r original post you can use the modify link on the right lower corner of the post
I suggest for learning vb.net that you take a simple project and try to complete it, look at the articles here they'v helped me a great deal in accomplishing easy and difficult tasks.
if you run into any trouble you can always ask here but ask specific questions on specific problems.
As to the question where the dataform wizard went, I'm afraid I can't help you with that since I never programmed in 2002.
If you want to display and edit data the datagrid maybe an option (can be complex)
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistaks.
|
|
|
|
|
have you tried Google? There are thousands of examples. I suggest you buy a book if you are asking such a basic question.
__________________________
Don't drink and derive.
Alcohol and calculus don't mix.
|
|
|
|
|
hi to all.
i am beginner in vb.net. i was reading a tutorial to make address book in vb.net but that tutorial was using vs.net 2002 in which dataform wizard is available. I am using vs.net 2005 and unable to find such sort of wizard. Please guide me how i can show data from data base to seperate fields in form using wizard or through any graphical process instead of coding.
thx
|
|
|
|
|
You can get an introduction by watching the "Forms over Data Video Series" here[^].
|
|
|
|
|
can i catch any windows focus in vb ?suppose i am running any vb application & i have clicked any windows apps then can i check in vb that focus is on any other window?my os is win 2000.
rahul
|
|
|
|
|
You'd have to implement the "CBT Hook" to get this information. There is no event or class in the .NET Framework that will do this for you. All you have to do is Google for "VB.NET CBT Hook" to find some examples. Warning! There is very little documentation specific to VB concerning hooks. You'll have to translate code from either C++ or C# to get it working.
|
|
|
|
|
thankx for solution.also we do the same by getactivewindow api.
rahul
|
|
|
|
|
That'll give you the active window, but not the active control window.
|
|
|
|
|
I was wondering how a you can check for a version of abode reader from vba in excel. I am using a 8.0 plugin version on reader in a form and when a user without the 8.0+ version installed on their machine is getting an outofmemory error if they try to run it. thanks.
Regards,
Oz
|
|
|
|
|
Yes - find out by looking in the registry.
Below is an example of how I find the location of the Access 97 exe by looking at the registry.
This is vbscript and the good news is that you can use vbscript within vba:
<br />
Set SysVarReg = WScript.CreateObject("WScript.Shell")<br />
accessLoc= SysVarReg.RegRead ("HKLM\SOFTWARE\Microsoft\Office\8.0\BinDirPath")+"\msaccess.exe"<br />
What you will need to look for is to see if the following exists:
"HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\8.0"
If it does then you know the user has version 8.0
I hope this gives you some idea of what to do.
You always pass failure on the way to success.
|
|
|
|
|
I am using Crystal Reports in my application I made using Visual Studio.NET.
I installed my application on the client machine, with all the DLLs
required(added the merge modules), the engine and the rest. When I start my
application and, from it, try to open up a report I get an exception "Query
engine error: C:\WINDOWS\Temp\temp_*******.rpt" with some wierd numbers
instead of *******. Can anyone tell me what the problem is here and how to
solve it. I am running the application on Windows 98.
|
|
|
|
|
windows 98? hmmm....how much memory [RAM and paging file size] does that machine have? Crystal reports and your application could be hogging on the system resources; making it impossible for the query to run successfully. Try the installation on more superior client machine.
---------------------------
Both optimists and pessimists are important in technology. The optimist invented the aeroplane; the pessimist invented the parachute.
Regards,
Hesbon Ongira
Nairobi, Kenya.
|
|
|
|
|
I have the codes
dim dataadapter as new oledb.oledbadapter("Select * from ITEM where dateAcquired between '9/20/2004' and '9/20/2007'
and it doesn't work.
What seems to be the problem?
gt
|
|
|
|
|
Impossible to say
1 - what does 'doesn't work' mean?
2 - what happens when you plug this code directly nto the DB
3 - what does the rest of your code look like ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Try the SQL statement in Query analyzer (SQL 2000) or Design a query and switch to SQL View in Access to see what are the results.
|
|
|
|
|
I tried it and it has an error which is criteria mismatch. What does it mean?
|
|
|
|
|
gt2 wrote: dim dataadapter as new oledb.oledbadapter("Select * from ITEM where dateAcquired between '9/20/2004' and '9/20/2007'
for date's you can use the convert statement (for sql server)
Select * from ITEM where dateAcquired between convert(datetime,'9/20/2004',102) and convert(datetime,9/20/2007,102)
or for access
select * from ITEM where dateacquired between #9/20/2004# and #9/20/2007#
hope it helps
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistaks.
|
|
|
|