A method in which I test the internet connection is not working when I execute the program using PsExec.
It shows this message:
"The remote server returned an error: (403) Forbidden"**
I need to execute the application remotely, that's why I use PsExec, but when I open the program without using PsExec the method runs ok.
The command I use to execute the program with PsExec:
"D:\PsExec.exe -s -i \\MK18455 D:\RemedyHealthCheck.exe "
The method:
Public Shared Function CheckForInternetConnection(link As String) As String
Try
Dim proxy As New WebProxy("ibproxy03.intranet.ibermatica:8080", True)
proxy.UseDefaultCredentials = True
Dim request As HttpWebRequest = WebRequest.Create(link)
request.Credentials = CredentialCache.DefaultCredentials
request.Proxy = proxy
Dim response As HttpWebResponse = request.GetResponse()
If response.StatusCode = HttpStatusCode.OK Then
Return "si"
Else
Return "no"
End If
Catch e As Exception
MsgBox(e.Message)
Return "no"
End Try
End Function
You are running psexec with the wrong user. when you set the -s flag you are actually running as the SYSTEM account, but your web server/proxy requires authentication. you should either allow that computer to bypass the authentication or remove the -s flag, assuming that the user running the psexec is allowed to access that webserver/proxy. another option is to manually set the -u flag to a user that is allowed. (needs a password if you are not running as that user)
Related
I am creating an application that will allow a user to send Invoices from a local database application to XERO.
Connection works fine when running on my machine at the office but when I port it to the clients terminal server I get this error.
System.Net.HttpListenerException (0x80004005): Access is denied
at System.Net.HttpListener.AddAllPrefixes()
at System.Net.HttpListener.Start()
at XeroConnectionTest.clsXeroAuth2.VB$StateMachine_6_oauth2.MoveNext() in Q:\XeroConnectionTest\XeroConnectionTest\clsXeroAuth2.vb:line 21
This is the code where it fails
Private callbackurl As String = "http://localhost:5000/signin/"
Public Async Function oauth2() As Task(Of Boolean)
Dim redirectUri As String = String.Format(callbackurl)
Dim listener = New HttpListener()
listener.Prefixes.Add(redirectUri)
Try
listener.Start()
stopListening = False
Catch hlex As HttpListenerException
'MsgBox(hlex.ToString)
Form1.TextBox1.Text = hlex.ToString
Return False
End Try
and the error occurs on listener.start() line.
Any help would be gratefully received
Thanks
Frostie
I'm trying to launch Internet Explorer with a different user to access a website that requires single sign on.
Below is the code that I'm using. It doesn't produce any errors but IE doesn't launch at all, not even the process.
Try
System.Diagnostics.Process.Start(IExplorerPath, Username, ConvertToSecureString(Password), Domain)
Success = True
Catch ex As Exception
Success = False
Error_Message = ex.Message
End Try
I also tried the following variation with the same result (nothing):
Try
Dim psi As New ProcessStartInfo()
psi.Filename = IExplorerPath
psi.UserName = Username
psi.Domain = Domain
psi.Password = ConvertToSecureString(Password)
psi.UseShellExecute = False
Process.Start(psi)
Success = True
Catch ex As Exception
Success = False
Error_Message = ex.Message
End Try
This is the ConvertToSecureString function:
Function ConvertToSecureString(ByVal str As String)
Dim password As New SecureString
For Each c As Char In str.ToCharArray
password.AppendChar(c)
Next
Return password
End Function
Ok, I've been searching a lot a solution for this and if you have it you deserve a Nobel price. In the mean time, if it helps anyone this is the workaround that I had to use:
Use Process.Start to run a .bat file that contains the following code:
runas /user:User#Domain.com "C:\Program Files\Internet Explorer\iexplore.exe"
Then, when the command prompt appears I use the Send Keys to type in the password and press Enter.
This launches IE with different credentials. But again, there should be a better way.
This may / may not work. Try to launch your website that requires single sign on in "CHROME", hit F-12, go to Application Tab -> Cookies -> Click on your site link. on left hand side look for something that represent your session id, may be JSESSIONID or similar, copy that. Now open your Internet Explorer, hit F-12 and manually create that JSESSIONID by running this command in console window
document.cookie = "JSESSIONID=<your-session-id-from-chrome"
hit play button to execute script
Refresh your browser
I am attempting to utilize a REST service that uses a GET method. I'm using the .Net Framework 4.5.2. What I've written below is just a test to see if I can actually make the request. If I put the URL directly into a browser I get a good response back with string data in json format. But when I attempt to run the code I end up getting the following error back:
"The underlying connection was closed: An unexpected error occurred on a send."
InnerException = {"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."}
I have tried setting the keepalive to both true and false and I've tried using a WebClient along with DownloadString too....all result in the same error. Does anyone have any idea of what I'm missing? Or is this a problem somehow on the server side?
Dim script As String = "236"
Dim deploy As String = "1"
Dim compid As String = "915960_SB2"
Dim h As String = "value1"
Dim id As String = "1241389"
Dim status As String = "in freezer"
Dim request As HttpWebRequest
Dim response As HttpWebResponse
Try
'I have removed the real website name from this code.
Dim theurl As String = "https://website/app/site/hosting/scriptlet.nl?script={0}&deploy={1}&compid={2}&h={3}&Id={4}&Status={5}"
Dim url As String = String.Format(theurl, script, deploy, compid, h, id, status)
request = HttpWebRequest.Create(url)
request.Method = "GET"
request.ContentType = "application/json"
'This is where the error occurs
response = request.GetResponse()
Catch ex As Exception
Dim test as string=""
Finally
End Try
I solved it. I stumbled upon the following web site where someone else had been having the same issue.
http://www.avivroth.com/2013/05/02/rest-calls-in-net-c-over-ssl-https/
The solution is to set the security protocol. I just went down the list from ssl to tls11 then to tls12 and found that the last one worked.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
I'm trying to connect on a server in vb.net win forms. I put a button and a text area to receive the data. But I'm unable to connect on the server. The server is open because i can ping it.
Private Sub SimpleButton1_Click(sender As System.Object, e As System.EventArgs) Handles SimpleButton1.Click
Dim PasswordConnection = New PasswordAuthenticationMethod("username", "pass")
Dim KeyboardInteractive = New KeyboardInteractiveAuthenticationMethod("username")
Dim ConnectionInfo = New ConnectionInfo("server.com", 22, "username", PasswordConnection, KeyboardInteractive)
Using client As New SshClient(ConnectionInfo)
client.Connect()
Dim cmd As SshCommand
Dim result As String
Dim result2 As String
cmd = client.CreateCommand("who")
cmd.CommandTimeout = TimeSpan.FromSeconds(10)
result = cmd.Execute
result2 = cmd.Error
MemoEdit1.Text = cmd.ExitStatus
If String.IsNullOrEmpty(result2) Then
MemoEdit1.Text = result2
End If
MemoEdit1.Text = result
client.Disconnect()
End Using
End Sub
Am I doing something wrong?
The program stuck directly on the "client.Connect()". As you can see im trying to connect on the event click of SimpleButton1
Normally No suitable authentication method found to complete authentication is used is returned from an SSH server when the server does not allow authentication by the offered methods by the client.
The SSH server could only allow public key authentication, or some form of two factor authentication in turn preventing password authentication. Download an SSH client like Putty and try to connect to the server directly and see what the result is.
I am new to programming in vb.net. I have come a long ways in my development and understanding of vb, but there is one hurtle I can not seem to fix. I am hosting an ftp server on my pc and I am making an app for it to connect to my server and download files. The problem with all the sample code is that everyone ASSUMES the server WILL be ONLINE. My pc may not be running 24/7 and I also may not have the ftp service running.In the first case it shouldnt even register that it is connected. In the second case, it WILL say that is connected b/c the pc is on, but it will return that the machine ou are trying to connect to is actively refusing the connection. Is there a way to TRULY check if the program is indeed connected to the server WITHOUT generating a bunch of Exceptions in the debugger? All I want is a call like:
Dim ftponline As Boolean = False 'Set default to false
ftponline = checkftp()
If ftponline Then
'continue program
Else
'try a different server
End If
So it would be a function called checkftp that returns a boolean value of true or false.
Here is my info:
Using Visual Studio 2010 Pro
Using .Net framework 4
Can anyone help?
Thanks!
I have tried the rebex ftp pack as well as the Ultimate FTP Pack.
Here is the updated code:
Public Function CheckConnection(address As String) As Boolean
Dim logonServer As New System.Net.Sockets.TcpClient()
Try
logonServer.Connect(address, 21)
Catch generatedExceptionName As Exception
MessageBox.Show("Failed to connect to: " & address)
End Try
If logonServer.Connected Then
MessageBox.Show("Connected to: " & address)
Return True
logonServer.Close()
Else
Return False
End If
End Function
Public Sub ConnectFtp()
types.Clear()
models.Clear()
ListBox1.Items.Clear()
ListBox2.Items.Clear()
TextBox2.Clear()
Dim request As New Rebex.Net.Ftp
If CheckConnection(*) Then
Dim tempString As String()
request.Connect(*)
request.Login(*, *)
request.ChangeDirectory("/atc3/HD_Models")
Dim list As Array
list = request.GetNameList()
Dim item As String = ""
For Each item In list
tempString = item.Split(New Char() {" "c})
If types.Contains(tempString(0)) = False Then
types.Add(tempString(0))
End If
If models.Contains(item) = False Then
models.Add(item)
End If
Next
request.Disconnect()
request.Dispose()
ElseIf CheckConnection(*) Then
request.Connect(*)
request.Login(*, *)
request.ChangeDirectory(*)
Dim list2 As Array
list2 = request.GetNameList()
Dim item2 As String = ""
Dim tempString2 As String()
For Each item2 In list2
MessageBox.Show(item2)
tempString2 = item2.Split(New Char() {" "c})
If types.Contains(tempString2(0)) = False Then
types.Add(tempString2(0))
End If
If models.Contains(item2) = False Then
models.Add(item2)
End If
Next
request.Disconnect()
request.Dispose()
End If
End Sub
No matter what I do, the second server will not connect. I even put a messagebox to show what items were being returned in the second server, but there are no messageboxes apearing when I run the program with my server offline. Is there anyone who can help?
If your code is designed with proper exception catching, it shouldn't be generating a "bunch" of exceptions. The first exception you catch should be your indication that the connection failed and your code should cease attempting to communicate at that point. If for some reason you really need to check the connectivity before attempting the FTP connection, you should be able to simply attempt to synchronously open a TCP socket to the FTP server's port. If that works, it's up and running.
You could simply open a socket to the server's IP address on Port 21 (assuming default FTP port).
I'm not much of a VB.Net programmer, but here's a link to sample code:
http://vb.net-informations.com/communications/vb.net_Client_Socket.htm
If you can establish the socket connection, you know that something is listening on that port (though you have not yet proven it's an FTP server, or that it will accept your login credentials...).
If you wish to simply avoid exceptions in the debugger, you could place the connection code in a method and apply the DebuggerHidden attribute to that method.