|
I need to call NetAPI32 to get domain info on legacy workstations (IE: Win98, etc - DirectoryServices is not avail in 98).
I have the following code. The call to DsGetDcNameAWin5 doesn't error off, but the values are 0. I've tried changing the function declare to (using a pointer) as the last param with no success also:
Private Declare Function DsGetDcNameAWin5 Lib "netapi32.dll" Alias "DsGetDcNameA" (ByVal ComputerName As String, ByVal DomainName As String, ByRef DomainGuid As GUID, ByVal SiteName As String, ByVal Flags As Integer, ByRef lpDomainControllerInfo As IntPtr) As Integer
Could someone please show how to properly call and then extract the data from this .dll?
Sample code:
Private Const NO_ERROR As Short = 0
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef pTo As Integer, ByRef uFrom As Integer, ByVal lSize As Integer)
Private Declare Function lstrlenA Lib "kernel32" (ByVal lpString As Integer) As Integer
Private Declare Function DsGetDcNameAWin5 Lib "netapi32.dll" Alias "DsGetDcNameA" (ByVal ComputerName As String, ByVal DomainName As String, ByRef DomainGuid As GUID, ByVal SiteName As String, ByVal Flags As Integer, ByRef lpDomainControllerInfo As Integer) As Integer
Private Structure GUID
Dim Data1 As Integer
Dim Data2 As Short
Dim Data3 As Short
<vbfixedarray(7)> Dim Data4() As Byte
Public Sub Initialize()
ReDim Data4(7)
End Sub
End Structure
Private Structure DOMAIN_CONTROLLER_INFO
Dim DomainControllerName As Integer
Dim DomainControllerAddress As Integer
Dim DomainControllerAddressType As Integer
Dim DomainGuid As GUID
Dim DomainName As Integer
Dim DnsForestName As Integer
Dim Flags As Integer
Dim DcSiteName As Integer
Dim ClientSiteName As Integer
Public Sub Initialize()
DomainGuid.Initialize()
End Sub
End Structure
Private Function SetDcNameA(Optional ByVal strDomain As String = vbNullString, Optional ByVal strComputer As String = vbNullString) As Boolean
Dim lpBuffer As Integer
Dim dci As DOMAIN_CONTROLLER_INFO
dci.DomainGuid.Initialize()
m_LastError = DsGetDcNameAWin5(strComputer, strDomain, dci.DomainGuid, vbNullString, m_Flags, lpBuffer)
If m_LastError <> NO_ERROR Then
GoTo ErrorHandler
End If
' Recover structure into one we can deal with in VB
'Call CopyMemory(dci, lpBuffer, Len(dci)) 'Doesn't compile
' Transfer contents to member structure.
m_DCI.DomainControllerName = PointerToStringA(dci.DomainControllerName)
m_DCI.DomainControllerAddress = PointerToStringA(dci.DomainControllerAddress)
m_DCI.DomainControllerAddressType = dci.DomainControllerAddressType
m_DCI.DomainGuid = dci.DomainGuid
m_DCI.DomainName = PointerToStringA(dci.DomainName)
End Sub
Private Function PointerToStringA(ByVal lpStringA As Integer) As String
Dim Buffer() As Byte
Dim nLen As Integer
On Error GoTo ErrorHandler
If CBool(lpStringA) Then
nLen = lstrlenA(lpStringA)
If CBool(nLen) Then
ReDim Buffer((nLen - 1))
CopyMemory(Buffer(0), lpStringA, nLen)
'Not sure if this line is correct as well.
PointerToStringA = StrConv(System.Text.UnicodeEncoding.Unicode.GetString(Buffer), VbStrConv.None)
End If
End If
Exit Function
ErrorHandler:
PointerToStringA = ""
End Function
|
|
|
|
|
I am currently studying computer in a local university in my country.
I am using Visual Basic 2008 to develop a program for a Windows computer(desktop) which only have one numeric keypad and does not have any standard keyboard.
I hope that when my program is running but Windows focus on other application, or when my program is running in inactive status, if the user press the '+' button (or other button set by me) for three times on the keypad with fast, Windows will switch to my program immediately.
How can I do that?
|
|
|
|
|
Set a keyboard hook[^] watching for the + key. When it is pressed start a timer. If the + key is pressed two more times before the timer event fires, show your form. Otherwise, do nothing.
|
|
|
|
|
How can I set my simple VB.NET program to start in minimized mode?
My program consist of one form.
|
|
|
|
|
Isn't there an initial state property for the form in the designer ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
Set the window state property of the form to minimized
Regards
Azeem
|
|
|
|
|
i am adding a tool in the existing menu bar
and i can view it in the design mode but unable
to view in runtime.i am using third party
controller (Infragistics).
pls help.
modified on Tuesday, June 24, 2008 10:24 AM
|
|
|
|
|
Not a lot to go on, is there? I suspect a licence issue, but the best bet is to contact Infragistics.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
i can view all other existing infragistic control but
the control i added is invisible.the project is of
another developer i just modifying and upgrading little.
when i first try to open in design view it was giving lots of errors.
but i downloaded infragistic.since then i can view all control except
the control i m adding.
thanx 4 replying
|
|
|
|
|
hey all,
i have an application developed in vb6 and i have to migrate it to vb.net
is there any free tool to help me doing that?
10x a lot
|
|
|
|
|
Visual Studio tries, but I don't know of any better tools. VB6 -> VB.NET is two different languages, some rewrite will always be needed.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi
I too doing the same job ..I didn't find any tool for this conversion.
Try to open the VB6 project file with the Visual Studio,it will ask for upgrade option
It will upgrade some code and leaves a message over the code where it fails.
Happy coding..
|
|
|
|
|
We have a system that we want to switch from SQL server to MySql. Is there a simple way to do that. I thought maybe we could just change the connection string in our app.config file but that does not seem to work.
Any and all advice welcome.
Thanks
Tom
|
|
|
|
|
If that doesn't work, you've used SQL that's specific to SQL Server, or you've used the SQL Server specific classes and need to move to the OleDB ones. Hard to know without you telling us what 'does not seem to work', means.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You may find the MySql Connector/Net[^] to be useful. Just replace your SqlClient references with the new references for MySql. And as Christian said in his reply to you, as long as you did not use any SQL Server-specific commands you will be good to go.
|
|
|
|
|
OK.. Pardon my ignorance please.. but what do you mean by replace SqlClient references with the new references for Mysql. Can you give me a example ?
Thanks in advance
Tom
|
|
|
|
|
Sure. This is probably how your code using SQL Server looks:
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim DatabaseConnection As New SqlConnection("connectionstringgoeshere")
DatabaseConnection.Open()
Dim SQLCommand As New SqlCommand("SELECT * FROM TABLE", DatabaseConnection)
SQLCommand.ExecuteNonQuery()
DatabaseConnection.Close()
End Sub
End Class
Now, after you have downloaded and installed the MySql Connector/Net, open the project's properties, click References, click Add, and add C:\Program Files\MySQL\MySQL Connector Net 5.1.6\Binaries\.NET 2.0\MySql.Data.dll. That's the default directory, it may be somewhere else on your computer. Next, change your code to MySql. I bolded the changes:
Imports MySql.Data.MySqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim DatabaseConnection As New MySqlConnection("connectionstringgoeshere")
DatabaseConnection.Open()
Dim SQLCommand As New MySqlCommand("SELECT * FROM TABLE", DatabaseConnection)
SQLCommand.ExecuteNonQuery()
DatabaseConnection.Close()
End Sub
End Class
Again referring back to what Christian said earlier, as long as you don't do any SQL Server-specific queries you should pretty much be able to just replace the SQL Server stuff with the MySql stuff. Make sure to update your connection string to be for MySql. (You can also use OleDbConnection if you don't want to use the MySql Connector.)
Hope this helps...
|
|
|
|
|
I am using tableadapters built from the data source so I can't just replace the sql server commands with the mysql commands. I guess I thought I should be able to just change the
connectionstring and provider name in my config file and it would go to the MySql database.
Tom
|
|
|
|
|
Hi
I want to open a jpg file from calling with button and the image load with windows picture or somthing else.
please help. tanx!
|
|
|
|
|
Bitmap.FromFile
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
please more explanation with complete code.
thank U
|
|
|
|
|
I see someone posted it. I recommend you read the article I link to in my sig, buy a book on VB.NET and learn some basics so you have a basis on which to understand answers given to you. If you can't work things out based on being told what method to call, you're probably just cutting and pasting code you're given but don't understand, and that's not how to learn.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
ViewPictureBox.Image = System.Drawing.Bitmap.FromFile("here is your image path")
|
|
|
|
|
Hello All,
I want to check a simple think in the database ie i want to check the particular data is already in the database or not. Particular table contain only one field and that field is only a primary key. i want to check it with my frond end that is visual studio.net 2008
I write the below code for that
rs.Open("select * from CategoryMaster where categoryname = '"&txtcat.Text &"'", con, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockOptimistic)
If rs.EOF Then
rs.AddNew()
rs.Fields("CategoryName") = txtcat.Text
rs.Update()
txtcat.Text = ""
txtcat.Focus()
Else
MsgBox("This category is Already in database ")
End If
I that code it shown some error in the below line
rs.Fields("CategoryName") = txtcat.Text
The error is Property 'Item' is 'ReadOnly'
Please help me to resolve this
Thanks
|
|
|
|
|
Try: rs.Fields("CategoryName").Value = txtcat.Text .
|
|
|
|