VB.NET Screenshot Application Window and Send - vb.net

I have built an application that obtains details from a web service and displays them in a GUI for the agent to see.
I've had instances of problems occuring, sometimes an exception due to a change in how the data is received due to the provider and unfortunately no user lets me know this occurs, they just click through and pay no attention to the error.
I've built a custom form to capture the error and then email it to me with some details like username etc. etc.
I would ideally LIKE to capture the screen of the application as well, much like an ALT+PRINTSCRN so I can see what the application looks like at the time of error as well.
How possible is this?

Assuming WinForm, I've done this before:
Public Sub SaveAsImage(frm As Form)
'Dim fileName As String = "sth.png"
'define fileName
Dim format As ImageFormat = ImageFormat.Png
Dim image = New Bitmap(frm.Width, frm.Height)
Using g As Graphics = Graphics.FromImage(image)
g.CopyFromScreen(frm.Location, New Point(0, 0), frm.Size)
End Using
image.Save(fileName, format)
End Sub
When being called, it will capture the current screen in the area defined by frm and save to a file.

Related

Auto login windows security window

I try to fill up automatically the name and the password for a windows security window, basically the page is opening after a couple of seconds with the window but the fields for user and password are empty. This is the code I have so far, any help is appreciate. Thank you.
This is where I am now:
Dim oProcess As New Process()
Dim psi As New ProcessStartInfo
psi.FileName = "arp"
psi.Arguments = "-a"
psi.UseShellExecute = False
psi.RedirectStandardOutput = True
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.CreateNoWindow = True
Dim p As Process = Process.Start(psi)
Dim s As String = p.StandardOutput.ReadToEnd()
s = s.Split(" ".ToCharArray)(1)
WebBrowser1.Navigate("http://user:pass#" + (s) + ":34655/")
It works but I get from cmd only the first ip(192.2.2.2), if I don't use the arp command I don't see the ip of the device.
Basically I need to get the ip from this cmd output from third row:
"interface: 192.2.2.2 ----0xb//////
internet address- physical address---type///////
134.45.455.455.4(this ip) mac address dynamic//////
etc etc"/////
Thank you
You need to be more specific.
If this site you are connecting to uses Basic authentication, you are presented with a System InputBox with standard fields and a button control.
If it uses WebForm LogIn authentication, you are presented with a Web Form
with semi-standard Form Elements to fill in.
In the former case, it is quite simple to perform an authentication throu WebRequest/HttpWebResponse or, if you really need to use a WebBrowser control,
to setup its .Navigate property to achieve the same result.
If your case is the latter, since you are using a WebBrowser control to navigate to an URI, you don't really need any PInvoke at all.
Mind that WebBrowser.Document contains the HtmlDocument that describes the HTML page.
It also lets you access all the object that the page defines.
So, if you know in advance which Site you are connecting to (ie, you need to perform this operation
for this one Site only), you can use the .DocumentCompleted Event of your WebBrowser and set
your parameters directly from there:
Consider:
["UserName"], ["Password"], ["LoginButton"]
as the IDs of the Html Elements that represent an <input> Textbox, an <input> Password,
and a <input> Button that forwards the form parameters in a .Click Event .
So, read from the Html Page the IDs of the elements in the form and just insert your values:
In WebBrowser1_DocumentCompleted:
WebBrowser1.Document.All(["UserName"]).SetAttribute("Value", "UserID")
WebBrowser1.Document.GetElementById(["Password"]).SetAttribute("Value", "Password")
WebBrowser1.Document.All(["LoginButton"]).InvokeMember("Click")
I'm using .Document.All and .Document.GetElementById to show that there are two different
methods to accomplish the same task.
If you don't know in advance what the content of the Html Page is, you need to perform a simple parsing of the page (using the HtmlDocument Object), retrieve the elements of the form and then repeat the
previous task.
As I said, you need to be more specific.
If you have questions, comment and I will edit my answer.

Error with sampleapp supplied with windowsSDK evernote

