Share via


Start VB.net application automatically when windows loads

Question

Wednesday, July 11, 2012 9:29 AM

I had developed an application in VB.NET 2010 and I want that after installing that application on any pc that application start automatically without manually starting it. How can i automatically start a vb.net application on windows startup or load?

Any Idea, help will be appreciated.

All replies (8)

Wednesday, July 11, 2012 11:24 AM ✅Answered | 2 votes

Hi programbeginner0011..

Welcomes you to MSDN forums.. This is very simple one. A Lot of time this will discussed in MSDN and lotof links have the Exact solutions.

Simply you create a shortcut for your application and add it to startup in Start-> all programes.. this steps you want to do in your application set up project..

Try the following links and it have  detailed & different approach, inforamtions for you..

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/27c7840e-e720-4c98-98db-47775cb683ef

http://social.msdn.microsoft.com/forums/en-US/vblanguage/thread/02540681-8c6b-4250-af78-158bc05b59f4

http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/2465cf86-5c9c-4544-8d0c-a1cbd95f5a06/

I hope it will enough for you..

If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful"


Friday, July 13, 2012 2:43 AM ✅Answered

Hi programbeiginner0011,

To start VB.net application automatically when windows loads you could add a shortcut of your application to the windows startup path:

1- Right click your project name in the solution explorer and add reference then in the com tape select "Windows Script Host Model" and hit OK.

2- you could create your shortcut when you lunch the application the first time (Form_Load) or add button or checkbox, whateve you like.

3- you need to copy the Interop.IWshRuntimeLibrary.dll from your debug folder to wherever you are going to but you application. or you could do that in the reference properties.

Imports IWshRuntimeLibraryPublic Class Form1    Dim SRT As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)    Dim SRTLNK As String = SRT & "\SRTSHCUT.lnk"    'To create Start shortcut in the windows Startup folder:    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged        'Add shortcut.        Dim WSHC As WshShellClass = New WshShellClass        Dim SRTSHCUT As IWshRuntimeLibrary.IWshShortcut        SRTSHCUT = CType(WSHC.CreateShortcut(SRTLNK), IWshRuntimeLibrary.IWshShortcut)        SRTSHCUT.TargetPath = Application.StartupPath & "\StartWhenWindowsStart.exe"        SRTSHCUT.Save()    End Sub    'To delete the shortcut:    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged        If IO.File.Exists(SRTLNK) Then            IO.File.Delete(SRTLNK)        End If    End SubEnd Class

Regards,


Wednesday, July 11, 2012 2:04 PM

Create shorcut in your desktop..after publish


Wednesday, July 11, 2012 2:38 PM

I am doing exactly the same thing as described in the tutorial, for example my application name is "Reader.exe" which is installed under "c:\program files\readerapp\reader.exe"

Dim CU As Microsoft.Win32.RegistryKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")

        With CU.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue("reader.exe", "D:\Program Files\readerapp\reader.exe")

        End With

NY USING ABOVE CODE VB SAYS THAT "EXPRESSION DOES NOT PRODUCE A VALUE"

IS THERE ANYTHING WRONG IN THE CODE ?  PLEASE DO LET ME KNOW !!

Thanks and Regards,


Wednesday, July 11, 2012 3:50 PM

SetValue does not produce a value as it's a Sub. I guess you want to put the call, including the preceding dot, into the With block.

Armin


Thursday, July 12, 2012 3:38 AM

how can we do this, can you please explain me a bit with an example code ,, thanks in advance !!


Thursday, July 12, 2012 10:42 AM

You have to move the call to SetValue, including the preceding dot, into the with block. Just select it, then move it. That's all.

Armin


Thursday, July 12, 2012 6:17 PM

or cut the section of code and paste (copy and paste dude! Dont spend too much time in front of the computer it does things to your mind ;D)  in with block.

Example:

With

Code moved here

ENd With

Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/