i have 2 vb applications. this is the code for the first one which when a button is clicked it will check if the other application is already open. If not, it'll open that application -
Dim sComputer As String
sComputer = Environ("COMPUTERNAME")
Dim LocalByName As Process() = Process.GetProcessesByName("ticket.prices", sComputer)
If LocalByName.Length = 0 Then
System.Diagnostics.Process.Start("http://ticket.prices.application")
End If
this runs fine. but what i need is that the customerid on the application 1 that is calling application 2, should be transfered while opening app 2.
e.g -
Customer 10001 screen is open on app 1. When i click open app 2, the above code runs and opens app 2. how do i make app 2 open to customer 10001 screen. Is there any way to pass parameters while opening app 2 in System.Diagnostics.Process.Start ?
Use the version of 'Process.Start' that takes 2 strings, the second being the commandline parameters. See here for details.
You want the ProcessStartInfo class, or use the Start method taking to strings. ProcessStartInfo gives you a lot of options about how to start your program, which often comes in handy. Its good to get familiar with it.
Dim info as New ProcessStartInfo()
info.Arguments = "10001"
info.FileName = "exename"
Dim LocalByName as New Process()
LocalByName.StartInfo = info
LocalByName.Start()
Getting the arguments in the new program is accomplished via Environment.GetCommandLineArgs()
For Each arg As String In Environment.GetCommandLineArgs()
Console.WriteLine(arg)
Next arg
It looks like what you ultimately want to accomplish is getting the currently selected row from App 1 and passing that to the second program, though. Is this correct? That opens a whole new ball of wax involving interprocess communication.
EDIT: The simplest way to get the selected edit would be to write the id out to a text file. You have to be careful when doing this because if you just write System.IO.File.WriteAllText("selectedrow.txt", "123"), you'll write to the app's startup path directory. You'll want to get the exe's current path as below
Dim u as New Uri(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
dim exepath as String = System.IO.Path.GetDirectoryName(u.LocalPath)
dim fullPath as String = System.IO.Path.Combine(exepath, "selectedrow.txt")
System.IO.File.WriteAllText(fullpath, "123")
This will overwrite the text in the file every time you change rows. You want to wrap this in a try/catch block so as not to crash the program. Make sure you log the errors; don't just swallow them. To read the data, you just do
dim id as string = System.IO.File.ReadAllText(PathToFileYoureWritingToInTheOtherProgram)
in the other program.
This isn't necessarily the best way to go about things, but its the simplest way I know of off the top of my head.
You might could look at MessageQueues if you a better solution, but as long as you're not changing selected rows every 100ms, writing the file should work fine.
Related
Greetings all: I have been struggling for 2 days to figure this out and have tried various techniques with frustrating results. I'm trying to start up a different database and close/quit the calling (first) database. I've created 2 button-click subs, one works very well and the second (which appears to be identical) flashes the new Db and then immediately returns to the calling DB. Here's the code that works well:
Dim objLeaveLookup As Object
Dim objOtherMenu As Object
Set objOtherMenu = GetObject("M:\QueryData\DBA Maintenance.mdb")
Set objLeaveLookup = GetObject("M:\QueryData\DBA_LookUp.mdb")
' Open Maintenance menu & quit DBA_Lookup
objOtherMenu.DoCmd.OpenForm "frm_MaintMenu"
objLeaveLookup.Application.Quit
and here is the code flashes the different Db, then frustratingly immediately returns to the original Db:
Dim objLeaveLookup As Object
Set objOtherMenu = GetObject("M:\QueryData\PurchMenu.mdb", "Access.Application").Application
Set objLeaveLookup = GetObject("M:\QueryData\DBA_LookUp.mdb", "Access.Application").Application
' Open Purchasing menu & quit DBA_LookUp
objOtherMenu.DoCmd.OpenForm "frm_PurMenu"
objLeaveLookup.Application.Quit
Any help to get the desired results will be GREATLY appreciated.
You may use FollowHyperlink.
See here: https://www.devhut.net/2018/01/21/ms-access-vba-open-another-database/
I am trying to figure out how to cause a Menu Strip item to open the active Windows accounts default browser to their homepage. I have tried Process.Start("about:blank") and for some reason this always opens Internet Explorer's about:blank page. (I have Google Chrome as my default browser with http://www.duckduckgo.com as its homepage on Windows 7 Pro.)
I know I can specify any URL to open the default browser, but how to get their selected homepage to open? I have found some articles based in C# that required looking into registry entries as to finding their chosen homepage per each browser. Would the process be the same/similar in VB.Net 2017 and how would I go about doing so? This is using VB.Net 2017 Community Edition and the project is a Windows.Forms desktop application.
The only way I found is to manually query the registry about the default command to handle the http protocol.
The first line of this code will return something like "C:\Program Files\Your Browser\browser.exe" -osint -url "%1", so you want to replace %1 by your landing page.
Then, if you want to use Process.Start with command line arguments, the first parameter will be the command and the second one the arguments.
Thus, we need to split the registry string between the command and the argument list. The regex will do this job.
I omited null checks and regex success for clarity.
Dim cmd = CStr(Registry.ClassesRoot.OpenSubKey("http\shell\open\command").GetValue(String.Empty))
cmd = cmd.Replace("%1","about:blank")
Dim r = new Regex("^""([^""]+)"" (.*)")
Dim m = r.Match(cmd)
Process.Start(m.Groups(1).Value, m.Groups(2).Value)
Found some clues here.
Dim readValue As String = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\
Associations\UrlAssociations\http\UserChoice", "Progid", Nothing).ToString
Will give an identifier for the current user's browser.
Dim path As String = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\"
& readValue & "\shell\open\command", "", Nothing).ToString
Will return the run command with path.
Add some code to extract the EXE and run it without arguments, for example;
Dim DivArr As Char() = {Chr(34), "\"c}
'split into segments using quotes and back-slash seperators
Dim parts() As String = path.Split(DivArr)
'find first segment with period/full-stop
Dim Executable As String = Array.Find(parts, Function(x) (x.Contains(".")))
Process.start(Executable)
You may try this:
Process.Start("your_url_here eg. www.homepage.com etc.")
and, this will open with google chrome if its your default browser.
This is a fairly simple app that opens and decodes packed XML. I can open the files directly from the apps UI no problem.
The issue is, I have 2 types associated with my app.
The ICON shows next to the 2 file types as they should, how ever, only one, if double clicked shows up in the Environment.GetCommandLineArgs().
Dim arguments() = Environment.GetCommandLineArgs() seems fool-proof.
I have used a msgbox to trap and display anything in position 1 of the list and the 2nd file type NEVER sends anything to the args list.
I am deploying (for now) using clickOnce and added per what I read at MS's site the following to the manifest file:
<fileAssociation
xmlns="urn:schemas-microsoft-com:clickonce.v1"
extension=".visual"
description="WoT visual file"
progid="wotvisual"
defaultIcon="XMLFile_789_32.ico"
/>
<fileAssociation
xmlns="urn:schemas-microsoft-com:clickonce.v1"
extension=".chunk"
description="WoT chunk file"
progid="wotchunk"
defaultIcon="XMLFile_789_32.ico"
/>
This is at the head of my main form load event:
Dim arguments() As String = Environment.GetCommandLineArgs()
If arguments.Length > 1 Then
Dim s1 = arguments(1)
If s1 <> String.Empty Then
openVisual(s1)
End If
I should mention that dbl clicking either file does indeed open my app.. It just never sees anything as in file path, from the .chunk types.
And if you spotted it, this is World Of Tanks I'm working with. I write tools for the modding community.
Good Morning,
I have been tasked with writing a program that locates the local port a MAC Address is registered to, and to do that I need to SSH and Telnet into Cisco devices and receive the output of the commands so I can parse it and decide what to do with the information.
So far I have the SSH connection and parsing done no problem thanks to Renci.SshNET. But I am having trouble with the Telnet, I set it up to use Telnetlib.dll and I know it works because I can do "show users" on the switch I'm connecting to and see that one of the vty lines are being occupied by my application. But in the application I'm writing all I get is the application freezing up, none of the buttons work, and I can't see the mouse when I hover over the window, so I'm guessing that the application isn't liking something at run-time.
The code I'm using, in VB.NET is:
Using client As TcpClient = New TcpClient(host, 23)
Dim tel As TelnetStream = New TelnetStream(client.GetStream)
Dim buff(client.ReceiveBufferSize) As Byte
Dim result As String
tel.SetRemoteMode(TelnetOption.Echo, False)
Dim exp As Expector = New Expector(tel)
exp.Expect("username: ")
exp.SendLine(username)
exp.Expect("password: ")
exp.SendLine(password)
exp.Expect(">")
tel.Read(buff, 0, buff.Length)
result = System.Text.Encoding.ASCII.GetString(buff)
MessageBox.Show(result)
End Using
Telnetlib.dll include the definitions for the Expector, SendLine, Expect, and TelnetStream.
I did some debugging and found that it freezes when it goes to execute the result = System.Text.Encoding.ASCII.GetString(buff)
command.
Thanks for any help.
I have been searching the web looking for a way to open a WORD file from a secure network folder by impersonating a user who has access. The closest I've come to finding the answer was this from 2 years ago:
Impersonating in .net (C#) & opening a file via Process.start
Here is the code that I am using. When I set the arguments = LocalFile_Test, everything works perfectly because the user is accessing the local c:\ that is has access to. But when I set arguments = RemoteFile_Test, Word opens up a blank document which is the same effect as if I put garbage in the arguments. So it appears that it cannot find the file even though when I login with the user/domain/password that I specify in the properties below, I can find that exact file name and it is not empty. Does anything jump out at you right away? I appreciate your time.
Dim LocalFile_Test As String = "C:\New.docx"
Dim RemoteFile_Test As String = "\\Server1\Apps\File\New.docx"
Dim MyStartInfo As New System.Diagnostics.ProcessStartInfo
MyStartInfo.FileName = "C:\Program Files\Microsoft Office\Office12\WINWORD.exe "
MyStartInfo.Arguments = LocalFile_Test
MyStartInfo.LoadUserProfile = True
MyStartInfo.UseShellExecute = False
MyStartInfo.UserName = "specialuser"
MyStartInfo.Domain = "mydomainname"
MyStartInfo.Password = New System.Security.SecureString()
MyStartInfo.Password.AppendChar("p"c)
MyStartInfo.Password.AppendChar("a"c)
MyStartInfo.Password.AppendChar("s"c)
MyStartInfo.Password.AppendChar("s"c)
Process.Start(MyStartInfo)
My understanding is that you are trying to get a password protected file from a server, and when you do process start, it just opens up a blank word doc. I think the error is how you are trying to get the file, I think you have to map the actual physical path of the file on the server, like
System.Web.HttpContext.Current.Server.MapPath("\\Server1\Apps\File\New.docx")
From there, I am fairly certain, you need to create network credentials for the user like
System.Net.NetworkCredential=New NetworkCredential(userName:=, password:=)
Finally, once that is done, you can either write the file, or transmit the file like so...
System.Web.HttpContext.Current.Response.TransmitFile(file name)
System.Web.HttpContext.Current.Response.WriteFile(file name)
Then,once you get the file, you can try to open it with process start.
Hope that helps, let me know if what I said doesn't work.