I want to open EXE file from the project resources,
This file require no installation just came with two .dll files, I put all the files inside the resources but my problem is the path will be different if I run my project from other computer.
I'm trying this method, it works but I guess I should use different path like for example "my.resources"
Can someone tell me how I can do that if the EXE file require two .dll files to run?
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Process.Start("C:\Users\PC\source\repos\WindowsApp2\WindowsApp2\Resources\TSICT.exe")
End Sub
End Class
Related
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/
I am trying to make a copy of this directory from my program and when I try it tells me that, "the path does not exist".
If your application is a 32-bit app on a 64-bit system then you're experiencing what's called File system redirection.
Because 32-bit apps cannot load 64-bit dlls, and 64-bit apps cannot load 32-bit dlls, a 64-bit system has two system folders:
System32 - the 64-bit version with 64-bit dlls, and:
SysWOW64 - the 32-bit version with 32-bit dlls.
The File System Redirector automatically redirects %SystemRoot%\System32 to %SystemRoot%\SysWOW64 for all 32-bit apps trying to access the System32 folder, so the reason you cannot copy the directory is because it doesn't exist in the SysWOW64 folder.
There are three ways you can overcome this. I've listed them in the order where the first is the most recommended, and the last is the least recommended:
Use the SysNative folder instead.
Instead of C:\Windows\System32 you can use C:\Windows\SysNative which will take 32-bit apps to the original System32 folder.
If Environment.Is64BitOperatingSystem = True AndAlso Environment.Is64Process = False Then 'Is this a 32-bit app in a 64-bit system?
My.Computer.FileSystem.CopyDirectory("C:\Windows\SysNative\spp\store", "your destination path here")
Else 'This is either a 64-bit app in a 64-bit system, or a 32-bit app in a 32-bit system.
My.Computer.FileSystem.CopyDirectory("C:\Windows\System32\spp\store", "your destination path here")
End If
Compile your app in 64-bit mode or AnyCPU.
Disable File System Redirection by P/Invoking the Wow64DisableWow64FsRedirection() function. (I really do not recommend this as things might break if your app tries to load dlls from the system directory).
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
My.Computer.FileSystem.CopyDirectory("C:\Windows\System32\spp\store", "D:\store", True)
End Sub
I've made an application that gets installed/deployed to /Program Files/STUDYvault/ called "STUDYvault Client.exe" and in the app, a button triggers/calls a .cmd that's in the same directory, called 'Scripts System.cmd'
Private Sub SynchroniseToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles MenuBackup.Click
System.Diagnostics.Process.Start("SCRIPTS SYSTEM.cmd")
End Sub
The .CMD just runs basic xcopy commands for backups. When the software is executed manually, it sees the .cmd within the same directory, however, when it is run by the system (eg startup, either by registry key or via shortcut in the startup folder) (I tried both Inno Setup AND NSIS), it crashes with an Unhandled Exception, 'Cannot find the file specified'. I'm thinking the OS is executing the .exe but running it in say /Windows or /System32 or something. It doesn't seem to be an issue with the visual studio app (it runs when executed manually, and finds the .cmd no matter what the directory) or the installer (it's basically just extracting to /Program Files and putting a link in the startup part of the registry)
My friend and I thought up a workaround, although it's quite nefarious. One could force the user to install the software to C:/Program Files/STUDYvault and have it unchangeable, and then in the app have it point to C:/Program Files/STUDYvault/Scripts System.cmd instead of just "SCRIPTS SYSTEM.cmd" - could this work also?
I'm sure I'm just missing something stupidly small, because the application fires the following code fine when installed:
Private Sub HivemindTechToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles HivemindTechToolStripMenuItem.Click
System.Diagnostics.Process.Start("http://my-website.com.au")
End Sub
EDIT:
Alright, I've developed a work-around for anyone having this issue. It seems to be rights-related or where the system is executing it from; so it's calling on the .CMD from wherever that is (most likely not its install directory) - so in-app I've had it call on:
Private Sub SynchroniseToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles MenuBackup.Click
System.Diagnostics.Process.Start("C:\\Program Files (x86)\\STUDYvault\\SCRIPTSYSTEM.cmd")
End Sub
Which is the install directory, and then in the installer (Inno Setup) I've used the following for defining the install directory under [setup]:
DefaultDirName={sd}\Program Files (x86)\STUDYvault
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
DisableDirPage=yes
Here, DefaultDirName=SD\DIRECTORY defines that it will be force-installed to Program Files (x86) (Fine for 64-bit Windows users, 32-bit users will have to deal with a second Program Files folder but x64 is the most common install in this day and age anyway so we won't have an issue there); DisableDirPage=yes hides the install page that asks the user where they want to install it - most users will leave it as-is but for the more curious user who may want to change it, this WILL break the install, seeing as it's calling on /Program Files (x86)/STUDYvault in-app.
It's a relatively dirty fix, and I feel like Dr. Evil here, but ...it works. Hopefully this will help anyone having a similar issue in the future.
Use this
Process.Start(Application.StartupPath & "\SCRIPTSYSTEM.cmd")
You can get location of the executable file by using Environment.CurrentDirectory. Using this property we can make the code works regardless of executable folder location (as long as cmd file exist in the same folder, of course). So this maybe a more proper way to get the job done :
Dim batchFilePath As String = Path.Combine(Environment.CurrentDirectory, _
"SCRIPTS SYSTEM.cmd")
System.Diagnostics.Process.Start(batchFilePath)
You may want to improve it further by adding logic to check if cmd file actually exist in the location pointed by batchFilePath (you can use System.IO.File.Exists() to do that).
i am making a 'simple' program that on button click does this:
Private Sub Button4_Click(sender As Object, e As EventArgs)
Dim proc As New System.Diagnostics.Process()
proc = Process.Start("resources\navcoder.exe", "")
proc.WaitForExit()
End Sub
all works fine when testing in visual studio but not once i publish and install, even if the resource folder is in the install directory.
if i change it to:
proc = Process.Start("c:\resources\navcoder.exe", "")
it works fine, but i obviuosly needs to have the folder there with the required files in it.
what am i doing wrong?
A lot of people seem not to realise what resources are. The whole point of adding a resource to your project is to have the data it contains compiled into your EXE. The Resources folder in your project is just a place to store the original source files. It doesn't exist as far as the application is concerned, just as your VB source code files don't exist. When you build your project, the data in those resources is compiled into your EXE so they are no longer files and can no longer be used as files.
That's why you don't embed other EXE files as resources. You could extract the resource and save it as a file first but I would recommend against that. Add a new folder to your project and add the EXE file and any dependencies to that folder and set their Build Action to Content. They will then be copied to your output folder as is. You can then execute the EXE file because it is an EXE file. You should also use Application.StartupPath as the root of the file path rather then relying on the current directory being what you think it will be.
You should always check for existance, if its a web app, would do this in the application start in the global asax. If you are running this under a different user account, check the account has permissions. Otherwise even if the directory exists, it will fail if it cant access it or does not have permissions to execute the file.
Might be able to tell you more if you give the actual exception. I.e Unauthorized or does not exist.
I have added COM control AxWindowsMediaPlayer to form in vb.net.
and just have following code
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WMPlayerVideo.URL = "abase.mp4"
End Sub
End Class
abase.mp4 file is kept in directory where exe is there. Every thing runs fine on dev m/c but on client machine application is not lauached.
When Interop.WMPLib.dll and Interop.WMPLib.dll are copied to the exe file directory then application is lauched at least but file is not played automatically and even on pressing play button its not played.
Is some dll registration required to make it work? or some references needed in project?
or some changes on user machine?
Copying the DLLs is required, it cannot work otherwise. Which leaves the location of the file. You are only giving the relative location of the file, not the full path (like "c:\mumble\foo.mp4"). On your machine, this file needs to be stored in the bin\Debug folder of your project directory to make it work. Another machine you deploy your program to isn't going to have a bin\Debug (or Release) folder. It still needs to be present in the same directory as the EXE. Maybe you forgot to copy the .mp4 file?
Clearly you'll want to provide the user with a way to select the file. Use OpenFileDialog.