vba word - find application on system and launch it - vba

I have an application, user can install it on any folder in his/her computer how can I find my application on his computer(where it is installed and launch it)
Dim path
path = "path/to/myApplication.exe" 'path to myApplication is unknown I need to find it
Shell """" & path & """", vbNormalFocus
Is there any easy way I can find where user has installed my application on his computer, in windows

This SO Article offers a great solution to your problem.
You can always iterate recursively through the file system, but there are obvious downsides to this method (time, permissions, networks etc.).

Related

How to distribute my Vb.net Webview2 app?

So I developed an vb.net app with webview2. My problem is: if I copy the entire debug folder to a new computer, It works. But if I create an installer with the entire debug folder, it does not work. Any idea?
I'm using the stable package from NuGet.
When I copied and pasted the files I didn't even need to bother with installing the evergreen release and it worked.
Are you using the default user data folder and are you installing to Program Files? If so, you may need to explicitly specify your user data folder to an app data folder for your application. Read more about Managing user data folders in the WebView2 documentation.
The default user data folder is the path of the host app executable with ".WebView2" appended to the end. So notepad's default would be "C:\windows\system32\notepad.exe.webview2". This doesn't work when the path containing the host executable doesn't have permissions to allow the host app to create the user data folder. Most installers run elevated and have additional permissions to create the application's installed files and folders. But when the installed app runs it generally doesn't have permission to modify the contents of its install path. Instead you should explicitly specify a user data folder and manage that folder including potentially deleting it when your app is uninstalled.
Public Sub New()
Dim url As String = Nothing
InitializeComponent()
InitializeBrowser(url)
End Sub
Private Async Sub InitializeBrowser(ByVal Optional url As String = Nothing)
Dim userDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\SoftwareName"
Dim env = Await CoreWebView2Environment.CreateAsync(Nothing, userDataFolder)
Await WebView21.EnsureCoreWebView2Async(env)
WebView21.Source = New Uri("https://www.google.com/")
End Sub
Maybe this can be your solution:
On March 14th, Microsoft began auto-installing the 'Microsoft Edge WebView2 Runtime' on Windows 10 machines without any notification to users.
Source: https://www.bleepingcomputer.com/news/microsoft/microsoft-is-auto-installing-the-windows-10-webview2-runtime/

Download .exe from MediaFire

I am creating a project in VB, it has a files downloader, it works fine with files like .txt or images but when I try to download an .exe, the .exe turns to corrupted file.
I'm using this code:
My.Computer.Network.DownloadFile("http://www.mediafire.com/file/w9lk3emdczlb8hi/x_y_w_h.exe", "C:\Users\" & SystemInformation.UserName & "\Desktop\x_y_w_h.exe")
Process.Start("C:\Users\" & SystemInformation.UserName & "\Desktop\x_y_w_h.exe")
Downloads the .exe from the mediafire and sets the Location path and after it it opens it with Process.Start but the .exe is corrupted
This might help you:
Dim savePath As String = "your_save_path" 'Remember to include the file_name.extension_name at the end of the save path
Dim WebClientDownload As New WebClient
WebClientDownload.DownloadFile("http://download1917.mediafire.com/breo3h1b14og/w9lk3emdczlb8hi/x_y_w_h.exe", savePath)
MsgBox("Download Complete.")
Remarks:
I had this problem in the past. You were trying to save the html web page as a .exe file as said by #DavidWilson.
To solve this, you have to find the direct download link, in this case, I right-clicked on the download button and then clicked on "copy link address". It's always a good idea to test if the link copied is functioning (some file hosting sites invoke a script to start the download, but mediafire isn't that tricky)

Move a file from the current users desktop?

I was making a installer for some program I made, and I was wondering if I could copy the folder with the contents from the Current Users desktop to another area, how would I do so?Im using: My.Computer.FileSystem.MoveFile("", "")
Move the folder "Emailer" (on the desktop) to System files (x86)
To acces path to the desktop use:
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
After you've obtained the desktop location (as Garath has pointed out in his answer), check out File.Move in the System.IO namespace. e.g
File.Move(path, path2);
http://msdn.microsoft.com/en-us/library/system.io.file.move.aspx

Open a file (.mdb file in Access) in VB.NET

I want to open a mdb file through VB.NET
Currently, I use:
retval = shell("explorer.exe " & filename)
where filename includes the path.
It should open the mdb file in Microsoft Access.
This works fine on Windows 7 (my system), but when I try it on Windows XP (client machine) it comes up with the file download security warning dialog asking to Open, Save or Cancel. If I click Open it presents the same dialog but now with Save and Cancel only.
I am sure there is a quick and easy way to open a file in its proper program through VB.NET. I know I can open the database using Interop, but I don't want to go down that route.
Thanks
You can use Process.Start to launch a program. Some good examples here: http://www.dotnetperls.com/process-start-vbnet
For example:
System.Diagnostics.Process.Start("database.mdb")

how to execute a batch file using a relative path added to the project

i have created a batch file and have added it to the project using add items. Basically what i am aiming at is to execute this file on a button click action.
I am using System.Diagnostics.Process.Start("hello.bat") command to run this file
i have changed the build action to resource for this batch file.
But when i run this program, it is not able to locate the batch file.
I am required to give a relative path as the path my vary from machine to machine. how can i make this file accessable using a relative path?
Resource puts it inside of your EXE as data. You can google how to write a vb.net resource to a file, use the io tempfilename function to get a tempfile and use that (appending .bat), then run the batchfile from the name you gave it.
If you can ship the .bat with your EXE, this is convenient for debugging and production:
* Put the batchfile in the BIN subdir (debug or release) with your exe. May have to click 'show all files' in project explorer to see these dirs. Right click the .bat and pick 'include in project'. Don't make it a resource.
Run it using application.startuppath & "\" & batfilename. (application.startuppath is only in winforms. You can google 'how to get exe path in vb.net console app' etc. if you need another way).