Sending email issue VB.net - vb.net

I have command line app that send an email and the issue is when i open the console and type all parameters (SendEmail.exe recipient subject message Sender Senderpass) email goes through OK, but when I do that from other application
Dim p As New ProcessStartInfo
Dim Tsubject As String = "TEST "
p.FileName = "SendEmail.exe"
p.Arguments = EmailReceivers & " " & subject & " " & " Message " & EmailSender & " " & SenderPass
p.WindowStyle = ProcessWindowStyle.Normal
Process.Start(p)
Then I get no error from SendEmail.exe it says Email Successfully Sent but I don't receive anything.

Maybe the character encoding messes around. Especially the "#" character might get messed up. Writing a batch application echo your argument will show you, if you can exclude this.
Do u have enclosed the subject in quotes? Otherwise a space might mess up the arguments.

Because you attach an executable file(.exe) in your email, so the target email server may filter your mail as mailware or sth dangerous and can harm the receiver.

Related

When setting user permissions to open up a particular form for a particular user I am getting a Runtime error from the DLookup statement

I am trying to restrict the availability of a form to be opened by a user. the following code picks up on the correct user access type and the correct form name, however i am getting the runtime error 2471. I would appreciate some help here as i cannot see what is wrong?
The error statement in this case is: Run-Time error '2471': The expression you entered as a query parameter produced this error: 'Stock'. When i go to debug it brings me to the DLookup and i cannot see what is wrong.
Watch expression:Watch : : "Employeeaccesstype =" & cable & " " & "AND FormName=" & thisform : "Employeeaccesstype =0 AND FormName=Stock" : String : Form_Stock.Form_Load
Private Sub Form_Load()
Dim cable As String
cable = TempVars("AccessType")
Dim thisform As String
thisform = Me.Form.Name
If DLookup("Hasaccess", "tblemployeeaccess", "Employeeaccesstype =" & cable & " " & "AND FormName=" & thisform) = False Then
DoCmd.Close
MsgBox "You Do Not Have Access"
End If
End Sub
All help will be most appreciated as i am on a deadline to finish this
If your fields Employeeaccesstype and FormName are text, then the values in the Dlookup need to be wrapped in single quotes. Additionally, you should cater for the possibility that the record doesn't exist in the table (returning a Null value from the DLookup):
If Nz(DLookup("Hasaccess", "tblemployeeaccess", "Employeeaccesstype ='" & cable & "' AND FormName='" & thisform & "'"),False) = False Then
You should also consider not actually allowing them to open the form in the first place.
Regards,
I changed tack here and went for a different approach. I created a new table to hold user login details and a query to join details on tables and referenced that on the Dlookup rather than trying to reference the login form through a variable. Witth those changes made i changed the DLookup to
If DLookup("Hasaccess", "AccessQuery", "HasAccess =false and Formname = 'Part' ") =
False Then
DoCmd.Close
MsgBox "You Do Not Have Access"
End If
This is now working correctly. Many thanks o Applecore for the assistance with this problem

Open a file in a new instance of program

