|
Hello,
I want to find the harddisk serial number,(not volume serial) using VB.net
CAn anyone guide me or give some link for help,
Any help would be appreciated.
Thank You.
|
|
|
|
|
|
Thanks For your reply,
I have found a code in VB which when run in Administrator Login works perfectly and gives me the Serial No.
But when i run the same code under normal or Limited User, The code does not give the Serial No.
I have gone through the code to find the difference, this is where i found the difference,
SmartOpen = CreateFile("\\.\PhysicalDrive" & CStr(drvNumber), _
GENERIC_READ Or GENERIC_WRITE, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, _
ByVal 0&, _
OPEN_EXISTING, _
0&, _
0&)
The CreateFile function returns a value >0 in Admin Mode but in User Mode it returns -1.
Can any one please tell me what exactly is happening in the above code and what does this CreateFile Function do.
Please , it's Urgent.
Thanks in Advance,
|
|
|
|
|
CreateFile is a Windows API that is used to open several kinds of devices like files, folders, COM ports, pipes, mailslots etc.
It can also open a physical disk drive or volume like in the example you have posted.
The MSDN documentation for CreateFile clearly states that opening a physical disk is dangerous and will require administrative privileges.
Check the Physical Disks and Volumes section in the following link
http://msdn.microsoft.com/en-us/library/aa363858(VS.85).aspx[^]
«_Superman_»
|
|
|
|
|
Hi,
I discovered the same stuff a year ago when I started using Vista.
In short:
- in order to get the drive serial number you need low-level access to it, i.e. a CreateFile
- although reading some properties is all you need, Vista will not allow you to do so when not running
as administrator. (Try dropping the GENERIC_WRITE).
IMO there is no way around it, disk serial numbers are no longer available to regular users!
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
We have a VS 2003 solution containing 1 vb project and several c# projects. The problem is when i try to build the vb project either VS exits or stuck at "performing main compilation". Please help
|
|
|
|
|
i want to validate the check box present inside the datagrid...
checked or not...
asp.net using c#
foreach (DataGridItem i in DataGrid1 .Items )
{
CheckBox chk = (CheckBox)i.FindControl ("chkbox");
if (chk.Checked )
{
}
}
// i use this to code to add checkbox in data grid
<asp:templatecolumn headertext="Approve" xmlns:asp="#unknown">
<itemtemplate>
<asp:checkbox id="chkbox" runat="server">
if u not able to understand my question plz ask me i will explain..
it is not working properly..
|
|
|
|
|
|
I'm looking for decent article/tutorial demonstrating how to use XmlTextReader to read XML into a (large) object tree. So far the articles are only showing a simple while (reader.Read()) { bla; } loop.
Anyone ever used XmlTextReader to do some serious parsing? Otherwise I'll just go with the XmlDocument thing, that seems to be a lot easier, but I'm curious if anyone has a nice real world usage pattern for XmlTextReader.
Wout
|
|
|
|
|
wout de zeeuw wrote: demonstrating how to use XmlTextReader to read XML into a (large) object tree
wout de zeeuw wrote: Otherwise I'll just go with the XmlDocument thing
The XmlDocument thing is an object tree so why wouldn't you just use it anyway?
|
|
|
|
|
Well, XmlDocument is the easier choice I agree. But if one were to use XmlTextReader to do it, how would that be done typically. I'm just curious if there's a standard way of handling this. I've experimented a bit with XmlTextReader, and I can get things working, but the end result of how I do it feels a bit kludgy.
Wout
|
|
|
|
|
XMLDocument is using a reader internally. You can use reflector to see how reader is used inside that. I think that will help you to understand the usage.
|
|
|
|
|
Nah, XmlDocument builds something generic, but the idea is to parse into a type safe tree of classes. But thanks for the suggestion anyway.
Wout
|
|
|
|
|
wout de zeeuw wrote: but the idea is to parse into a type safe tree of classes
Um, wouldn't that be Serialization?
|
|
|
|
|
Yeah, sort of, except that I want to deserialize an object graph (i.e. objects are sometimes referenced, rather than owned) using my custom xml format (I need tight control over the xml format). I'm now doing a custom implementation, just to see how it ends up... it's a bit involved (but not terrible), see e.g. typical code snippet below:
public static DbTable Read(DbProjectBuilder projectBuilder, XmlTextReader r) {
DbTable table = new DbTable();
bool isEmptyElement = XmlUtil.ReadStartElement(r, "Table");
while (r.IsStartElement()) {
switch (r.Name) {
case "Name":
table.Name = r.ReadElementString();
break;
case "Notes":
table.Notes = r.ReadElementString();
break;
case "PrimaryKeyType":
table.PrimaryKeyType =
(DbPrimaryKeyType)Enum.Parse(typeof(DbPrimaryKeyType), r.ReadElementString());
break;
case "PrimaryKeyName":
table.PrimaryKeyName =
r.ReadElementString();
break;
case "Columns":
ReadColumns(projectBuilder, table, r);
break;
case "Indexes":
ReadIndexes(projectBuilder, table, r);
break;
default:
r.ReadInnerXml();
break;
}
}
if (!isEmptyElement) {
r.ReadEndElement();
}
return table;
}
private static void ReadIndexes(DbProjectBuilder projectBuilder, DbTable table, XmlTextReader r) {
bool isEmptyElement = XmlUtil.ReadStartElement(r, "Indexes");
while (r.IsStartElement()) {
if (r.Name == "TableIndex") {
DbTableIndex tableIndex = DbTableIndex.Read(projectBuilder, table, r);
table.Indexes.Add(tableIndex);
} else {
r.ReadInnerXml();
}
}
if (!isEmptyElement) {
r.ReadEndElement();
}
}
private static void ReadColumns(DbProjectBuilder projectBuilder, DbTable table, XmlTextReader r) {
bool isEmptyElement = XmlUtil.ReadStartElement(r, "Columns");
while (r.IsStartElement()) {
if (r.Name == "Column") {
DbColumn column = DbColumn.Read(projectBuilder, r);
table.Columns.Add(column);
} else {
r.ReadInnerXml();
}
}
if (!isEmptyElement) {
r.ReadEndElement();
}
}
Wout
|
|
|
|
|
wout de zeeuw wrote: see e.g. typical code snippet below:
Ok, um after seeing your code I guess I should warn you that you appear to be reinventing the wheel only yours is shaped like a square.
|
|
|
|
|
led mike wrote: Ok, um after seeing your code I guess I should warn you that you appear to be reinventing the wheel only yours is shaped like a square.
Hehe, and chromed too! My main purpose is experimenting to get a feel for this XmlTextReader thing...
Wout
|
|
|
|
|
If its your custom xml format then you will have an xsd for it. Use xsd.exe to spit out class definitions tagged up for deserialization.
|
|
|
|
|
Hi Guys,
Is there any way to restrict the files browsable in the FileBrowserDialog to a specific directory or sub directory? I've got two directories i want to browse the files in.
Anything like that exist?
Regards
Tris
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Ive got an object that I inherit from DataTable and the overloaded constructor shown below
When I try to deserialize it i get the error
"The constructor to deserialize an object of type 'MyLibrary.CSVImport' was not found.
[Serializable]
public class CSVImport : DataTable
public CSVImport():base()
{
}
Project is target 2.0
I must have something missing that I need to do in order to deserialize the object. Below is the code that does the testing
DataTable dt;
FileStream fs = new FileStream(s3, FileMode.Open);
CSVImport csv = new CSVImport(fs,out err);
csv.SetFirstRowAsHeader();
// test serialization
fs = new FileStream(@"C:\test.bin", FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, dt);
fs.Close();
fs = null;
bf = null;
dt = null;
fs = new FileStream(@"C:\test.bin", FileMode.Open);
bf = new BinaryFormatter();
dt = (DataTable)bf.Deserialize(fs);// Boom! Does not like this..
fs.Close();
|
|
|
|
|
If you inherit from a class which has a non-public deserialization constructor, you will have to implement it. Like:
public class CSVImport : DataTable
public CSVImport():base()
{
}
public CSVImport(SerializationInfo info,
StreamingContext context):base(info, context)
{
}
|
|
|
|
|
Thank you...
So in this case the parent DataTable has a non-public deserialization constructor?
|
|
|
|
|
|
I have a problem with binding data using BindingSource, typed dataset and DataGridView. My problem is: BindingSource, therefore grid, is empty after binding data (bindingSource.Count is 0). I couldn't figure out what I'm doing wrong and I'd be very happy if anyone could help me with this.
My application structure is like this: I have two assemblies, one is Winforms UI and other is database class library.
UI
-DataGridView, datasource as BindingSource
-BindingSource, datasource = DBAssembly.typedDataset, datamember = DBAssembly.typedDataset.myTable
Database DLL
-Sql Server CE database
-Typed Dataset
-DB class for database operations
UI Code
OnLoad
this.db = new DB();
db.BindData();
DB Code
constructor
create typedDataSet object
create typedDataSetTableAdapters.MyTableTableAdapter object
create typedDataSetTableAdapters.TableAdapterManager object
BindData()
this.myTableTableAdapter.Fill(this.typedDataSet.MyTable)
I'd appreciate any help with this
|
|
|
|
|
Hi,
Does anyone know what I should install for having support to Microsoft Access database in Entity Framework in Visual Studio 2008 ?
Currently, I see only SQL Server and SQL Server Compact Edition as available database type when I want to add an "ADO.NET Entity Data Model".
Thanks,
Fred
|
|
|
|