Getting Startup Location In Windows - vb.net

I've written a small program to open at startup, but I want to give the user the ability to delete it from showing on startup by clicking a button.
But it needs to be compatible on XP, Vista and Windows 7.
Is there a line of code which will get the default startup folder path automatically so I can then delete it using my button?
Thank you in advance

What you are wanting is the SpecialFolder.Enumeration. and use the Environment methods
Something like this Environment.GetFolderPath(Environment.SpecialFolder.Startup)
To do your deletion you need to use System.IO.File.Delete(path)
To check to see what files are out there try making a console application and use this code.
Module Module1
Sub Main()
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup)
For Each file In System.IO.Directory.GetFiles(path)
Console.WriteLine(file)
Next
Console.ReadLine()
End Sub
End Module

Related

How to make my System close and re-open automatically?

Im making a system, and as part of the system i need to have a reset function. I have tried Application.reset, environment and shell, but nothing seems to be working with the 2017 VB.net console app?
Just run the program and let the current instance exit. Warning: don't run this example. It'll create and endless loop of spawned processes.
Module Module1
Sub Main()
Process.Start("ConsoleApp2")
End Sub
End Module

VB.Net Application starts as background process in Windows 10

We have an internally developed VB.Net Windows Forms Application that handles all our Auto-Updating for our other software applications. Whenever I run the application in Windows 10, the application starts under the "Background Processes" section of the Task Manager. The only way I can get it to run in the foreground is to run it as an Administrator even though I'm an Admin on the VM and my UAC settings are turned all the way down. This doesn't happen in Windows 7 or 8 so I'm wondering if there's something I'm doing wrong or something about Windows 10 that's changed where it has to be run as an Admin. Our other applications don't seem to have this issue, it's just specifically this one application for some reason but I can't seem to figure out what's different.
So I put some more error handling in and it sounds like #xfx was onto the right idea. The application is erring when it starts up because it can't register the URL of the WCF service so it never got to the point where it was displaying the form. Once I manually registered the URL of the WCF service and ran the application as an Admin, it displayed and worked like normal.
This is because of the way the project has been configured in Visual Studio.
Here's how to create an application that behaves like a background process:
In the Project settings dialog, disable the Enable application framework option
Next, change the Startup object to Sub Main
Finally, add a Module to the project and add the following code:
Module Module1
Sub Main()
Application.Run()
End Sub
End Module
If you run the application (not from within the IDE, but directly) it will behave just like the one you describe.
The application will remain as a background process as long as it doesn't display a Form. As soon as one is displayed, you will see that Task Manager moves the process from the Background processes list to the Apps list.
To test this, just change the code in the Module for this version:
Imports System.Threading
Module Module1
Sub Main()
Dim tmp As New Thread(Sub()
Thread.Sleep(3000)
Using f As New Form1()
f.ShowDialog()
End Using
End Sub)
tmp.Start()
Application.Run()
End Sub
End Module
The application will start as a background process and 3 seconds later will display form, becoming a foreground process.

Showing pdf in Access form gets stuck on initializing screen

I am trying to display a pdf file in an Access form, but my code only works once. When I close the Access application and reopen it Acropdf doesn't display the pdf, it just gets stuck on this screen:
Private Sub Command1_Click()
Dim strPdfDoc As String
'Below is my source
strPdfDoc = "F:\Grifols\files\Unified Region TemplateV1_0_Budget.pdf"
'Here I am loading the pdf file with Acropdf
AcroPDF0.loadFile strPdfDoc
End Sub
I get no errors when debugging the code, but the pdf never shows.
I struggled with this issue for a long time, it was only happening when the EXE was run as Administrator.
My fix was the following:
Set EXE compile to x86 CPU
Change PDF output path to ProgramData: "C:\ProgramData(Client)(Project)"
Update code to first call "AxAcroPDF1.LoadFile(PDFfilepath)" then call "AxAcroPDF1.src = PDFfilepath"
Important: If you need to run the application on Windows Server for some reason, then the 32bit version of Crystal Runtime needs to be installed
Check that your version of Adobe Reader is up to date and replace your code with this. I was able to load the file several times, close and reopen and load again.
Private Sub Command1_Click()
Dim pdf As AcroPDF
Set pdf = Me.AcroPDF0.Object
pdf.LoadFile "F:\Grifols\files\Unified Region TemplateV1_0_Budget.pdf"
End Sub
I had Acrobat Reader DC installed, I Downgraded to 11 from this link
https://helpx.adobe.com/acrobat/kb/install-reader-x-windows.html
And changed the following registry setting to get this to work
To disable the Enable Protected Mode at startup configuration, navigate to the following registry key:
HKEY_CURRENT_USER\Software\Adobe\Acrobat Reader\DC\Privledged
… then modify the bProtectedMode REG_DWORD value to 0 to disable and 1 to enable:
found it at this link
http://terenceluk.blogspot.co.uk/2016/01/disabling-enable-protected-mode-at.html
I found a solution, that work for me, at this link:
To solve initializing screen for Acrobat Reader XI, just disable "Enable Protected Mode At Startup"

How to save/install a file into the C drive of users computer on installation of project?

I have a piece of code in my project that looks in to the users c drive to access the media folder (to play a sound). My problem lies with the fact that I have placed a WAV file called 'beep.wav' into this folder.
I want to be able to install this sound automatically into this folder if they have not already a file called 'beep.wav' in this folder. My method so far is :
Module playSound
Sub PlaySimpleSound()
Try
My.Computer.Audio.Play("c:\Windows\Media\Beep.wav")
Catch
End Try
End Sub
End Module
Any questions/ clarification please just ask.
Assistance greatly appreciated.
If this wav file is going to be exclusive to your program I would embed it into your program as a resource. You would then be able to access it without requiring it to be installed in their media folder.
Add your wave file as an Audio Resource and set it's Build Property to Embedded Resource
Then change your PlaySimpleSound Method to this, notice that I put the declaration for the SoundPlayer at the Module level so it is not created everytime you play the sound.
Module playSound
Dim sp As System.Media.SoundPlayer = New System.Media.SoundPlayer
Sub PlaySimpleSound()
Try
sp.Stream = My.Resources.beep
sp.Play()
Catch
End Try
End Sub
End Module
I'm not sure what you mean, but you can give the option to the user to open the sound(.wav) using an open file dialog. If that's not what you want, please let me know.

VB.net program with no UI

I'm making a VB.net program via a text file and I'm compiling it using vbc.exe via command line. I'm trying to get just a simple program to run in the background of my computer. Problem is, it displays the annoying console window. How do I get nothing to show? No form, no console?
Just use windows forms application don't load the form at all! Just go in project properties and uncheck enable application framework. Now, in the startup object dropdown, select "sub main". Add a module to the project and put a Public Sub Main() in it. You do all the stuff in main() and don't load form at all.
I think you need a form of some kind to keep the message loop going.
Maybe a NotifyIcon type program. It would keep it away from the task bar and desktop areas.
And then customize the NotifyIcon to "Only Show Notifications" from the "Customize" menu for your icon using Windows.
1) Add a module in your project, and create Sub Main
2) Write whatever you want in Sub Main,and MAKE SURE you end it with this statement:
Application.Run()
3) Open properties of your project and choose "Sub Main" as startup object
So , your application will have NO INTERFACE (NO FORM / NOT CONSOLE APPLICATION) and will run from Sub Main(), in addition it will NOT TERMINATE once all the code in Sub Main has executed.Your program will run like a NORMAL windows form application, and will only exit when you want.