' Download the thumbnail for a note; then display it on this app's form.
Dim thumbnail As Byte() = ENSession.SharedSession.DownloadThumbnailForNote(myResultsList(0).NoteRef, 120)
Try
Dim ms As New MemoryStream(thumbnail, 0, thumbnail.Length)
ms.Position = 0
Dim image1 As System.Drawing.Image = System.Drawing.Image.FromStream(ms, False, False)
PictureBoxThumbnail.Image = image1
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
' Display a note's content as HTML in a WebBrowser control.
Dim myContent = myDownloadedNote.HtmlContent
WebBrowser1.DocumentText = myContent
End If
with these 2 blocks of code from the included "Sampleapp"
i am getting the following errors....
Error 1 'PictureBoxThumbnail' is not declared. It may be
inaccessible due to its protection level.
H:\Michael-Documents\Visual Studio
2013\Projects\WindowsApplication1\WindowsApplication1\Form1.vb 84
17 WindowsApplication1
Error 2 'WebBrowser1' is not declared. It may be inaccessible
due to its protection level. H:\Michael-Documents\Visual Studio
2013\Projects\WindowsApplication1\WindowsApplication1\Form1.vb 91
13 WindowsApplication1
could anyone give me a helping hand, as to what is wrong. Sometimes the Head does not want to think. :-)
This sample app from the Evernote Windows SDK consists of a form with two controls on it named PictureBoxThumbnail and WebBrowser1. I checked the relevant code on Github and confirmed that they are there in the VB.NET SDK sample.
It sounds like somehow in the copy of the app you have in your Visual Studio, the names of these controls have been altered, or the controls may not be on the form at all.
Double-click on the form ("Form1") in the VS Solution Explorer window so as to open it in the VS Designer. There should be one PictureBox control on the left-hand side, named PictureBoxThumbnail, and one larger WebBrowser control on the right-hand side named WebBrowser1. If you don't have either or both of these controls on your form, add them; or if they are not named PictureBoxThumbnail and WebBrowser1, respectively, then rename them to those names. Then the app should run properly.

Access to path is denied when trying to import from the client's desktop with SSIS

I'm creating a html page that will import an excel file in to a tracking system. On a button click event excel file is located / ssis package is fired / data imported then closed out. Thats the idea work flow. Problem is the excel file access is being denied before the package even executes
Here is the exact error :
I've tried :
excel file properties have been shared to everyone
identity impersonate set to true
hard coding the path
here is the VB code
Protected Sub bntExecute_Click(sender As Object, e As EventArgs) Handles btnExecute.Click
Dim app As Application = New Application()
Dim package As Package = Nothing
'Dim fileName As String = "C:\Users\Desktop\T. Bryant III\PTSID_Update_Template"'
Try
Dim fileName As String = Server.MapPath(System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName.ToString()))
FileUpload1.PostedFile.SaveAs(fileName)
package = app.LoadPackage("#C:\Users\Desktop\T.Bryant III\KitImport", Nothing)
'excel connection from package'
package.Connections("SourceConnectionExcel").ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0data source =" + fileName + "Extended Properties = Excel 8.0"
'Execute the pakage'
Dim results As Microsoft.SqlServer.Dts.Runtime.DTSExecResult = package.Execute()
Catch ex As Exception
Throw ex
Finally
package.Dispose()
package = Nothing
End Try
End Sub
Thanks in advance or if there is an easier way to do this please let me know. The package when executing it in ssis works fine with its own connection manager etc.
A few things to try. If they don't work for you as permanent solutions, they should at least confirm that your code is working and you are dealing with a persmissions issue (which appears to be the case).
Move your file to the public folder (C:\Users\Public).
Run your application (or web browser) as an administrator (if applicable to your version of Windows).
If you are using a web browser, try using a different one.
If nothing else works, try pasting your code into a Windows Form Application.
If you still get the same error after trying all of this, it's time to take another look at your code. Remove the Try/Catch block to determine precisely which line is throwing the error. If you've tried hard coding, I'm guessing it's the SaveAs method. I'm not sure what class FileUpload1 is, but some SaveAs methods won't overwrite existing files unless you explicitly tell them to. Check the appropriate documentation and see if you don't need to pass a True value somewhere along with filename.
Update us with the results. At the very least, this should narrow down your problem and allow for a better diagnosis of it.

Download Report and attach to email