All;
I have a bit of code I've written that opens a design blueprint when I scan a bar code. It works well enough, but I'd like to open a new instance of the design software (Solidworks) and have the print display in the new instance. Right now, no matter how many Solidworks instances I have open, the print will only open in the first instance started.
The line commented out below is the line that works, just not in the right instance. The line below that is what I'd expect to work, but it returns a 'file not found' even though the path to solidworks and the print path are both correct.
Any explanation as to why this isn't working would be much appreciated as I'm obviously very new at this...and have no idea what I'm doing.
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim barcode As String = tb_barcode.Text
Dim filename As String = tb_barcode.Text
'Add File Extension to end of path
Dim ext As String = ".SLDDRW"
'Split job number from detail number in barcode textbox
barcode = Split(tb_barcode.Text, ".")(0)
filename = Split(tb_barcode.Text, ".")(1)
'- This works, just in primary instance
'System.Diagnostics.Process.Start("G:\Fixtures\" & barcode & "\Details\" & barcode & " DET " & filename & ext)
'- This does not work
System.Diagnostics.Process.Start("'C:\Program files\Solidworks Corp\Solidwork\SLDWORKS.exe' 'G:\Fixtures\" & barcode & "\Details\" & barcode & " DET " & filename & ext + "'")
Catch
MessageBox.Show("File Not Found")
End Try
End Sub
Sorry for naive approach but shouldn't there be a comma in Process.Start between 2 arguments?
Start(String, String)
Starts a process resource by specifying the name of an application and a set of command-line arguments, and associates the resource with a new Process component. docs
Why don't you use the Application.ExecutablePath.That returns the Application's path with its full name. Then your code should be
System.Diagnostics.Process.Start(Application.Executablepath, "G:\Fixtures\" & barcode & "\Details\" & barcode & " DET " & filename & ext + "'")
Also make sure that the second string argument is a valid path.

How to execute Batch File while passing parameters from Excel

I am trying run a batch file placed at a particular path. The file requires user inputs for which I want the parameters to be passed from Excel cells. This execution of the batch file within Excel should happen by usage of click command button.
I am new to VBA. I tried the following code, but on clicking the button nothing is happening.
Private Sub CommandButton2_Click()
sid = Excel.Worksheets("Sheet1").Range("I8").Value
user = Excel.Worksheets("Sheet1").Range("I9").Value
Password = Excel.Worksheets("Sheet1").Range("I10").Value
msg = "hi"
Shell ("CMD.EXE /c C:\Users\shashank.b03\Desktop\test_CMD.bat" & sid &" "& user &" "& password &" ")
End Sub
Here is an example which I have tested and should work fine for you. It just calls the shell command and passes it a command string.
You can change the path where your batch file is in the string & if you don't want to show the shell window when you're running this use vbHide instead of vbNormalFocus.
You'll just have to change this a bit to put the cell values into the sid, user and password variables.
Hope this helps.
Dim sid As String
Dim user As String
Dim password As String
CommandString = "c:\test.bat" + " " + sid + " " + user + " " + password
Call Shell("cmd.exe /c" & CommandString, vbNormalFocus)
Here is a more basic example of using parameters and a batch file from shell.
Save the following as test.bat
set arg1=%1
echo HELLO %1!
pause
Put this code inside a button or some other component in excel;
Private Sub CommandButton1_Click()
Dim sid As String
sid = "Shashank"
CommandString = "c:\test.bat" + " " + sid
Call Shell("cmd.exe /c" & CommandString, vbNormalFocus)
End Sub
Make sure that the path where the batch file is saved is the same as the one in commandstring.
When this is run, you'll see the string held in the variable sid is passed to the batch file and used. You should be able to get it working from here.
Hope this helps

Concatenating a complex string in VB. NET

I am using START-PROCESS to call MSTEST with multiple arguments that define the container and test settings, however I think it's choking on the way I'm concatenating this. Should I use some other method of constructing this string before putting it into START-PROCESS?
Dim rwSettings As String = "\\PerfvsCtlr2\LoadtestSettings\PerfVSCtlr2forRemote.testsettings"
Dim rwContainer As String = "\\PerfvsCtlr2\LoadTest\LoadTestDefs\Heifer_Interactive_Peak_Workload.loadtest"
Dim rwResults As String = Workload.txtRwResults.Text
System.Diagnostics.Process.Start(Environment.GetEnvironmentVariable("VS110COMNTOOLS") & "..\Ide\MSTEST.EXE", "/Testsettings:""" & rwSettings & "" & " /Testcontainer:""" & rwContainer & "" & " /Resultsfile:""" & rwResults & "")
The problem is unknown currently, because process.start opens and closes the window far too quickly for me to catch any sort of error message. So my question is two-fold:
Does the above concatenation look correct? Is there a way I can get more information on either the final execution string Process.Start is putting together or the error message it's returning?
You can use Path.Combine to build paths and String.Format to build the arguments for Process.Start:
Dim rwSettings As String = "\\PerfvsCtlr2\LoadtestSettings\PerfVSCtlr2forRemote.testsettings"
Dim rwContainer As String = "\\PerfvsCtlr2\LoadTest\LoadTestDefs\Heifer_Interactive_Peak_Workload.loadtest"
Dim rwResults As String = "Workload.txtRwResults.Text"
Dim fileName = System.IO.Path.Combine(Environment.GetEnvironmentVariable("VS110COMNTOOLS"), "Ide\MSTEST.EXE")
Dim args = String.Format("/Testsettings:{0} /Testcontainer:{1} /Resultsfile:{2}", rwSettings, rwContainer, rwResults)
System.Diagnostics.Process.Start(fileName, args)
However, i must admit thar i'm not sure if this yields the desired result. It might give you an idea anyway.
I suspect that your problem is that you are not closing your quotation marks, for instance:
" /Testcontainer:""" & rwContainer & ""
Should be:
" /Testcontainer:""" & rwContainer & """"
Notice that the double-quotation mark at the end needs to be a quadruple quotation mark. Simply saying "" means an empty string.
Should you use something else? Probably. It would be more readable and efficient if you used StringBuilder or String.Format, but even so, you'll still have to fix the closing quotes issue.

Use the actual value of String as a Formatted Value for TextBlock.Text

So basically I have this:
A WPF window with 1 Button (btn_Convert) and 2 TextBoxes (txtBox_StringValue and txtBox_Result).
In txtBox_StringValue I then paste in a formatted string value:
"This is a Header" & vbCrLf & "======================" & _
vbCrLf & "INFO" & vbCrLf & "======================"
Then when I click btn_Convert I would like the following to happen.
Code:
Dim tempStringValue = txtBox_StringValue.Text
txtBox_Results.Text = tempStringValue
However (obviously), when I do the above the Results TextBox just displays the string again:
"This is a Header" & vbCrLf & "======================" & _
vbCrLf & "INFO" & vbCrLf & "======================"
Instead of:
This is a Header
======================
INFO
So how do I get the value of the string and then strip the containing double-quotes so that the value when assigned acts like it was a variable value set in code, not just passing a string.
From the research I have done I am guessing that I need to use Reflection, however I am not familiar with the Reflection concept and don't know how to approach it.
Any help would be greatly appreciated!
Reflection won't help you in this case. It sounds like what you're talking about is dynamically interpreting some VB.NET source code and output the result of executing that code to another text box. In that case you need to use the Code DOM classes to dynamically build an assembly in memory and execute it.