473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

using LsaOpenPolicy in VB.NET

Hi all,

in VB.NET i want to enumerate the list of users with a special userright. So
i want try to use the LsaEnumerateAccountWithUserRight.

When i try to open a policy handle i return a nullreference error and i
don't know why?

here is my code:
Private Declare Function LsaOpenPolicy Lib "ADVAPI32.dll" ( _
ByVal SystemName As String, _
ByVal ObjectAttributes As
LSA_Object_Attributes, _
ByVal AccessMask As Integer, _
ByRef Handle As IntPtr _
) As Long
Public Function OpenHandle() As IntPtr
Dim Handle As IntPtr
Dim Ret As Long
Ret = LsaOpenPolicy("", Nothing, &HFFFF, Handle)
Return Handle
End Function
Nov 21 '05 #1
5 2228
"AndyL" <An***@discussions.microsoft.com> schrieb:
in VB.NET i want to enumerate the list of users with a special userright.
So
i want try to use the LsaEnumerateAccountWithUserRight.

When i try to open a policy handle i return a nullreference error and i
don't know why?

here is my code:
Private Declare Function LsaOpenPolicy Lib "ADVAPI32.dll" ( _
ByVal SystemName As String, _
=> 'ByRef SystemName As LSA_UNICODE_STRING'.
ByVal ObjectAttributes As
LSA_Object_Attributes, _
=> 'ByRef ObjectAttributes As LSA_OBJECT_ATTRIBUTES'.
ByVal AccessMask As Integer, _
ByRef Handle As IntPtr _
) As Long


=> 'As Int32'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
Hi Herfried,

it doesn't work :-(

I receive always a NullReferenceError WHY?

CU Andy

Dim LsaObjectAttribs As New LSA_Object_Attributes
Dim LsaHandle As IntPtr
Dim computer As New LSA_UNICODE_STRING
Dim Access As Long = &HFFFF
computer.Length = 0
LsaObjectAttribs.Length = 0
If Not LsaOpenPolicy(computer, LsaObjectAttribs, Access, LsaHandle) = 0 Then
Exit Function

"Herfried K. Wagner [MVP]" wrote:
"AndyL" <An***@discussions.microsoft.com> schrieb:
in VB.NET i want to enumerate the list of users with a special userright.
So
i want try to use the LsaEnumerateAccountWithUserRight.

When i try to open a policy handle i return a nullreference error and i
don't know why?

here is my code:
Private Declare Function LsaOpenPolicy Lib "ADVAPI32.dll" ( _
ByVal SystemName As String, _


=> 'ByRef SystemName As LSA_UNICODE_STRING'.
ByVal ObjectAttributes As
LSA_Object_Attributes, _


=> 'ByRef ObjectAttributes As LSA_OBJECT_ATTRIBUTES'.
ByVal AccessMask As Integer, _
ByRef Handle As IntPtr _
) As Long


=> 'As Int32'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
"AndyL" <An***@discussions.microsoft.com> schrieb:
I receive always a NullReferenceError WHY?

CU Andy

Dim LsaObjectAttribs As New LSA_Object_Attributes
Dim LsaHandle As IntPtr
Dim computer As New LSA_UNICODE_STRING
Dim Access As Long = &HFFFF
=> 'As Int32'.
computer.Length = 0
LsaObjectAttribs.Length = 0
If Not LsaOpenPolicy(computer, LsaObjectAttribs, Access, LsaHandle) = 0
Then


Post your declarations of 'LSA_UNICODE_STRING' and 'LSA_OBJECT_ATTRIBUTES'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
Hi,

here it is

<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Structure LSA_UNICODE_STRING
Dim Length As Integer
Dim MaximumLength As Integer
Dim Buffer As Long
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Structure LSA_Object_Attributes
Dim Length As Long
Dim RootDirectory As Long
Dim ObjectName As Long
Dim Attributes As Long
Dim SecurityDescriptor As Long
Dim SecurityQualityOfService As Long
End Structure

Private Declare Function LsaOpenPolicy Lib "ADVAPI32.dll" ( _
ByRef SystemName As LSA_UNICODE_STRING, _
ByRef ObjectAttributes As
LSA_Object_Attributes, _
ByVal DesiredAccess As Long, _
ByRef PolicyHandle As IntPtr) As Long

Public Function OpenHandle() As String
Dim LsaObjectAttribs As New LSA_Object_Attributes
Dim LsaHandle As IntPtr
Dim computer As New LSA_UNICODE_STRING
Dim Access As Long = &HFFFF
computer.Length = 0
LsaObjectAttribs.Length = 0
If Not LsaOpenPolicy(computer, LsaObjectAttribs, Access, LsaHandle)
= 0 Then Exit Function

End Function

"Herfried K. Wagner [MVP]" wrote:
"AndyL" <An***@discussions.microsoft.com> schrieb:
I receive always a NullReferenceError WHY?

CU Andy

Dim LsaObjectAttribs As New LSA_Object_Attributes
Dim LsaHandle As IntPtr
Dim computer As New LSA_UNICODE_STRING
Dim Access As Long = &HFFFF


=> 'As Int32'.
computer.Length = 0
LsaObjectAttribs.Length = 0
If Not LsaOpenPolicy(computer, LsaObjectAttribs, Access, LsaHandle) = 0
Then


Post your declarations of 'LSA_UNICODE_STRING' and 'LSA_OBJECT_ATTRIBUTES'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
"AndyL" <An***@discussions.microsoft.com> schrieb:
<StructLayout(LayoutKind.Sequential, Pack:=1)> _
I am curious why you set 'Pack' to 1 for this structure.
Structure LSA_UNICODE_STRING
Dim Length As Integer
=> 'As Short'.
Dim MaximumLength As Integer
=> 'As Short'.
Dim Buffer As Long
=> 'As String'.
<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Dito.
Structure LSA_Object_Attributes
Dim Length As Long
=> 'As Int32'.
Dim RootDirectory As Long
=> 'As IntPtr'.
Dim ObjectName As Long
=> 'As PLSA_UNICODE_STRING'.
Dim Attributes As Long
=> 'As Int32'.
Dim SecurityDescriptor As Long
=> 'As IntPtr'.
Dim SecurityQualityOfService As Long
=> 'As IntPtr'.
ByVal DesiredAccess As Long, _
=> 'As Int32'.
ByRef PolicyHandle As IntPtr) As Long Dim Access As Long = &HFFFF


=> 'As Int32'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: rawCoder | last post by:
Hi All, I have a *.cer file, a public key of some one and I want to encrypt some thing using this public key. Can someone point me to a sample code for Encrypting some file using...
1
by: Mike | last post by:
When trying to compile (using Visual Web Developer 2005 Express Beta; frameworkv2.0.50215 ) the source code below I get errors (listed below due to the use of ICallBackEventHandler. Ultimately I...
10
by: Christopher Benson-Manica | last post by:
Why can't I use a class destructor in a using declaration: using MyClass::~MyClass; ? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org ...
17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
8
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using...
14
by: john.burton.email | last post by:
I've done some extensive searching and can't seem to find an answer to this - Is it correct to using "using" with templates, for example: using std::vector; Or do I need to specify the type...
4
by: Adrian Wallis | last post by:
Hello, I'm trying to call LsaOpenPolicy, but get the error 'System.AccessViolationException'. I originally tried a conversion from working VB6 code and I've compared the code with working C#...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
12
by: abhishek.gilra | last post by:
Does anyone know how to add users to the log on locally list in User Rights Management inside Local Security settings. Thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.