 |

|
Hmm, now it works, even with using the same code as the one that didn´t work.I di d nothing more, than copying binaries from bin/Debug/ and running them on another computer. I can´t understand this behaviour.
|
|
|
|

|
I think that is properly called a heisenbug[^].
That is odd behaviour. Something to do with a 64/32 bit compilation on a 32/64 bit machine (I mean really unsure)! The only other things that spring to mind immediately is the framework version or that restarting your machine might be a good idea, in case VS has screwed up. Hope you get it stable.
|
|
|
|

|
Maybe it is stable now. But there is new problem. I have tried decrypting encrypted file, but it fails to decrypt, decrypted data absolutely do not match data which was encrypted. I am using this code:
Public Sub Save(ByVal carrier As DataCarrier, ByVal password As String, ByVal filename As String)
Try
Using sha As New SHA512Managed
Dim hash = sha.ComputeHash(Encoding.Default.GetBytes(password))
Dim key As Byte() = New Byte(31) {}
Dim iv As Byte() = New Byte(15) {}
Array.Copy(hash, 0, key, 0, 32)
Array.Copy(hash, 32, iv, 0, 16)
Using aes As New RijndaelManaged, filestr As New FileStream(filename, FileMode.Create, FileAccess.Write)
Using cryptostr As New CryptoStream(filestr, aes.CreateEncryptor(key, iv), CryptoStreamMode.Write)
ExportData(carrier).Save(cryptostr)
End Using
End Using
End Using
Catch ex As Exception
Logging.Instance.WriteException(ex, TraceEventType.Error)
MessageBox.Show(String.Format(My.Resources.UnhandledExceptionExString, ex.Message, ex.ToString), My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Public Function Load(ByVal password As String, ByVal filename As String) As XDocument
Dim sha As SHA512Managed
Dim aes As RijndaelManaged
Dim trans As ICryptoTransform
Dim cryptostr As CryptoStream
Dim filestr As FileStream
Try
sha = New SHA512Managed()
Dim hash = sha.ComputeHash(Encoding.Default.GetBytes(password))
aes = New RijndaelManaged()
Dim key As Byte() = New Byte(31) {}
Dim iv As Byte() = New Byte(15) {}
Array.Copy(hash, 0, key, 0, 32)
Array.Copy(hash, 32, iv, 0, 16)
trans = aes.CreateEncryptor(key, iv)
filestr = New FileStream(filename, FileMode.Open)
cryptostr = New CryptoStream(filestr, trans, CryptoStreamMode.Read)
Return XDocument.Load(cryptostr)
Catch ex As Exception
Logging.Instance.WriteException(ex, TraceEventType.Error)
MessageBox.Show(String.Format(My.Resources.UnhandledExceptionExString, ex.Message, ex.ToString), My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If cryptostr IsNot Nothing Then cryptostr.Dispose()
If filestr IsNot Nothing Then filestr.Dispose()
If trans IsNot Nothing Then trans.Dispose()
If aes IsNot Nothing Then aes.Dispose()
If sha IsNot Nothing Then sha.Dispose()
End Try
End Function
modified 17-Nov-12 11:23am.
|
|
|
|

|
Can you post the code for the Export.Save method so we can see how you are using the cryptostream?
|
|
|
|

|
Do you mean ExportData(carrier).Save(cryptostr) ? That is System.Xml.Linq.Save method.
|
|
|
|

|
I've never tried encrypting something exactly as you are trying, but I believe the problem is that you're not calling the write method of the crypto stream. Check out the information on the write method of the crypto stream for for information. Below is a function I use to encrypt a string. As you can see I call the write method of the crypto stream and pass in a byte array of the data I want to encrypt. Hopefully the code below helps you.
Public Shared Function Encrypt(value As String, key() As Byte, iv() As Byte) As string
Dim bytValue() As Byte Dim bytEncoded() As Byte Dim rijndael As New Rijndael Managed
Dim ms As New MemoryStream
bytValue = Encoding.ASCII.GetBytes(value.ToCharArray) Using CryptoStream As New CryptoStream(ms, rijnadel.CreateEncryptor(key, iv), CryptoStreamMode.Write)
CryptoStream.Write(bytValue, 0, bytValue.Length)
CryptoStream.FlushFinalBlock()
bytEncoded = ms.ToArray
ms.Close()
End Using
Return Convert.ToBase64String(bytEncoded)
End Function
|
|
|
|

|
Why do you think, I do not call Write ? I call System.Xml.Linq.XDocument.Save.
It looks, that it is really a Heisenbug.
|
|
|
|

|
Hi,
My VB6 application has been developed long back using Access as back end. Now I am planning to migrate data from Access to sQL server 2008 .
1)Previously vb6 application was retrieving date from Access file in dd/MM/yyyy format which is the system format without any format function.(Uses RecordSet object) . After migrating to sQL server 2008 date retrieved in yyyy-MM-dd format which I have to format each time to my required format.
So it's creating issues at many places like inserting records to server, date comparison with date controls of vb6 etc. So I may have to apply format() function at many places. Can we use any once only setup to retrieve date in required format , so the application changes will be minimal. (at SQL Server side or at my application). ie the RecordSet.Open will always provide date data in dd/MM/yyyy format without any explicit formatting.
2)I am not able to use seek function with RecordSet object
Thanks in Advance
Johnson
|
|
|
|