I would like to ask if anyone knows the thing that i want to do:
I have a report in microsoft report server that's waiting for a parameter (person_id) to make the fulfill.
I need to send an email with the report of each person_id. I need to run a function that runs my report called per_permissions.rdl download it and attached the file to send it by email. Example in vb.net code
strSql = "SELECT per_id,per_email FROM person"
dt_person = getDataTable(strSql)
For each dr_person As DataRow in dt_persona.Rows
attached_file = mysticFunction(dr_person("per_id"))
...
Next
Public Shared Sub DownloadFile(ByVal _URL As String, ByVal _SaveAs As String)
Try
Dim _WebClient As New System.Net.WebClient()
_WebClient.DownloadFile(_URL, _SaveAs)
Catch _Exception As Exception
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString())
End Try
End Sub
Yes, it is fairly simple. Using the ReportExecutionService.Render method you can render the report however you want. We've used this to run reports and attach them to emails automatically.
The MSDN site has some code to get you started.
To add a reference to the report execution web service, right-click References, select Add Service Reference... and add a reference to the web service that will look something like:
http://MyReportServer/ReportServer/ReportExecution2005.asmx
You will also need the report service web service, which is:
http://MyReportServer/ReportServer/ReportService2005.asmx

is there a way to query IEmployeePayrollInfo with QuickBooks SDK?

I am starting to work with the QuickBooks SDK, and so far I am able to query Employees no problem, like so:
_sessionManager.OpenConnection("", "<software>")
_sessionManager.BeginSession("", ENOpenMode.omDontCare)
Dim requestSet As IMsgSetRequest = GetLatestMsgSetRequest(_sessionManager)
' Initialize the message set request object
requestSet.Attributes.OnError = ENRqOnError.roeStop
Dim empQuery As IEmployeeQuery = requestSet.AppendEmployeeQueryRq()
' Do the request and get the response message set object
Dim responseSet As IMsgSetResponse = _sessionManager.DoRequests(requestSet)
Dim response As IResponse = responseSet.ResponseList.GetAt(0)
Dim empRetList As IEmployeeRetList = response.Detail
....
_sessionManager.EndSession()
_sessionManager.CloseConnection()
Which will give me a list of employees which I can iterate through. This works well for the basic employee data, such as name, date of birth, etc. but there is a EmployeePayrollInfo property that does not seem to be returned with the IEmployeeQuery.
I see that there is an interface IEmployeePayrollInfo but I have not as yet been able to figure out if there is a way to query it. I see that there are report related payroll info queries, but I am trying to query the EmployeePayrollInfo directly, to retrieve the vacation information. Is this something that can be done with QBFC?
EDIT
I was able to get this working, see accepted answer below.
Open Quickbooks.
Go to the Edit menu and click Preferences.
In the Preferences window, click Integrated Applications in the list on the left.
Click the Company Preferences tab.
Select the application with which you are connecting to QuickBooks.
Click Properties.
Check "Allow this application to access Social Security Numbers, customer credit card information, and other personal data"
The employee data should now include EmployeePayrollInfo. Please comment if this does not work.
For anyone searching for the same functionality, the only information I was able to find seems to indicate that Intuit has specifically excluded this functionality from the QuickBooks SDK for security reasons. What we ended up doing to solve our problem is create a custom report in QuickBooks that included all of the information that we needed, exported it as a CSV file, and then import it accordingly in our software. Same end result, but a couple more steps than we were originally hoping for. Hopefully Intuit will change their mind about excluding this from the SDK.
UPDATE
I have finally been able to query the EmployeePayrollInfo, what was needed was adding "EmployeePayrollInfo" to the query itself like so:
empQuery.IncludeRetElementList.Add("EmployeePayrollInfo")
So now the code looks like this:
Dim sessionManager As New QBSessionManager
sessionManager.OpenConnection2("", "<software>", ENConnectionType.ctLocalQBD)
sessionManager.BeginSession("", ENOpenMode.omDontCare)
Dim requestSet As IMsgSetRequest = sessionManager.CreateMsgSetRequest("US", 12, 0)
requestSet.Attributes.OnError = ENRqOnError.roeStop
Dim empQuery As IEmployeeQuery = requestSet.AppendEmployeeQueryRq()
empQuery.IncludeRetElementList.Add("EmployeePayrollInfo") ' this line did the trick!
Dim responseSet As IMsgSetResponse = sessionManager.DoRequests(requestSet)
Dim response As IResponse = responseSet.ResponseList.GetAt(0)
Dim empRetList As IEmployeeRetList = response.Detail
If empRetList.Count > 0 Then
For i As Integer = 0 To empRetList.Count - 1
Dim emp As IEmployeeRet = empRetList.GetAt(i)
If emp IsNot Nothing Then
' do something with the queried data
End If
Next
End If
sessionManager.EndSession()
sessionManager.CloseConnection()