|
Sockets, with properly written code of course, is the fastest you're going to get.
The real bottleneck is going to be your database server hardware, database structure, quality of your queries and whatever code you write to send data back to the clients.
|
|
|
|
|
Using newtonsoft json to read a json file.
I download a sample json file with zip codes: http://jsonstudio.com/resources/
using this code:
Dim json As String = File.ReadAllText("C:\Users\Presentation\Desktop\zips.json")
Dim o As JObject = JObject.Parse(json)
But it fails with:
An unhandled exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll
Additional information: Additional text encountered after finished reading JSON content: {. Path '', line 2, position 0.
Why would this default, and I assume correct data file, fail already here?
Can anyone help me? Thx
|
|
|
|
|
It doesn't work because you're not deserializing a complete JSON document. You're actually trying to is deserialize a list of JSON fragments. You have to process this one line at a time, not all at once.
Given the identifier names in the JSON file are very short, you'd probably be better off creating a strongly typed class so you can map those short names to something more friendly in your code.
The code snippets are in C#, but are EASILY converted to VB.NET. I'm just too lazy to do it for you.
private IList<ZipCodeData> ProcessFile(string filepath)
{
using (var sr = File.OpenText(filepath))
{
List<ZipCodeData> objects = new List<ZipCodeData>();
var lineContent = sr.ReadLine();
while (!string.IsNullOrEmpty(lineContent))
{
var obj = JsonConvert.DeserializeObject<ZipCodeData>(lineContent);
objects.Add(obj);
lineContent = sr.ReadLine();
}
return objects;
}
}
The ZipCodeData class looks like this:
public class ZipCodeData
{
[JsonProperty("city")]
public string City { get; set; }
[JsonProperty("loc")]
public double[] Location { get; set; }
[JsonProperty("pop")]
public int Population { get; set; }
[JsonProperty("state")]
public string State { get; set; }
[JsonProperty("_id")]
public string Zip { get; set; }
}
|
|
|
|
|
OK thanks. That explains. I was living with the impression that a json file could be read at once, because I saw that json conversion to dataset or datatable.
|
|
|
|
|
You can, if the file is written correctly. The one you linked to isn't setup as a proper JSON array of objects so you have to process them one at a time.
|
|
|
|
|
i now how it works with a user:
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run "runas /user:'username' 'script.VBS'"
WshShell.AppActivate ("runas.exe")
but i want to put the clientcomputer instead of the user...
can you help me
|
|
|
|
|
You have to use WMI and the Win_Process class to start a process on a remote machine. Because of security risks, it can NOT be a user interactive process. The script you want to run must be on the remote machine so you will probably have to copy it over there first. Also, the person running your local script must have administrator permissions to the remote machine!
win32_process remote process[^]
|
|
|
|
|
I don't want to run it on a remote machine...
i want to start a script on a server and this script should run the other script on a normal pc... which is used by a user...
my problem is that when i run it on the user, my msgBox isn't shown anywhere, so I think i have to run it on the pc, isn't it right?
sry if my first question wasn't clearly...
|
|
|
|
|
You're not describing this correctly at all.
How many machines are involved. Give them names and use ONLY those names to refer to the machines. Do not use "user", use "Client" and "Server". Which machine is local and which is the remote machine?
Member 11916735 wrote: i want to start a script on a server and this script should run the other script on a normal pc.
OK. This describes a user logged into a server, running a script on it that will launch a script on a remote client machine.
What am I missing?
|
|
|
|
|
okay, please let me explain again:
I have one service running on the server (service is running as domain administrator).
this service executes my script.
this script should start another script on a client, wich prompts a msgbox for the currently logged in user.
Due the service (and so also the script) is running as domain administrator, I hope I can use its permissions for the client, no matter wich user is logged in on the client.
I hope everything is clearly for you now.
|
|
|
|
|
That's a LOT better!
Too bad, it's never going to work.
You can launch your process (script) on the remote machine. The problem is, because of security concerns, it's not allowed to put up any kind of user interface. The user on the machine will NEVER see the dialog box or anything that asks for input from the user on the remote machine. I think the security implications of code being launched on a users machine from an unknown remote server are quite obvious.
There is no way to get around this.
What's the purpose of this script running on the remote machine?
|
|
|
|
|
Starting the process as user will not work on Win2012. Getting access Denied and user is an admin
Dim psi As New System.Diagnostics.ProcessStartInfo
psi.UseShellExecute = False
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.Verb = "runas"
|
|
|
|
|
For the last time, you do NOT need the Verb = "runas" line at all. It does nothing in this context.
In what context is this code running? Is it part of a Windows Service? A console app? A Windows Forms app? What?
The code works fine as an admin user. It will NOT work if the user running this code is Local System.
|
|
|
|
|
it's a console app and user is admin user and even if I remove Verb = "runas" still getting the same issue
|
|
|
|
|
OK, now, is the app that you're trying to launch on a network share? If so, Does the user that you're impersonating have access to that share?
What happens if you change the WindowStyle to Normal?
|
|
|
|
|
Maybe this details will help.
SID1 have access to cmd.exe and shares.
SID2 have access to DB .
When I run this I am passing SID2 while accessing cmd.exe under SID1
psi.Domain = Domain
psi.UserName = UserName
Dim pword As New System.Security.SecureString()
For Each c As Char In Password
pword.AppendChar(c)
Next
psi.Password = pword
Settings windows to normal don't help
|
|
|
|
|
No, you're NOT accessing "CMD" as SID1 and as you've been told before, you don't need CMD.EXE. The process you are launching is done as the user you're impersonating. If that user doesn't have access to the shares you're going to get Access Denied.
The process is not created as SID1. It's created as the user you're impersonating. A security context is first created for the user you're impersonating, then CreateProcessAsUser is called in that context to load the executable and setup the process. The problem is that the user you're impersonating cannot load the executable because it doesn't have access to the share where the executable is stored. Access Denied.
You're going to have to grant access to the network location to the user you're impersonating for this to work.
|
|
|
|
|
Upvoted for persistence.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It's not the most accurate description of what happens behind the scenes, but it should be sufficient to get the point across.
|
|
|
|
|
Hi
I have one problem i visual basic 2008
I have one project in avr which send back text after receiving text from UDP terminal
for example Terminal send "Hello" , AVR send answer "Readed"
i have UDP terminal "Hercules" and all works good, but in VB not receive, but is one strange thing , when I open VB program first time, then UDP receive one text "Readed" , because I send one text in "Form1_Load"
also when I send from AVR text every 500ms (without waiting for PC) then all works good and UDP receive all texts,
not receive only when AVR wait for text from PC .
In terminal in Android also all works perfect, only in VB is problem.
can you help me ?
here is listing :
Imports System.Net
Imports System.Net.Sockets
Imports System.Net.EndPoint
Imports System.Text.Encoding
Imports System.Text
Public Class Form1
Dim publisher As New Sockets.UdpClient()
Dim subscriber As New Sockets.UdpClient(8899)
Dim counterAs Int16
Dim ep As IPEndPoint
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
counter+= 1
publisher.Connect(TbTo.Text, TbPort.Text)
Dim subscriber As New UdpClient()
Dim sendbytes() As Byte = ASCII.GetBytes(TbSend.Text & Chr(13))
publisher.Send(sendbytes, sendbytes.Length)
subscriber.Close()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
subscriber.Client.ReceiveTimeout = 3000
subscriber.Client.Blocking = False
ep = New IPEndPoint(0, 8899)
subscriber.Connect("10.10.100.254", 8899)
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Opened" & Chr(13))
subscriber.Send(sendBytes, sendBytes.Length)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Try
Dim rcvbytes() As Byte = subscriber.Receive(ep)
TbRcv.Text = counter & ASCII.GetString(rcvbytes) & vbCrLf
Catch ex As Exception
End Try
End Sub
End Class
|
|
|
|
|
Do you have a code example how to implement BCP or Bulk Insert in .net using .frm files.
|
|
|
|
|
I got something better; it's called documentation[^].
Contains explanation on all the switches and code examples.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I'm new in VBs..
i've got this code:
For i = 0 To 20 Step 1.0
MsgBox "Blubb"& i &"bla"
Next i
and this error:
800A0401
"Statement completion expected"
"Compile error in Microsoft VBScript"
modified 19-Feb-16 6:17am.
|
|
|
|
|
What's with
Hide Copy Code
? Comment that out....
|
|
|
|
|
sry that was a mistake, i don't have this in my code... it was a copy and paste error -.-
now my code is right
|
|
|
|