|
If you're worried about "formats" of DateTime values in the Access database, you've been storing datetime data as strings, not datetime values.
You shouldn't be worried about those "formats" at all since a true datetime value is has no format in the database.
The only time you should be worried about the format of a datetime is when such values are presented in the UI or the user has to otherwise interact with them.
|
|
|
|

|
Hi all,
We have a financial system that writes a text file out that could be several 100 or even 1000 lines long. It writes the file into a txt file and can't be modified to be another file extension and then be renamed after the data has been loaded.
I have a service already written that notices that a txt file has shown up in this directory and fires off the application that needs to read this data.
I don't want to have the application which reads the data begin the process until after the financial system has written all data to the file.
I've searched all kinds of VB help sites and here is the code most refer to in various ways:
Public Function IsFileLocked(filename As String) As Boolean
Dim Locked As Boolean = False
Try
Dim fs As FileStream = File.Open(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)
fs.Close()
Catch ex As IOException
Locked = True
End Try
Return Locked
End Function
I have my file open in Notepad to test and have the file being accessed, but it falls straight through the code and does not hit the catch. I even opened the file in Excel and had the same result.
Any ideas?
Lost in the vast sea of .NET
|
|
|
|

|
This method will only work if the file being written by the financial system opens the file for exclusive write, meaning no shared readers or writers. Apparently, the financial system is allowing other processes to write to the file and the same time it's writing it.
The only other way I know of to determine if the file is completely written is to enumerate the system handle table, determine if the file is open currently open and:
1) Keep checking this handle every few seconds and wait for it to disappear. This should signal the end of the file write.
2) Depending on how the file is being written, you may find that the file is being opened, written, then closed, repeatedly. You may have to keep checking and waiting for an arbitrary amount of time to see if the file is again opened before considering the file complete.
|
|
|
|

|
I goofed... I was using notepad over and over to try and replicate the file being accessed. I found that notepad doesn't cause the file to show as open. When I tried Excel, right before doing my post, I goofed and opened my output file instead of my input file.
I still need to do some testing when the financial system is writing a file to make sure it works the same way or if I need to take your suggestion and look at the file handle.
Thanks!
Lost in the vast sea of .NET
|
|
|
|

|
I just did testing with the financial system and the code worked without having to go to the file handles.
Thanks again for your reply!
Lost in the vast sea of .NET
|
|
|
|

|
Hi all,
Please ignore my post. I was using notepad over and over to try and replicate the file being accessed. I found that notepad doesn't cause the file to show as open. When I tried Excel, right before doing my post, I goofed and opened my output file instead of my input file.
Code works... Thanks to anyone that started researching this issue...
Lost in the vast sea of .NET
|
|
|
|

|
That's because Notepad does not keep the file open as you are editing it. It opens the file, reads the contents, closes the file, then shows you the contents in the window.
Same thing with Excel and reading text files. Excel WILL however, keep a workbook file open for the life of the working session.
modified 14-Nov-12 7:53am.
|
|
|
|

|
KreativeKai wrote: Any ideas?
A file being reported as "in use" may even vary on the file-system being used; there is no real way of testing, but trying and recovering if things go wrong.
For reading, that means simply putting up a message that the file is locked by another application which needs to be closed first. For writing, it means (in the ideal case) that one offers a SaveFileDialog to save the file under a new name.
"Testing and opening" is not an option, since it creates a race-condition; the file could be opened between the moment you checked it's status and the moment you're going to lock it.
|
|
|
|

|
I agree with everything you said in your reply because each situation you're trying to code for can vary.
In the situation I have however I won't need to worry about the file being re-locked. Basically the financial system writes a report file in text format and the code I posted in the original thread works to check if the file is currently open. Once the financial system has completed the output it will never be opened again except by my application that is picking it up and converting the report to PDF and then deleting the original text file.
My application is executed by a service I wrote that checks if a text file shows up in a certain directory. The service checks every minute. If it sees a text file it executes. My app then goes through the directory and starts reading files for conversion. I don't want to start this process if the financial system has not completed the output, so I'll basically skip if opened and catch it the next time the app executes (1 minute later).
My biggest mistake was assuming notepad would hold the file open for testing....
Lost in the vast sea of .NET
|
|
|
|

