|
You could try opening up a TCP/IP Socket on the standard SQL Server port (1433) on each machine you find to see if you can connect...or try to open a named pipe to the machine ("\\.\pipe\sql\query" or "\\.\pipe\MSSQL$instancename\sql\query")...if they succeed, it's probably an SQL server ;o)
"The greatest danger to humanity is humanity without an open mind." - Ian Mariano
http://www.ian-space.com/
|
|
|
|
|
Yes, there is a way to Enumerate Servers on Win9x. However, I can't get the Code I have to work just right in VB.NET. If someone out there can help on this it would be great!!! The only thing it does is it keeps recusing the Top-Level Network Node (i.e. "Microsoft Windows Network" for me).
Here's what I have so far:
<Code>
'Declarations
'API Declarations
Private Declare Auto Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Integer, ByVal dwBytes As Integer) As Integer
Private Declare Auto Function GlobalFree Lib "kernel32" (ByVal hMem As Integer) As Integer
'API Declarations for Win9x
Private Declare Ansi Function WNetOpenEnum Lib "mpr.dll" Alias "WNetOpenEnumA" (ByVal dwScope As Integer, ByVal dwType As Integer, ByVal dwUsage As Integer, ByRef lpNetResource As IntPtr, ByRef lphEnum As Integer) As Integer
Private Declare Ansi Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA" (ByVal hEnum As Integer, ByRef lpcCount As Integer, ByVal lpBuffer As Integer, ByRef lpBufferSize As Integer) As Integer
Private Declare Ansi Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As Integer) As Integer
'Structures
<Runtime.InteropServices.StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure NETRESOURCE
Dim Scope As Integer
Dim Type As Integer
Dim DisplayType As Integer
Dim Usage As Integer
Dim LocalName As IntPtr
Dim RemoteName As IntPtr
Dim Comment As IntPtr
Dim Provider As IntPtr
End Structure
'Constants for WNetEnum
Private Enum ResourceScopes
resConnected = &H1 'All currently connected resources (the dwUsage parameter is ignored)
resGlobalNet = &H2 'All resources on the network.
resRemembered = &H3 'All remembered (persistent) connections (dwUsage is ignored)
resRecent = &H4
resContext = &H5
End Enum
Private Enum ResourceTypes
resAny = &H0 'All resources (this value cannot be combined with RESOURCETYPE_DISK or RESOURCETYPE_PRINT).
resDisk = &H1 'All disk resources.
resPrinter = &H2 'All print resources.
resReserved = &H8
resUnknown = &HFFFF
End Enum
Private Enum ResourceUseages 'Ignored if the ResourceScope is not 'resGlobalNet'
resAll = ((&H1) Or (&H2))
resConnectable = &H1
resContainer = &H2
resNoLocalDevice = &H4
resSibling = &H8
resReserved = &H80000000
End Enum
Private Enum ResourceDisplayTypes 'Used to Determine the Resource Type of the NETRESOURCE Struct
resGeneric = &H0
resDomain = &H1
resServer = &H2
resShare = &H3
resFile = &H4
resGroup = &H5
resNetwork = &H6
resRoot = &H7
resShareAdmin = &H8
resDirectory = &H9
resTree = &HA
End Enum
'Enumerations
Public Enum ServerTypes
All = &HFFFFFFFF '/* handy for NetServerEnum2 */
Browsers = &H10000
Browser_Backup = &H20000
Browser_Master = &H40000
Domains = &H80000000
DomainController = &H8
DomainBackController = &H10
DomainMaster = &H80000
DomainMember = &H100
Novell = &H80
NTClusters = &H1000000 '/* NT Cluster */
Servers = &H2 ' All Servers
ServersDialIn = &H400
ServersLocal = &H40000000
ServersPrintQ = &H200
ServersNT = &H8000
ServersSQL = &H4 ' SQL Server
ServersXenix = &H800
ServersUnix = &H800
TimeServers = &H20
Workstations = &H1
WorkstationsNT = &H1000
WorkstationsWin9x = &H400000 '/* Windows95 and above */
End Enum
'Routine to Refresh Servers on a Win9x Machine (uses Recursion)
Private Sub RefreshServersWin9x(Optional ByVal Domain As String = Nothing)
Dim vResource As NETRESOURCE
Dim hResult, hEnum, hBuffer, hPointer, i As Integer
Dim nBufferSize As Integer = 16384, nCount As Integer = &HFFFFFFFF
Const GMEM_FIXED As Integer = &H0
Const GMEM_ZEROINIT As Integer = &H40
Const GPTR As Integer = (GMEM_FIXED Or GMEM_ZEROINIT)
'Initialize the Buffer Pointer
Dim ptrBuffer As IntPtr = IntPtr.Zero, ptrDomain As IntPtr = IntPtr.Zero
If (Not IsNothing(Domain)) AndAlso (Domain.Length > 0) Then
ptrDomain = Marshal.StringToBSTR(Domain)
ptrBuffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(vResource))
vResource.RemoteName = ptrDomain
Call Marshal.StructureToPtr(vResource, ptrBuffer, True)
End If
Try
hResult = WNetOpenEnum(ResourceScopes.resGlobalNet, ResourceTypes.resAny, ResourceUseages.resContainer, ptrBuffer, hEnum)
If (hResult = 0) And (hEnum <> 0) Then 'Successful
'Enumerate the Resource
hBuffer = GlobalAlloc(GPTR, nBufferSize)
hResult = WNetEnumResource(hEnum, nCount, hBuffer, nBufferSize)
If (hResult = 0) Then 'Successful
hPointer = hBuffer
For i = 0 To nCount - 1
'Retrieve the Information for the Resource
vResource = CType(Marshal.PtrToStructure(New IntPtr(hPointer), GetType(NETRESOURCE)), NETRESOURCE)
'Recurse to Find the Servers if this is a Root or Domain Node
Select Case vResource.DisplayType
Case ResourceDisplayTypes.resDomain, ResourceDisplayTypes.resGroup, ResourceDisplayTypes.resNetwork, ResourceDisplayTypes.resRoot
Call Me.RefreshServersWin9x(Marshal.PtrToStringAnsi(vResource.RemoteName))
End Select
'Determine the Next Pointer
hPointer += Marshal.SizeOf(vResource)
Next i
End If
End If
bInitialized = True
Catch
'Call Globals.ErrorMessage("Refresh")
Finally
'Free Up Memory
Call Marshal.FreeCoTaskMem(ptrBuffer)
Call Marshal.FreeCoTaskMem(ptrDomain)
If (hEnum > 0) Then hResult = WNetCloseEnum(hEnum)
If (hBuffer > 0) Then hResult = GlobalFree(hBuffer)
End Try
End Sub
</Code>
|
|
|
|
|
there is a Microsoft Spreadsheet 10.0 component in VB.NEt.
I dont know how to do data binding with it at run time (by code). plz help me to do that?
--thnx
waiting for a quick reply
Aakash
|
|
|
|
|
|
|
If in VB6, right click on the Forms folder, select Add, then choose MDI Form.
Nick Parker
May your glass be ever full.
May the roof over your head be always strong.
And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing
|
|
|
|
|
Wow, the Zen of MDI...
Pete
Insert Sig. Here!
|
|
|
|
|
I heard that resource(memory) is freed automatically for you in vb.net but not vb6, so i was wondering how do you do it manually in vb6 ?
|
|
|
|
|
Set MyObject = Nothing
Paul
I think there're pieces of me you've never seen - Tori Amos, Tear in Your Hand
|
|
|
|
|
Setting an Object = Nothing does not ALWAYS free the memory in VB6 (this goes for .NET as well). Get familiar with the Objects you are using, if they implement a "Close" or "Dispose" method, ALWAYS use it before Setting your Object = Nothing.
For example, watch ADO eat up memory in a VB6 app. However, when you use the Close method, the memory usage goes way down. It takes a little while for the VB6 runtime to clean up the memory references, but it happens.
|
|
|
|
|
I am trying to add numbers from a listbox
Its working with vb6 but not with vb.net.
That's what I tried but it's not working
Dim sum As Integer
Dim i As Integer
sum = 0
i = 0
For i = 0 To ListBox2.Items.Count - 1
sum = sum + ListBox2.Items(ListBox2.SelectedIndex)
Next i
TextBox5.Text = sum
I would like the sum of what's inside the listbox to appear inside the textbox
Ex: 12 + 12 + 12 from the listbox and sum would be 36 in the textbox
|
|
|
|
|
I'm thinking you might want to go for
sum = sum + CInt(ListBox2.Items(ListBox2.SelectedIndex).Value)
Paul
Why don't you take a good look at yourself and describe what you see - Led Zeppelin, Misty Mountain Hop
|
|
|
|
|
Please respond to forum
Golfmaltais wrote:
it's still makes a error
sum = sum + CInt(ListBox2.Items(ListBox2.SelectedIndex).Value)
public 'Value' type of 'DataRowView' is no where to be found.
Ooops. My bad.
What happens when you use
For i = 0 To ListBox2.Items.Count - 1
sum = sum + ListBox2.Items(ListBox2.SelectedIndex)
Next i
?
Paul
Why don't you take a good look at yourself and describe what you see - Led Zeppelin, Misty Mountain Hop
|
|
|
|
|
PLEASE respond to forum
Golfmaltais wrote:
not valid with type of 'Integer' and type of 'DataRowView'
Hold on! I've only just clicked on to this DataRowView thing.
How is ListBox2 defined? A ListBox item should be of type Object. A DataRowView is an item of a DataView.
[edit]I have this question wrong. I should be asking "How is ListBox2 populated?"[/edit]
Paul
Why don't you take a good look at yourself and describe what you see - Led Zeppelin, Misty Mountain Hop
|
|
|
|
|
I am trying to add numbers from a listbox to to make a total in a texbox its working with vb6 but not with vb.net that what I did and it's not working
Dim sum As Integer
Dim i As Integer
sum = 0
i = 0
For i = 0 To ListBox2.Items.Count - 1
sum = sum + ListBox2.Items(ListBox2.SelectedIndex)
Next i
TextBox5.Text = sum
|
|
|
|
|
Try specifying the property of the object you are referencing in:
sum = sum + ListBox2.Items(ListBox2.SelectedIndex).
In VB6 each data type had a default property, and I don't think VB.NET has this so you need to indicate which property you are reading from. Is it numeric?
HTH
Andy
|
|
|
|
|
Hi,
I wrote a Collection Class(viz: MYCollection)
(Derived from Collection Base).
And have added methods for Add() and Remove().
I have used this Class in a Custom Control,
and exposed a Property of type MyCollection.
Now, the VS.Net IDE does show the Collection Editor
Dialog Box for the Property,but when I add items to the
collection using the Collection Editor, the changes
are not persisted. (ie: The IDE does not Generate code
for the Items added to the collection).
What is to be done to persist the Items Added using
the Collection Editor (ie: to make the VS.Net generate code for the Added Items, just like it does for ListView
Items Collection, for Example)
Someone please help me....
Thanks
|
|
|
|
|
As I said: I want to read the summary information out of an word file.
I got a definition page of a wordfile (v8.0) at http://www.wotsit.org.
But the offsets described in this file seems to be invalid.
Infos:
SummaryInformation -> STTBFASSOC (Table of Associated Strings)
STTBFASSOC -> offset in FIB: 410 0x019A fcSttbfAssoc long
the FIB starts at offset 0x0000
Maybe somebody had the same problem ... and fixed it? So that he can help me...
thx
Martin
|
|
|
|
|
I set the background picture of my main window. But I just can't get rid of it from the attribute window latter. How can I remove it? Thanks
|
|
|
|
|
I have never found a way to do that. You could do what I have always resorted to. Go into the Windows Forms Designer Generated Code region and remove the Form1.BackgroundPicture property. Then save and exit VS.NET. Reopen the thing and it should be gone.
You will now find yourself in a wonderous, magical place, filled with talking gnomes, mythical squirrels, and, almost as an afterthought, your bookmarks
-Shog9 teaching Mel Feik how to bookmark
|
|
|
|
|
Go to the property, mark all the text with the mouse and press DELETE.
It's strange, but it's this way...
lazy isn't my middle name.. its my first.. people just keep calling me Mel cause that's what they put on my drivers license. - Mel Feik
|
|
|
|
|
After many hours of battling with others sample code and sifting through countless message board posts I believe I have managed to come up with a fairly functional and stable encryption and decryption class that utilises multiple encryption methods.
The code is shown below and a sample call would look something like
Dim Crypto As New Crypto(Crypto.Providers.DES)
Dim Encrypted as string = Crypto.Encrypt("Test String", "Keystring")
Dim Decrypted as string = Crypto.Decrypt(Encrypted , "Keystring")
‘Crypto class
Imports System.Security.Cryptography
Imports System.IO
Imports System.Text
'SymmCrypto is a wrapper of System.Security.Cryptography.SymmetricAlgorithm classes
'and simplifies the interface. It supports customized SymmetricAlgorithm as well.
'Original Code from Frank Fang
'Revised by Jerome Howard to remove Bad Data errors, create seperate CryptoIV and
'use the maximum legal keysize for each encryption algorithm
Public Class Crypto
'256 Bit IV Key that is truncated when a smaller keys are required
Private bytIV() As Byte = _
{12, 241, 10, 21, 90, 74, 11, 39, 9, 91, 45, 78, 189, 211, 133, 62, 121, 22, 101, 34, 90, 74, 121, 39, 93, 9, 45, 78, 1, 211, 33, 162}
'Supported .Net intrinsic SymmetricAlgorithm classes.
Public Enum Providers
DES
RC2
Rijndael
End Enum
Private _CryptoService As SymmetricAlgorithm
'Constructor for using an intrinsic .Net SymmetricAlgorithm class.
Public Sub New(ByVal NetSelected As Providers)
Select Case NetSelected
Case Providers.DES
_CryptoService = New DESCryptoServiceProvider()
Case Providers.RC2
_CryptoService = New RC2CryptoServiceProvider()
Case Providers.Rijndael
_CryptoService = New RijndaelManaged()
End Select
End Sub
'Constructor for using a customized SymmetricAlgorithm class.
Public Sub New(ByVal ServiceProvider As SymmetricAlgorithm)
_CryptoService = ServiceProvider
End Sub
'Depending on the legal key size limitations of a specific CryptoService provider
'and length of the private key provided, padding the secret key with a character
'or triming it to meet the legal size of the algorithm.
Private Function GetLegalKey(ByVal Key As String) As Byte()
'key sizes are in bits
Dim sTemp As String
If (_CryptoService.LegalKeySizes.Length > 0) Then
Dim maxSize As Integer = _CryptoService.LegalKeySizes(0).MaxSize
If Key.Length * 8 > maxSize Then
sTemp = Key.Substring(0, (maxSize / 8))
ReDim Preserve bytIV((maxSize / 8) - 1)
Else
Dim moreSize As Integer = _CryptoService.LegalKeySizes(0).MinSize
Do While (Key.Length * 8 > moreSize)
moreSize += _CryptoService.LegalKeySizes(0).SkipSize
Loop
ReDim Preserve bytIV(moreSize / 8)
sTemp = Key.PadRight(moreSize / 8, "X")
End If
Else
sTemp = Key
ReDim Preserve bytIV(Key.Length)
End If
'convert the secret key to byte array
Return ASCIIEncoding.ASCII.GetBytes(sTemp)
End Function
Public Function Encrypt(ByVal Source As String, ByVal Key As String) As String
Dim bytIn As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(System.Web.HttpUtility.UrlEncode(Source))
Dim ms As MemoryStream = New MemoryStream()
'set the keys
_CryptoService.Key = GetLegalKey(Key)
_CryptoService.IV = bytIV
'create an Encryptor from the Provider Service instance
Dim encrypto As ICryptoTransform = _CryptoService.CreateEncryptor()
'create Crypto Stream that transforms a stream using the encryption
Dim cs As CryptoStream = New CryptoStream(ms, encrypto, CryptoStreamMode.Write)
'write out encrypted content into MemoryStream
cs.Write(bytIn, 0, bytIn.Length)
cs.FlushFinalBlock()
cs.Close()
Dim bytOut() As Byte = ms.ToArray()
ms.Close()
Return Convert.ToBase64String(bytOut) 'convert into Base64 so that the result can be used in xml
End Function
Public Function Decrypt(ByVal Source As String, ByVal Key As String) As String
'convert from Base64 to binary
Dim bytIn As Byte() = System.Convert.FromBase64String(Source)
Dim ms As MemoryStream = New MemoryStream(bytIn)
Dim bytKey() As Byte = GetLegalKey(Key)
Dim bytTemp(bytIn.Length) As Byte
'set the private key
_CryptoService.Key = bytKey
_CryptoService.IV = bytIV
'create a Decryptor from the Provider Service instance
Dim encrypto As ICryptoTransform = _CryptoService.CreateDecryptor()
'create Crypto Stream that transforms a stream using the decryption
Dim cs As CryptoStream = New CryptoStream(ms, encrypto, CryptoStreamMode.Read)
Try
'read out the result from the Crypto Stream
cs.Read(bytTemp, 0, bytTemp.Length)
cs.FlushFinalBlock()
ms.Close()
cs.Close()
Catch
End Try
Return System.Web.HttpUtility.UrlDecode(Encoding.ASCII.GetString(bytTemp))
End Function
End Class
|
|
|
|
|
Simple question that has me stumped.
Help!
Chris
|
|
|
|
|
Have a look at the article "Registry handling with .NET" by S Nishant in this site (www.codeproject.com/dotnet/csregistry01.asp).
The VB.NET equivalent is virtually identical.
Imports Microsoft.Win32.Registry
Imports Microsoft.Win32.RegistryKey
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rKey As Microsoft.Win32.RegistryKey
Dim rKey1 As Microsoft.Win32.RegistryKey
rKey = Microsoft.Win32.Registry.LocalMachine
rKey1 = rKey.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion")
ListBox1.Items.Add("RegisteredOwner :- " + rKey1.GetValue("RegisteredOwner"))
ListBox1.Items.Add("RegisteredOrganization :- " + rKey1.GetValue("RegisteredOrganization"))
ListBox1.Items.Add("ProductName :- " + rKey1.GetValue("ProductName"))
ListBox1.Items.Add("CSDVersion :- " + rKey1.GetValue("CSDVersion"))
ListBox1.Items.Add("SystemRoot :- " + rKey1.GetValue("SystemRoot"))
rKey1.Close()
End Sub
HTH
Andy
|
|
|
|
|
Heya - I also had a bit of trouble with the registry. I can modify it easy enough but I can't get it to refresh without restarting the computer. Is there some way to force Windows to reload the registry without restarting?
Thanks
Nic R
------------------------------------------
I beat the internet - the end guy is hard.
|
|
|
|
|