|
There is a COM library for accessing Word, Excel, Access databases etc. Just add a reference or component or what-ever it's called in VB6 and it should be pretty obvious from there on (sorry havn't used VB6 for 2 years or so but I do remember playing around with it).
The Welsh will always support two teams: The Welsh, and anyone playing England
|
|
|
|
|
I am trying to write a piece of code that spawns a window when the user presses both mouse buttons simultaneously.
I have been thinking the only way to do this would be to have two mouse hooks, watching for left and right clicks respectively, and checking the time difference between clicks. It would then cancel the message if the time is within a certain interval, and show the window.
Any better ideas? Please?
All your source are belong to us!
|
|
|
|
|
The easiest way would be to handle the click event and check the state of the buttons inside the event. The following will close the form if both buttons are depressed:
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e _<br />
As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick<br />
If e.Button = Windows.Forms.MouseButtons.Left Then<br />
If MouseButtons = Windows.Forms.MouseButtons.Right Then<br />
Me.Close()<br />
End If<br />
End If<br />
If e.Button = Windows.Forms.MouseButtons.Right Then<br />
If MouseButtons = Windows.Forms.MouseButtons.Left Then<br />
Me.Close()<br />
End If<br />
End If<br />
End Sub<br />
Hope this helps.
Keith
|
|
|
|
|
There would be no form present when watching for mouse clicks. This is why I have suggested using a mouse hook.
All your source are belong to us!
|
|
|
|
|
I have a form that has ftp information entered and the program connected to the website. The next time a user starts the program, I want that info to be in a pull down for them to select. Eventully, the pulldown will have several websites ftp info stored in them. I was thinking of storing the info in an xml file but I realize this is not very secure. Is there a better way to store this information.
Almerica
|
|
|
|
|
Just encrypt the sensitive data. The only problem then is encrypting the encryption keys, and encrypting the encrypted encryption keys......
It's all a balance of how much security you need but the .NET Framework's System.Security.Cryptography namespace will help you out, there are assymetric and symmetric algorithms there including RSA and TripleDES.
The Welsh will always support two teams: The Welsh, and anyone playing England
|
|
|
|
|
Hi there.
You can either save the information in the registry or in a XML file, but you should incript the data to make in more secure. There is DLL's and source code available to encode and decode data. For example CryptoAPI.cls. This is a VB6 based class module that I use to encrypt data.
Hope this will help you in some way.
A programmer's life is good... or is it?? Ek dink nie so nie!
|
|
|
|
|
I am wondering what is an xml editor and if an application provide that, what can you do with it?
|
|
|
|
|
its edits xml files duh!! lol .. well u have to look up what xml is first.If u know xml(i doubt it) , an xml editor smartly allows u to edit xml files.For eg.
if u have this piece of xml in an xml file
<question status="answered"> What is XML?</question>
normally u could just edit it in notepad , but an xml edit would allow u to 'smartly' edit the file as in it would be able to change the value of status or the node value etc,, if what i'm sayin is bouncing of your head i really suggest reading something on what xml is.And its really helpful nowadays , a lot of things are based on XML.
Gideon
-- modified at 2:44 Sunday 16th July, 2006
|
|
|
|
|
hey sorry but i did'nt know that xml example was'nt going to show up! the html parser took it off.So i modified the above message.
|
|
|
|
|
Hi
The first set of source code is the class for a combobox in a grid,
hopefully. In the second set of code we try to use the combobox class, but
the grid is empty.
I don't understand how this works. The first set of code I downloaded from
internet and when i tried it, it worked fine. But when I changed the second
part of the code it started to give me trouble. Before I changed the code
they used Datacolumns,Datarows and Datatables and added them to the Dataset
which they used to the Datagrid and it worked fine. I don't understand what
is wrong know that I'm using a table I haven't "made" myself but a table I
got from a connection. As the third set of code showing, when using
comboboxes you can set the Datasource to a table you have connected to with
a connection and it works fine, so I think the second part of code should
work, but the grid is empty when the program starts.
If there is anyone who understand my problem and have a solution, please
give me an answer.
Thanks
Fia
'The MyComboColumn class
Imports System.Data
Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Namespace ComboBoxTest
Public Class MyComboColumn
Inherits System.Windows.Forms.DataGridTextBoxColumn
Private _cboColumn As ComboBox
Private _objSource As Object
Private _strMember As String
Private _strValue As String
Private _bIsComboBound As Boolean = False
Private _backBrush As Brush = Nothing
Private _foreBrush As Brush = Nothing
Private _iRowNum As Integer
Private _cmSource As CurrencyManager
Public Sub New(ByVal objSource As DataSet, ByVal strMember As String, ByVal
strValue As String, ByVal bUseDropDownList As Boolean)
'_objSource = objSource
_strMember = strMember
_strValue = strValue
_cboColumn = New ComboBox
_cboColumn.DataSource = objSource.Tables(0)
_cboColumn.DisplayMember = _strMember
_cboColumn.ValueMember = _strValue
If bUseDropDownList = True Then
_cboColumn.DropDownStyle = ComboBoxStyle.DropDownList
Me.ReadOnly = True
Else
'AddHandler _cboColumn.KeyPress, AddressOf _cboColumn_KeyPress
AddHandler _cboColumn.KeyUp, AddressOf _cboColumn_KeyUp
End If
AddHandler _cboColumn.Leave, AddressOf cboColumn_Leave
_cboColumn.Visible = False
End Sub
Private Sub _cboColumn_KeyPress(ByVal sender As Object, ByVal e As
KeyPressEventArgs)
e.Handled = True
End Sub
Private Shadows Sub _cboColumn_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs)
Dim index As Integer
Dim actual As String
Dim found As String
' Do nothing for certain keys such as navigation keys
If ((e.KeyCode = Keys.Back) Or _
(e.KeyCode = Keys.Left) Or _
(e.KeyCode = Keys.Right) Or _
(e.KeyCode = Keys.Up) Or _
(e.KeyCode = Keys.Delete) Or _
(e.KeyCode = Keys.Down) Or _
(e.KeyCode = Keys.PageUp) Or _
(e.KeyCode = Keys.PageDown) Or _
(e.KeyCode = Keys.Home) Or _
(e.KeyCode = Keys.ShiftKey) Or _
(e.KeyCode = Keys.End)) Then
Return
End If
' Store the actual text that has been typed
actual = _cboColumn.Text
' Find the first match for the typed value
index = _cboColumn.FindString(actual)
' Get the text of the first match
If (index > -1) Then
found = _cboColumn.Items(index).ToString()
' Select this item from the list
_cboColumn.SelectedIndex = index
' Select the portion of the text that was automatically
' added so further typing will replace it
_cboColumn.SelectionStart = actual.Length
_cboColumn.SelectionLength = found.Length
End If
End Sub
Protected Overloads Overrides Sub Edit(ByVal source As CurrencyManager,
ByVal rowNum As Integer, ByVal bounds As Rectangle, ByVal [ReadOnly] As
Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
If _bIsComboBound = False Then
_bIsComboBound = True
Me.DataGridTableStyle.DataGrid.Controls.Add(_cboColumn)
End If
_iRowNum = rowNum
_cmSource = source
_cboColumn.Font = Me.TextBox.Font
Dim anObj As Object = Me.GetColumnValueAtRow(source, rowNum)
_cboColumn.Bounds = bounds
_cboColumn.BeginUpdate()
_cboColumn.Visible = True
If Not (anObj.GetType Is System.DBNull.Value) Then
'TextObject Is System.DBNull.Value
_cboColumn.SelectedValue = anObj
Else
_cboColumn.SelectedIndex = 0
End If
_cboColumn.EndUpdate()
_cboColumn.Focus()
End Sub
Public Sub cboColumn_Leave(ByVal sender As Object, ByVal e As EventArgs)
Dim objValue As Object = _cboColumn.SelectedValue
If objValue Is Nothing Then
objValue = DBNull.Value
Else
Me.SetColumnValueAtRow(_cmSource, _iRowNum, objValue)
End If
_cboColumn.Visible = False
End Sub
Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As
Rectangle, ByVal source As CurrencyManager, ByVal rowNum As Integer, ByVal
backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)
Dim strCountry As String = "Huh?"
Dim aRowA As DataRow()
Dim anObj As Object = Me.GetColumnValueAtRow(source, rowNum)
Dim aType As Type = anObj.GetType
If Not (aType.GetType Is System.DBNull.Value) Then
aRowA = CType(_objSource, DataTable).Select(_strValue + " = " +
anObj.ToString)
Else
aRowA = CType(_objSource, DataTable).Select
End If
If aRowA.Length > 0 Then
strCountry = aRowA(0)(_strMember).ToString
End If
Dim rect As Rectangle = bounds
Dim rectF As RectangleF = rectF.op_Implicit(rect) ' Convert to
If Me._backBrush Is Nothing Then
g.FillRectangle(backBrush, rect)
Else
g.FillRectangle(_backBrush, rect)
End If
rect.Y += 2
If Me._foreBrush Is Nothing Then
'g.DrawString(Text, Me.DataGridTableStyle.DataGrid.Font, ForeBrush, RectF,
Format)
g.DrawString(strCountry, Me.TextBox.Font, foreBrush, rectF)
Else
g.DrawString(strCountry, Me.TextBox.Font, _foreBrush, rectF)
End If
End Sub
Public WriteOnly Property backgroundColour() As System.Drawing.Color
Set(ByVal Value As System.Drawing.Color)
If Value.Equals(System.Drawing.Color.Transparent) Then
Me._backBrush = Nothing
Else
Me._backBrush = New SolidBrush(Value)
End If
End Set
End Property
Public WriteOnly Property foregroundColour() As System.Drawing.Color
Set(ByVal Value As System.Drawing.Color)
If Value.Equals(System.Drawing.Color.Transparent) Then
Me._foreBrush = Nothing
Else
Me._foreBrush = New SolidBrush(Value)
End If
End Set
End Property
End Class
End Namespace
----------------------------------------------------------------------------
----------------------------------------------------------------------------
------------------------------------
'The Form's class
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Imports ReceptNet.ComboBoxTest
Public Class DataGridSample
Inherits Form
Private ds As DataSet
Private myGrid As DataGrid
Shared Sub Main()
Application.Run(New DataGridSample)
End Sub
Private Sub ConnectToData()
Dim AppPath As String = Replace(Replace(Application.ExecutablePath,
Application.ProductName + ".exe", ""), Application.ProductName + ".exe", "")
& "Recept.mdb"
Dim cString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
AppPath
Dim cn As System.Data.OleDb.OleDbConnection = New
System.Data.OleDb.OleDbConnection(cString)
Dim adpTables As System.Data.OleDb.OleDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
adpTables.TableMappings.Add("Table", "Kött")
cn.Open()
Dim cmdTable As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT * FROM
Kryddor", cn)
cmdTable.CommandType = CommandType.Text
adpTables.SelectCommand = cmdTable
ds = New DataSet("Customers")
adpTables.Fill(ds)
cn.Close()
Dim GridTableStyle As DataGridTableStyle = New DataGridTableStyle
GridTableStyle.MappingName = "Kött"
Me.myGrid.TableStyles.Add(GridTableStyle)
AddStyle(myGrid,ds)
End Sub
Private Sub AddStyle(ByVal grdSrc As DataGrid, ByVal dataS As DataSet)
Dim aCboCol As MyComboColumn = New MyComboColumn(dataS, "KöttID", "", False)
aCboCol.Width = 129
aCboCol.MappingName = "KöttID"
aCboCol.HeaderText = "Kött"
myGrid.TableStyles("Kött").GridColumnStyles.Add(aCboCol)
End Sub
Private Sub DataGridSample_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ConnectToData()
End Sub
End Class
----------------------------------------------------------------------------
----------------------------------------------------------------------------
------------------------------------
Me.cboDatum.DataSource = ds.Tables(1)
cboDatum.DisplayMember = "KöttID"
cboDatum.ValueMember = ""
|
|
|
|
|
How can use DataGrid .... so that i would like to fill it from database after that i would like to change the values of it then i would like to view report with new data that i filled from DataGrid.
|
|
|
|
|
Hallo ,
i think this is help you.
http://www.codeproject.com/csharp/webservicecache.asp
Regards Thomas
|
|
|
|
|
I want to move form with control label on the form, can anyone help me?
Thanks
................
|
|
|
|
|
Uhhh.... What?
Are you asking how to move a form by holding the mouse button down on a control on the form??
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I have code for that.
Put this at the top of your form class(in the declarations area):
Private Declare Function ReleaseCapture Lib "user32" () As Integer
'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As Integer) As Integer
Private Const HTCAPTION As Short = 2
Private Const WM_NCLBUTTONDOWN As Short = &HA1S
Private Const WM_SYSCOMMAND As Short = &H112S
And put this in the label_mousedown sub:
Dim Button As Short = Button \ &H100000
Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
Dim X As Single = (X)
Dim Y As Single = (Y)
ReleaseCapture()
SendMessage(Handle.ToInt32, WM_NCLBUTTONDOWN, HTCAPTION, 0)
Now when you hold the mouse down on that label, you will be able to move the form around.
Posted by The ANZAC
-- modified at 22:53 Friday 14th July, 2006
|
|
|
|
|
Even Better:
Put this at the top of your form class(in the declarations area):
Private Declare Function ReleaseCapture Lib "user32" () As Integer
'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As Integer) As Integer
But Put the rest in a public sub named MoveForm:
Dim Button As Short = Button \ &H100000
Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
Dim X As Single = (X)
Dim Y As Single = (Y)
ReleaseCapture()
SendMessage(Handle.ToInt32, WM_NCLBUTTONDOWN, HTCAPTION, 0)
And in your label_MouseDown Sub call the MoveForm Sub:
Posted by The ANZAC
|
|
|
|
|
You might want to reply to the orignal poster with this. That way, he gets the email message that you replied to HIS post.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
How do you make your program run other executable programs, i have tried open but it doesn't work. I tried to structure a process, but am not sure how to do it properly.
I am using Visual Basic 2005 Express Edition (Version 8). The executable is called "Install.exe" but the method i used to locate it holds it in a sttring called objFile.
Thankyou in advance.
Posted by The ANZAC
|
|
|
|
|
Call Process.Start(...) method. For more info, check this[^] out.
Best,
Jun
|
|
|
|
|
Thankyou
Posted by The ANZAC
|
|
|
|
|
|
hi all
i am designing a paintbrush i am stuck on combobox i am using a combobox fill with images as a texture i already add all images in combobox as a texture but now i want to implement images as a texture so i need help how to implement selected image/texture on my second image or painting give me some idea
syed imran azmat
|
|
|
|
|
Hi, to all
I am trying to retrieve HDD serialnumber.
I is fairly done in DiskID32 (just google it if you do not know what DiskID32 is) with differet methods.
I am trying to simulate same functionality in VB.
I am not doing anything new just trying to convert DiskID32 to VB.
I have written lot of code but stuck with DeviceIOControl.
There are two functions
1. ReadPhysicalDriveInNTWithZeroRights
- to read HDD SN without admin rights
In this function DeviceIOControl fail with errorcode 1306
i.e. "Indicates two revision levels are incompatible."
2. ReadIdeDriveAsScsiDriveInNT - to read HDD from SCSI Back door
In this function DeviceIOControl fail with errorcode 87
i.e. Invalid Parameter value
Please help me to solve this problem.
Below is the source code (copy it into a form and hit F5)
'==============================================================
Option Explicit
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const FILE_ANY_ACCESS = 0
Private Const OPEN_EXISTING = 3
Private Const CREATE_NEW = 1
Private Const INVALID_HANDLE_VALUE = -1
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const IDENTIFY_BUFFER_SIZE = 512
Private Const OUTPUT_DATA_SIZE = IDENTIFY_BUFFER_SIZE + 16
'IOCTL commands
Private Const DFP_GET_VERSION = &H74080
Private Const DFP_SEND_DRIVE_COMMAND = &H7C084
Private Const DFP_RECEIVE_DRIVE_DATA = &H7C088
Private Const FILE_DEVICE_SCSI = &H1B
Private Const IOCTL_SCSI_MINIPORT_IDENTIFY = ((FILE_DEVICE_SCSI * 65536) + &H501)
Private Const IOCTL_SCSI_MINIPORT = &H4D008 'see NTDDSCSI.H for definition
'Bits returned in the fCapabilities member of GETVERSIONOUTPARAMS
Private Const CAP_IDE_ID_FUNCTION = 1 'ATA ID command supported
Private Const CAP_IDE_ATAPI_ID = 2 'ATAPI ID command supported
'Valid values for the bCommandReg member of IDEREGS.
Private Const IDE_ATA_IDENTIFY = &HEC 'Returns ID sector for ATA.
Private Const IDE_ATAPI_IDENTIFY = &HA1 'Returns ID sector for ATAPI.
'GETVERSIONOUTPARAMS contains the data returned
'from the Get Driver Version function
Private Type GETVERSIONOUTPARAMS
bVersion As Byte 'Binary driver version.
bRevision As Byte 'Binary driver revision
bReserved As Byte 'Not used
bIDEDeviceMap As Byte 'Bit map of IDE devices
fCapabilities As Long 'Bit mask of driver capabilities
dwReserved(3) As Long 'For future use
End Type
'IDE registers
Private Type IDEREGS
bFeaturesReg As Byte 'Used for specifying SMART "commands"
bSectorCountReg As Byte 'IDE sector count register
bSectorNumberReg As Byte 'IDE sector number register
bCylLowReg As Byte 'IDE low order cylinder value
bCylHighReg As Byte 'IDE high order cylinder value
bDriveHeadReg As Byte 'IDE drive/head register
bCommandReg As Byte 'Actual IDE command
bReserved As Byte 'reserved for future use - must be zero
End Type
'SENDCMDINPARAMS contains the input parameters for the
'Send Command to Drive function
Private Type SENDCMDINPARAMS
cBufferSize As Long 'Buffer size in bytes
irDriveRegs As IDEREGS 'Structure with drive register values.
bDriveNumber As Byte 'Physical drive number to send command to (0,1,2,3).
bReserved(2) As Byte 'Bytes reserved
dwReserved(3) As Long 'DWORDS reserved
bBuffer() As Byte 'Input buffer.
End Type
'Status returned from driver
Private Type DRIVERSTATUS
bDriverError As Byte 'Error code from driver, or 0 if no error
bIDEStatus As Byte 'Contents of IDE Error register
'Only valid when bDriverError is SMART_IDE_ERROR
bReserved(1) As Byte
dwReserved(1) As Long
End Type
Private Type IDSECTOR
wGenConfig As Integer
wNumCyls As Integer
wReserved As Integer
wNumHeads As Integer
wBytesPerTrack As Integer
wBytesPerSector As Integer
wSectorsPerTrack As Integer
wVendorUnique(2) As Integer
sSerialNumber(19) As Byte
wBufferType As Integer
wBufferSize As Integer
wECCSize As Integer
sFirmwareRev(7) As Byte
sModelNumber(39) As Byte
wMoreVendorUnique As Integer
wDoubleWordIO As Integer
wCapabilities As Integer
wReserved1 As Integer
wPIOTiming As Integer
wDMATiming As Integer
wBS As Integer
wNumCurrentCyls As Integer
wNumCurrentHeads As Integer
wNumCurrentSectorsPerTrack As Integer
ulCurrentSectorCapacity As Long
wMultSectorStuff As Integer
ulTotalAddressableSectors As Long
wSingleWordDMA As Integer
wMultiWordDMA As Integer
bReserved(127) As Byte
End Type
'Structure returned by SMART IOCTL commands
Private Type SENDCMDOUTPARAMS
cBufferSize As Long 'Size of Buffer in bytes
DRIVERSTATUS As DRIVERSTATUS 'Driver status structure
bBuffer() As Byte 'Buffer of arbitrary length for data read from drive
End Type
Private Type SRB_IO_CONTROL
HeaderLength As Long
Signature(8) As Byte
Timeout As Long
ControlCode As Long
ReturnCode As Long
Length As Long
End Type
'Status Flags Values
Private Enum STATUS_FLAGS
PRE_FAILURE_WARRANTY = &H1
ON_LINE_COLLECTION = &H2
PERFORMANCE_ATTRIBUTE = &H4
ERROR_RATE_ATTRIBUTE = &H8
EVENT_COUNT_ATTRIBUTE = &H10
SELF_PRESERVING_ATTRIBUTE = &H20
End Enum
Private Type ATTR_DATA
AttrID As Byte
AttrName As String
AttrValue As Byte
ThresholdValue As Byte
WorstValue As Byte
StatusFlags As STATUS_FLAGS
End Type
Private Enum IDE_DRIVE_NUMBER
PRIMARY_MASTER
PRIMARY_SLAVE
SECONDARY_MASTER
SECONDARY_SLAVE
TERTIARY_MASTER
TERTIARY_SLAVE
QUARTIARY_MASTER
QUARTIARY_SLAVE
End Enum
Private Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" _
(ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
lpSecurityAttributes As Any, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function DeviceIoControl Lib "kernel32" _
(ByVal hDevice As Long, _
ByVal dwIoControlCode As Long, _
lpInBuffer As Any, _
ByVal nInBufferSize As Long, _
lpOutBuffer As Any, _
ByVal nOutBufferSize As Long, _
lpBytesReturned As Long, _
lpOverlapped As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(hpvDest As Any, _
hpvSource As Any, _
ByVal cbCopy As Long)
Private Declare Function lstrcpyn Lib "kernel32" Alias "lstrcpynA" (ByVal lpString1 As String, ByVal lpString2 As String, ByVal iMaxLength As Long) As Long
Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
'============================================
'
' TO READ Serial No. with zero admin rights
'
'============================================
Private Const IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER As Long = &H2D0C10
Dim IOCTL_STORAGE_QUERY_PROPERTY As Long
Private Const METHOD_BUFFERED = 0
Private Const FILE_DEVICE_MASS_STORAGE = &H2D
Private Const IOCTL_STORAGE_BASE = FILE_DEVICE_MASS_STORAGE
'Types of queries
Private Enum STORAGE_QUERY_TYPE
PropertyStandardQuery = 0 'Retrieves the descriptor
PropertyExistsQuery = 1 'Used to test whether the descriptor is supported
PropertyMaskQuery = 2 'Used to retrieve a mask of writeable fields in the descriptor
PropertyQueryMaxDefined = 3 'use to validate the value
End Enum
'define some initial property id's
Private Enum STORAGE_PROPERTY_ID
StorageDeviceProperty = 0
StorageAdapterProperty = 1
End Enum
Private Enum STORAGE_BUS_TYPE
BusTypeUnknown = 0
BusTypeScsi
BusTypeAtapi
BusTypeAta
BusType1394
BusTypeSsa
BusTypeFibre
BusTypeUsb
BusTypeRAID
BusTypeiSCSI
BusTypeSATA
BusTypeSAS
BusTypeMaxReserved = &H7F
End Enum
'Query structure - additional parameters for specific queries can follow the header
Private Type STORAGE_PROPERTY_QUERY
PropertyId As STORAGE_PROPERTY_ID 'ID of the property being retrieved
QueryType As STORAGE_QUERY_TYPE 'Flags indicating the type of query being performed
AdditionalParameters(1) As Byte 'Space for additional parameters if necessary
End Type
'Device property descriptor - this is really just a rehash of the inquiry
'data retrieved from a scsi device
'
'This may only be retrieved from a target device. Sending this to the bus
'will result in an error
Private Type STORAGE_DEVICE_DESCRIPTOR
Version As Long
Size As Long
DeviceType As Byte
DeviceTypeModifier As Byte
RemovableMedia As Boolean
CommandQueueing As Boolean
VendorIdOffset As Long
ProductIdOffset As Long
ProductRevisionOffset As Long
SerialNumberOffset As Long
BusType As STORAGE_BUS_TYPE
RawPropertiesLength As Long
RawDeviceProperties(1) As Byte
End Type
Private Type MEDIA_SERAL_NUMBER_DATA
SerialNumberLength As Long
Result As Long
Reserved(2) As Long
SerialNumberData(1) As Byte
End Type
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Function CTL_CODE(lngDevFileSys As Long, lngFunction As Long, lngMethod As Long, lngAccess As Long) As Long
CTL_CODE = (lngDevFileSys * (2 ^ 16)) Or (lngAccess * (2 ^ 14)) Or (lngFunction * (2 ^ 2)) Or lngMethod
End Function
Private Function ReadPhysicalDriveInNTWithZeroRights() As Long
Dim drive As Integer
Dim hPhysicalDriveIOCTL As Long
Dim driveName As String
Dim lastError As Long
IOCTL_STORAGE_QUERY_PROPERTY = CTL_CODE(IOCTL_STORAGE_BASE, &H500, METHOD_BUFFERED, FILE_ANY_ACCESS)
For drive = PRIMARY_MASTER To QUARTIARY_SLAVE
driveName = "\\.\PhysicalDrive" & drive
hPhysicalDriveIOCTL = CreateFile(driveName, 0, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, _
OPEN_EXISTING, 0, ByVal 0&)
'MsgBox hPhysicalDriveIOCTL
If hPhysicalDriveIOCTL <> INVALID_HANDLE_VALUE Then
Dim query As STORAGE_PROPERTY_QUERY
Dim cbBytesReturned As Long
Dim bBuffer(10000) As Byte
Dim ret As Long
Dim SDD As STORAGE_DEVICE_DESCRIPTOR
query.PropertyId = StorageDeviceProperty
query.QueryType = PropertyStandardQuery
ret = DeviceIoControl(hPhysicalDriveIOCTL, _
IOCTL_STORAGE_QUERY_PROPERTY, _
query, Len(query), _
bBuffer(0), 10001, _
cbBytesReturned, ByVal 0&)
lastError = GetLastError
If ret <> 0 Then
CopyMemory SDD, bBuffer(0), Len(SDD)
Dim SerialNumber(1000) As Byte
Dim modelNumber(1000) As Byte
lstrcpy SerialNumber(0), SDD.SerialNumberOffset
MsgBox "Serial : " & StrConv(SwapBytes(SerialNumber), vbUnicode)
Else
MsgBox driveName & " handle : " & hPhysicalDriveIOCTL & vbCrLf & "DeviceIoControl ERROR : " & lastError
End If
End If
CloseHandle hPhysicalDriveIOCTL
Next
End Function
Private Function ReadIdeDriveAsScsiDriveInNT() As Long
Dim SENDIDLENGTH As Long
Dim sOutParam As SENDCMDOUTPARAMS
Dim sINParam As SENDCMDINPARAMS
Dim counter As Integer
Dim controller As Integer
Dim drive As Integer
Dim driveName As String
Dim hScsiDriveIOCTL As Long
Dim p As SRB_IO_CONTROL
Dim buffer() As Byte
Dim dummy As Long
Dim IDSEC As IDSECTOR
Dim ret As Long
Dim lastError As Long
SENDIDLENGTH = Len(sOutParam) + IDENTIFY_BUFFER_SIZE
controller = 0
For controller = 0 To 15
driveName = "\\.\Scsi" & controller & ":"
'Try to get a handle to PhysicalDrive IOCTL, report failure
hScsiDriveIOCTL = CreateFile(driveName, _
GENERIC_READ Or GENERIC_WRITE, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, _
OPEN_EXISTING, 0&, 0&)
Debug.Print driveName & " handle = " & hScsiDriveIOCTL
If hScsiDriveIOCTL <> INVALID_HANDLE_VALUE Then
drive = 0
For drive = 0 To 1
ReDim buffer(0 To LenB(p) + SENDIDLENGTH)
p.HeaderLength = LenB(p)
p.Timeout = 10000
p.Length = SENDIDLENGTH
p.ControlCode = IOCTL_SCSI_MINIPORT_IDENTIFY
'lstrcpyn p.Signature(0), "SCSIDISK", 8
p.Signature(0) = Asc("S")
p.Signature(1) = Asc("C")
p.Signature(2) = Asc("S")
p.Signature(3) = Asc("I")
p.Signature(4) = Asc("D")
p.Signature(5) = Asc("I")
p.Signature(6) = Asc("S")
p.Signature(7) = Asc("K")
p.Signature(8) = Asc(vbNullChar)
'MsgBox StrConv(p.Signature, vbUnicode)
'sINParam.irDriveRegs.bFeaturesReg = 0
'sINParam.irDriveRegs.bSectorCountReg = 1
'sINParam.irDriveRegs.bCylLowReg = 0
'sINParam.irDriveRegs.bCylHighReg = 0
'sINParam.irDriveRegs.bDriveHeadReg = &HA0
sINParam.irDriveRegs.bCommandReg = IDE_ATA_IDENTIFY
sINParam.bDriveNumber = drive
CopyMemory buffer(0), p, Len(p)
CopyMemory buffer(LenB(p)), sINParam, LenB(sINParam)
ret = DeviceIoControl(hScsiDriveIOCTL, _
IOCTL_SCSI_MINIPORT, _
buffer(0), _
LenB(p) + LenB(sINParam) - 1, _
buffer(0), _
LenB(p) + SENDIDLENGTH, _
dummy, _
ByVal 0&)
lastError = GetLastError
'ret is gettig errorcode 1306
'means "Indicates two revision levels are incompatible."
If ret <> 0 Then
CopyMemory IDSEC, buffer(LenB(p)), LenB(IDSEC)
MsgBox "Model = " & StrConv(SwapBytes(IDSEC.sModelNumber), vbUnicode)
MsgBox "SerialNumber = " & StrConv(SwapBytes(IDSEC.sSerialNumber), vbUnicode)
Else
MsgBox driveName & " handle : " & hScsiDriveIOCTL & vbCrLf & "DeviceIoControl ERROR : " & lastError
End If
Next drive
End If
Next
End Function
Private Function SwapBytes(b() As Byte) As Byte()
Dim bTemp As Byte
Dim cnt As Long
For cnt = LBound(b) To UBound(b) Step 2
bTemp = b(cnt)
b(cnt) = b(cnt + 1)
b(cnt + 1) = bTemp
Next cnt
SwapBytes = b()
End Function
Private Sub Form_Load()
MsgBox "Calling ReadPhysicalDriveInNTWithZeroRights"
ReadPhysicalDriveInNTWithZeroRights
MsgBox "Calling ReadIdeDriveAsScsiDriveInNT"
ReadIdeDriveAsScsiDriveInNT
End
End Sub
'======================================================
|
|
|
|
|
Hi,
There is a requirement to insert data into Bulk like 20,000 - 30,000 rows into database.
Description:
I have to get one number from text file,bifercate that number and from 1st 5 digit i have to find out ID from sql server 2005 table and then go for second number of that number ,find out ID from sql server 2005 table,this process happens for 4 times for that one number and i have to do same process for 20000 rows.
Once i get all those IDs into variables into vb.net from sql server 2005,i have to insert those into one physical table and than one package will run that insert those records into another table.
Here main problem i am feeling is speed issue,to process 20000 rows for getting ids and inserting back into sql server takes somuch time.
So can some body help me out which way to go to insert records into database?
thanks
montu3377
|
|
|
|
|