|
I had a similar problem and solved it using
Public Function FileInUse(ByVal sFile As String) As Boolean
If System.IO.File.Exists(sFile) Then
Try
Dim F As Short = FreeFile()
FileOpen(F, sFile, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite)
FileClose(F)
Catch
Return True
End Try
End If
End Function
usage
Do While FileInUse(sSourcePath & "\" & sFileName & "." & sExtension)
System.Threading.Thread.Sleep(1000)
sTimeOut += 1
If sTimeOut = 15 Then
WriteLogLog("File " & sFile & " in use.")
Exit Sub
End If
Loop
Im testing each second if the file can be opened, if it can't then it is because it is in use. When the loop ends I know my file is no longer in use.
best regards
modified 19-Nov-12 10:20am.
|
|
|
|
|

|
You're not going to get any code to do this as VBScritp can't do the things required to pull this off.
But, you can always use this[^].
|
|
|
|

|
I'd rather opt for a Group Policy which could be distributed in your domain (assuming that you want your setting to be used on all computers of your company).
|
|
|
|

|
Is there a way to determine the SQL Server configuration from vb.net?
I would like to be able to determine what the memory allocation is weather its an express or full version and what version it is.
Any information on this would be great,
|
|
|
|
|

|
Thanks for the reply, I will need to read about that stuff before i can attempt it but its a good starting point thank you
|
|
|
|

|
Log in as 'sa' and execute this command:
SELECT
(Physical_memory_in_bytes/1024.0)/1024.0 AS Physical_memory_in_Mb
FROM
sys.dm_os_sys_info
No special privileges for this command:
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
Please remember to vote if you find this helpful.
|
|
|
|

|
Thanks for your help, this has pointed me in the right direction once I develop the complete solution i will post.
|
|
|
|

|
How to write source code for Add, Delete, Update, Save, view in crystal report in VB.Net 2008
|
|
|
|

|
By coming up with a GOOD set of requirements (hint: FAR more than what you have in your post), designing a solution that fits those requirements and writing code to implement the solution.
|
|
|
|

|
I am trying to monitor network bandwidth usage on a per user basis and am new to vb.net. I have a list of users with their IP addresses already if that helps.
Basically trying to mimic the remote desktop service manager.
I am lost when it comes to this so any information about how to accomplish this would be greatly appreciated.
Is this even possible?
modified 13-Nov-12 11:54am.
|
|
|
|

|
DinoRondelly wrote: Is this even possible?
Hard to answer; when I use "Fiddler" to monitor the traffic, I can see what's going on in detail. There's probably examples on using the same "winpcap" from .NET here on CodeProject.
Still, I think "time" is more frequently (and easier) used to limit the users' access.
|
|
|
|

|
Hello All -
I have seen on this site Article 42852 / Reading-Barcodes-from-an-Image-III, however, this appears to only read the first page of a multipage tiff. I need to find something that can read all the pages (could be a 500 page tiff) for barcodes. Also, does anyone know of a sample project on this site (or any other site) with source code to do this and scan a folder of tiff images instead one at a time.
Thanks in advanced.
|
|
|
|

|
daveofgv wrote: I have seen on this site Article 42852 / Reading-Barcodes-from-an-Image-III, however, this appears to only read the first page of a multipage tiff. I need to find something that can read all the pages (could be a 500 page tiff) for barcodes
If you need to find it, good luck.
To create it;
- Isolate the trick from the article to a minimal console-app
- Try fetch total number of pages on a given TIFF file
- Try fetch specific page of a given TIFF file
- do trick N times, while showing progress bar
daveofgv wrote: Also, does anyone know of a sample project on this site (or any other site) with source code to do this and scan a folder of tiff images instead one at a time.
It'll be quite expensive to do them "all at once", it there's over a hundred. Doing above trick for each file in a directory, is explained here[^]
|
|
|
|

|
I am trying to get all logged on users and their IPAddresses and display them in a data grid veiw in a windows form using VB.net I have tried the below code and it appears to get the users on a windows 7 machine but not on servers. Any information on this would be greatly appreciated.
Public Shared Function GetUsers() As List(Of Users)
Dim UserList As New List(Of Users)
Try
Using searcher = New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_LogonSession WHERE LogOnType = 2")
For Each queryObj As ManagementObject In searcher.Get()
Dim qry As String = "Associators of " _
& "{Win32_LogonSession.LogonId=" & queryObj.GetPropertyValue("LogonId") & "} " _
& "Where AssocClass=Win32_LoggedOnUser Role=Dependent"
Using iSearch = New ManagementObjectSearcher(qry)
For Each res As ManagementObject In iSearch.Get()
Dim ret As New Users(res.GetPropertyValue("Name"), _
"", "")
UserList.Add(ret)
Next
End Using
Next
End Using
Return UserList
Catch err As ManagementException
MessageBox.Show(err.Message)
Return UserList
End Try
End Function
|
|
|
|

|
Unless the users are logged in on Remote Desktop (or Terminal Services) to the server, this code won't show you anything on the server.
LogOnType = 2 is Interactive logons only. Remove the WHERE clause and see what you get.
|
|
|
|

|
Thanks so much for the reply
What I am trying to do is determine all users logged on to a server and then get their IPAdresses and any other information I can get on them.
I did what you suggested but for some reason this also included Local Services,Network Services and others in the list of users. Also every user in the list was triplicated.
This is the first project I have done in VB.net so forgive me if i come off as a novice.
Any information or code samples would be greatly appreciated.
|
|
|
|

|
and what were their LogOnTypes??
I have no idea what kind of user you're looking for! "Logged on users" can mean anything depending on HOW they are logged on. Are they remote desktop sessions? HTTP Sessions? Mapped drives?? Each of these is a different logon type and needs to be handled differently.
|
|
|
|

|
Thanks for the reply,
I am trying to get all users that are on the server that have remoted in and their IPAddresses. Similar to what is showing in the task manager under the users tab and in the terminal service manager.
|
|
|
|

|
That's obtained from the WMI provider for Remote Desktop. You're using the LogOnSession class, which is a bit too high level for what you're looking for. You can find the docs on these classes here[^].
|
|
|
|

|
Thanks for the reply,
I will look into what you have suggested, do you by any chance have any code samples of how this works? If not no worries,
Thanks!!
|
|
|
|

|
Nope. I've never had to do what you're doing.
|
|
|
|

|
http://www.codeproject.com/Articles/111430/Grabbing-Information-of-a-Terminal-Services-Sessio
Works perfectly
modified 12-Nov-12 14:46pm.
|
|
|
|

|
Great. Glad you got something that works for you.
|
|
|
|

|
hi experts!
can you help me with this problem?
i am making an id monitoring system.
here is the error.
"The type initializer for 'again.Module1' threw an exception."
thank you very much.
|
|
|
|

|
Not enough information.
We need to see the stack trace and the code for "again.Module1", which I think is a mistake in your code anyway. But, we'd need to see the code where this error pops up.
|
|
|
|

|
I'm doing a homework which i need to create a pizza order form. I've created the form along with the codes but i'm getting errors when debugging it. Like the one below:
C:\Users\Vasquez\Documents\Visual Studio 2005\Projects\Pizza Order\Pizza Order\Form1.vb(113) : error BC30451: Name 'txtSurname' is not declared.
This is the code to it:
If ds.Tables("CustInfo").Rows.Count = 0 Then
MsgBox("Number not found in database.")
cmdSave.Enabled = True
txtSurname.Focus()
Exit Sub
I wish i could put more but i'm limited to what i can post cause it long and i have other errors as well!
|
|
|
|

|
You (presumably) are trying to set the focus to some control on your form, but you do not appear to have a control named txtSurname. Check the spelling of your controls.
One of these days I'm going to think of a really clever signature.
|
|
|
|

|
Hello !
i have an application in vb.net 2010 , and i'm using System.Net.Mail to send emails.
is there any way to test smtp connection , before begin to send emails .
Thank you !
|
|
|
|

|
The only way to really test it is to try and send an email. Kind of defeats the purpose now, doesn't it?
|
|
|
|

|
thank you , but i need to check if smtp server is ready , and if not i need to display a warning to user and cancel the sending process. If is ready i can begin sending emails.
i have found this code , but doesn't work when i test with a invalid smtp server name:
public bool ValidSMTP(string hostName)
{
bool valid = false;
try
{
TcpClient smtpTest = new TcpClient();
smtpTest.Connect(hostName, 25);
if (smtpTest.Connected)
{
NetworkStream ns = smtpTest.GetStream();
StreamReader sr = new StreamReader(ns);
if (sr.ReadLine().Contains("220"))
{
valid = true;
}
smtpTest.Close();
}
}
catch
{
throw;
}
return valid;
}
|
|
|
|

|
If you give the Connect method an invalid hostname and port that cannot be connected, it'll throw a SocketException with the error code in it.
if the hostname is a real server but nothing is listening on 25, it'll throw a SocketException.
If the hostname is real and 25 is blocked by a firewall, you'll get a SocketException.
Sooo... what's with the lonely little "throw" statement? Remove that and your code will work. That is, assuming that the SMTP server is listening on port 25...
The problem with this code is that you're only testing the server connection, not the ability to send email. Just because the server responds to a connection request does not mean that the credentials given for the SMTP account to send an email will work.
That's why I said the best way to check is to actually send an email.
|
|
|
|
 |