
LeeSalter
Avatar/Signature-
Posts
26 -
Joined
-
Last visited
About LeeSalter
- Birthday 12/08/1972
Personal Information
-
Occupation
Would-Be Programmer!!
-
Visual Studio .NET Version
VB .NET Standard Edition
-
.NET Preferred Language
VB
LeeSalter's Achievements
Newbie (1/14)
0
Reputation
-
Here's some code to put all of your NT/2000 Servernames into a text file. It may help you. #Region "Add Domain Servers To Text File" Public Function GetNetList(ByVal DomainName As String) As String() Dim ServerInfo As New Server_info_101() Dim i, MaxLenPref, level, ret, EntriesRead, TotalEntries, _ ResumeHandle As Integer Dim BufPtr As New IntPtr() Dim iPtr As IntPtr Dim tempPtr As Integer Dim ans(0) As String Dim sw As StreamWriter If File.Exists(Application.StartupPath & "\Servers.txt") = True Then Dim sr1 As StreamReader = File.OpenText(Application.StartupPath & _ "\Servers.txt") Do Until sr1.Peek = -1 frmMoveUser.lstboxServers.Items.Add(sr1.ReadLine) Loop Exit Function End If sw = File.CreateText(Application.StartupPath & "\Servers.txt") Const SV_TYPE_DOMAIN_CTRL As Long = &H8 Const SV_TYPE_DOMAIN_BAKCTRL As Long = &H10 ' let's do it! MaxLenPref = -1 level = 101 ret = NetServerEnum(0, level, BufPtr, MaxLenPref, EntriesRead, _ TotalEntries, SV_TYPE_ALL, DomainName, ResumeHandle) If ret <> 0 Then MsgBox("Hmmmm... something went wrong", vbCritical, "Error!") Return ans End If Dim nSize As Integer = Marshal.SizeOf(ServerInfo) ReDim ans(EntriesRead - 1) tempPtr = BufPtr.ToInt32 ' loop thru the entries For i = 0 To EntriesRead - 1 ' copy the stuff into our structure iPtr = New IntPtr(BufPtr.ToInt32 + i * nSize) ServerInfo = CType(Marshal.PtrToStructure(iPtr, _ GetType(Server_info_101)), Server_info_101) ' Output ServerName to our text file. If ServerInfo.Type = 266291 Or _ ServerInfo.Type = 266259 Or _ ServerInfo.Type = 102435 Or _ ServerInfo.Type = 102403 Then sw.WriteLine(ServerInfo.Name) End If Next NetApiBufferFree(iPtr) NetApiBufferFree(BufPtr) sw.Close() Dim sr As StreamReader = File.OpenText(Application.StartupPath & _ "\Servers.txt") Do Until sr.Peek = -1 frmMoveUser.lstboxServers.Items.Add(sr.ReadLine) Loop sr.Close() End Function #End Region If you want though, you can substitute the following lines:- If ServerInfo.Type = 266291 Or _ ServerInfo.Type = 266259 Or _ ServerInfo.Type = 102435 Or _ ServerInfo.Type = 102403 Then sw.WriteLine(ServerInfo.Name) End If ...with... If ServerInfo.Type = 266291 Or _ ServerInfo.Type = 266259 Or _ ServerInfo.Type = 102435 Or _ ServerInfo.Type = 102403 Then myComboBox.Items.Add(ServerInfo.Name) End If ...to add the server to your combo box directly. HTH. :)
-
Is there a way in VB .NET or an API that creates/deletes Network shares in an NT/2000 environment. I can do it by shelling out and using rmtshare, but that's ugly in my opinion. :)
-
Does anybody know if you can manipulate UNIX servers from within VB .NET. I am writing a centralized user admin programme for my company. I can get most of the Windows/API stuff sorted out (Adding/Deleteing/Modifying NT/2000 users etc). However, we also run quite a few applications that use UNIX back-ends. Would it be possible to add users to this platform in the same sort of way??
-
Thanks for that....I had seen that before, but my c# conversion skills are not too hot at present. I was wondering if there was a simple but reliable vb .net version knocking around. If not, I'll try to convert the c# code. :D
-
Has anybody figured out Ping in vb.Net yet?? I've looked at some code from another site, but it only seems to work the first time it is run, then comes back as failed every other time, so it can't be trusted. The code I'm on about is posted below:- Option Strict On Option Explicit On Imports System.Net Imports System.Net.Sockets Public Enum ICMPType EchoReply = 0 Unreachable = 3 Echo = 8 End Enum ' --- ICMP Echo Header Format --- ' (first 8 bytes of the data buffer) ' Buffer (0) ICMP Type Field ' Buffer (1) ICMP Code Field ' (must be 0 for Echo and Echo Reply) ' Buffer (2) checksum hi ' (must be 0 before checksum calc) ' Buffer (3) checksum lo ' (must be 0 before checksum calc) ' Buffer (4) ID hi ' Buffer (5) ID lo ' Buffer (6) sequence hi ' Buffer (7) sequence lo ' Buffer (8)..(n) Ping Data Module net Private Const portICMP As Integer = 7 Private Const bufferHeaderSize As Integer = 8 Private Const packageHeaderSize As Integer = 28 Public Sub Echo(ByVal RemoteName As String, ByVal DataSize As Byte, ByVal pStatus As Label) 'for timing Dim intStart As Integer 'for timing Dim intEnd As Integer 'address/port of remote host Dim RemoteHost As IPEndPoint Dim rhEP As EndPoint 'id of this packet Dim Identifier As Short = 0 'sequence number of this packet Dim Sequence As Short = 0 'the socket we use to connect and 'send data through Dim ICMPSocket As Socket 'the request buffer Dim RequestBuffer() As Byte 'the reply buffer Dim ReplyBuffer(255) As Byte 'the number of bytes received Dim RecvSize As Integer = 0 RemoteHost = GetRemoteEndpoint(RemoteName) rhEP = CType(RemoteHost, System.Net.EndPoint) DataSize = Convert.ToByte(DataSize + bufferHeaderSize) ' If odd data size, we need to add ' one empty byte If (DataSize Mod 2 = 1) Then DataSize += Convert.ToByte(1) End If ReDim RequestBuffer(DataSize - 1) ' Set Type Field RequestBuffer(0) = Convert.ToByte(ICMPType.Echo) ' Set ID Field BitConverter.GetBytes(Identifier).CopyTo(RequestBuffer, 4) ' Set Sequence Field BitConverter.GetBytes(Sequence).CopyTo(RequestBuffer, 6) ' load some data into buffer Dim i As Integer For i = 8 To DataSize - 1 RequestBuffer(i) = Convert.ToByte(i Mod 8) Next i ' Set Checksum Call CreateChecksum(RequestBuffer, DataSize, RequestBuffer(2), RequestBuffer(3)) Try ICMPSocket = New Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp) ICMPSocket.Blocking = False 'Start Countof RTT intStart = System.Environment.TickCount 'Send Data ICMPSocket.SendTo(RequestBuffer, 0, DataSize, SocketFlags.None, RemoteHost) 'Receive Data RecvSize = ICMPSocket.ReceiveFrom(ReplyBuffer, SocketFlags.None, rhEP) 'End Count of RTT intEnd = System.Environment.TickCount If RecvSize > 0 Then Dim ReS As String Select Case ReplyBuffer(20) Case Convert.ToByte(ICMPType.EchoReply) ReS = (intEnd - intStart).ToString 'get the RTT pStatus.Text = "Host: " + RemoteHost.Address.ToString + " - RTT: " + ReS Case Convert.ToByte(ICMPType.Unreachable) ReS = "Unreachable" pStatus.Text = ReS Case Else ReS = "Something Happened" pStatus.Text = ReS End Select End If Catch e As Exception MessageBox.Show(e.Message + vbNewLine + e.TargetSite.Name) Finally If Not ICMPSocket Is Nothing Then ICMPSocket.Close() End If End Try End Sub Public Function GetRemoteEndpoint(ByVal RemoteAddress As String) As IPEndPoint Return New IPEndPoint(Dns.Resolve(RemoteAddress).AddressList(0), portICMP) End Function ' ICMP requires a checksum that is the one's ' complement of the one's complement sum of ' all the 16-bit values in the data in the ' buffer. ' Use this procedure to load the Checksum ' field of the buffer. ' The Checksum Field (hi and lo bytes) must be ' zero before calling this procedure. Private Sub CreateChecksum(ByRef data() As Byte, ByVal Size As Integer, ByRef HiByte As Byte, ByRef LoByte As Byte) Dim i As Integer Dim chk As Integer = 0 For i = 0 To Size - 1 Step 2 chk += Convert.ToInt32(data(i) * &H100 + data(i + 1)) Next chk = Convert.ToInt32((chk And &HFFFF&) + Fix(chk / &H10000&)) chk += Convert.ToInt32(Fix(chk / &H10000&)) chk = Not (chk) HiByte = Convert.ToByte((chk And &HFF00) / &H100) LoByte = Convert.ToByte(chk And &HFF) End Sub End Module
-
CRACKED IT! In Form2 (UserManager) I declared :- Public frm3 as Form3 Public frm4 as form4 'etc etc Then in the Activated method of Form3, form4 etc etc I have:- frm2.frm3=Me frm2.frm4=Me Finally, in the Closing event of Form2:- frm3.dispose frm4.dispose 'etc etc Thanks UCM. That's precisely what I needed!! Woohoo!! Happy days! :) I think I'm beginning to get the hang of this OOP lark!
-
OK, I'll try that when I get back to work tomorrow. Watch this space.......
-
OK. Form 1 acts as a control panel in my application. Form 2 is a replica that I've created of the NT User Manager. Form3 lists the currently selected users Shortcuts and profile information etc etc. When a button/menu item on Form1 (controlpanel) is clicked, an input box is displayed asking for a user id. Form1 then creates an instance of Form2 (user manager), not within Form1, but seperate, displaying that users name, description, password info etc. After that, Form1 creates an instance of Form3, again, seperately, that displays that users profile and shortcut information. I want Form3 to be a child of the User Manager form, so that when the User Manager form is closed, Form3 is closed too. Hope this makes more sense UCM and thanks for your help so far.
-
Also, I've set a button on Form2 to display the name of it's MDIChildren. It comes back to say the Form3 is a child, so it is assigning it correctly. However, Form3 never displays itself after the Form3.Show method is called. ???? :(
-
I don't think that's correct. My MenuItem lives on Form1 and is responsible for creating instances of Form2 and Form3 when clicked. I want Form2 to be the parent of Form3. If I specify : Dim frm2 as new Form2() Dim frm3 as new Form3() frm3.mdiParent=Me ...bearing in mind that this code lives on Form1, wouldn't this set Form1 to be Form3's parent?
-
Thanks UCM. That's not what I'm trying to achieve. When a menu item is clicked on Form1, it opens up Form2 and Form3. I don't want Form3 to be inside Form2. When I close Form2, I also want Form3 (and any other child forms) to be closed as well, just leaving Form1. Hope this makes sense. :)
-
I also have an MDI question. I have a Main form (we'll call it form 1) From form1 I have some code that creates two new forms (form2 and form3) I want form2 to be the parent of form3. I am using this code to set the properties. (form2 has it's IsMDIContainer set to True at desing time). on Form1: dim frm2 as new Form2 dim frm3 as new form3 frm3.mdiParent=frm2 frm2.show frm3.show Form2 does indeed display itself, Form3 does not. any ideas?
-
I've figured this out. The structure passed to the NetUserGetInfo API from my LANUser class was declared as a Structure type. I changed it to a subclass and it seems to have solved not only this problem, but also a problem I was having with my app locking up and getting a StackOverflowError. Structure variables are placed on the stack. Class variables are placed on the heap, unless I'm mistaken, and as I was calling the NetUser api each time I wanted to administer a different user, the stack was filling up very quickly!!
-
Oh man, I'm glad that it's not just me!! :)
-
I have two forms. I have this code at the top of the first form (ControlPanel). Public frmUserManager As UserManager Public myUser As LANUser A button on ControlPanel has the following code attached: Private Sub btnAdministerUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdministerUser.Click Dim UserID As String Dim setTop As Short = CShort(MyBase.Top) + CShort(MyBase.Height) Dim setLeft As Short = CShort(MyBase.Left) Try If frmUserManager.Visible = True Then 'frmManagerWindow already exists. End If Catch ex As Exception frmUserManager = New UserManager(setTop, setLeft) Me.myUser = New LANUser() End Try UserID = InputBox("Please enter User ID", "Enter User ID") If Me.myUser.GetUserDetails(UserID, frmUserManager) = True Then frmUserManager.Show() End If End Sub LANUser is a class that has some methods that call the NetUserGetInfo API. After the button on ControlPanel is pressed and the code is fired, the UserManager form is displayed with details from the LANUser class. This works perfectly for seven or eight passes. However, eventually, an error occurs just before displaying the input box that say "Error Creating Window Handle". Has anybody come across this problem before??