run a program on windows startup

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 544 Views - Last Post: 22 March 2019 - 12:33 PM Rate Topic: -----

#1 miladzz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-March 19

run a program on windows startup

Posted 22 March 2019 - 04:46 AM

hello dreamincode family, i'm happy to join the forum.

i need resolve my startup error

form1 is empty nothing in i just want test startup but when i do this, i open form1 test.exe copy to startup but when i restart the computer nothing run ? i want learn why ?


Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


        FileCopy("TEST.exe", Environment.GetFolderPath(Environment.SpecialFolder.Startup) & "\TEST.exe")


    End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: run a program on windows startup

#2 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6775
  • View blog
  • Posts: 27,938
  • Joined: 12-December 12

Re: run a program on windows startup

Posted 22 March 2019 - 04:54 AM

Please describe what you are attempting to do.

(In particular, the Startup folder is intended for shortcuts, not executable files.)
Was This Post Helpful? 0
  • +
  • -

#3 miladzz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-March 19

Re: run a program on windows startup

Posted 22 March 2019 - 05:19 AM

its for my self, i will create a application for delete %temp%, temp, recent, cache files for speed my pc its all but i want before make startup and after i will edit, and in the futur share with some people why not
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6775
  • View blog
  • Posts: 27,938
  • Joined: 12-December 12

Re: run a program on windows startup

Posted 22 March 2019 - 05:30 AM

If you search, for example, ".net add shortcut to startup folder" you can find links like this.
Was This Post Helpful? 0
  • +
  • -

#5 miladzz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-March 19

Re: run a program on windows startup

Posted 22 March 2019 - 05:34 AM

how use it ? ; http://prntscr.com/n1fpg9
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6775
  • View blog
  • Posts: 27,938
  • Joined: 12-December 12

Re: run a program on windows startup

Posted 22 March 2019 - 05:55 AM

The author included some basic instructions,

Quote

Create a shortcut to your program in the Window’s startup folder so the programs starts up at boot time. You need to “Add reference…” from the right click on your project from the hand pane and add “Windows Script Host Object Model” from the COM tab. Below change “program” to whatever your program is called.

so what issue do you have with the code?
Was This Post Helpful? 0
  • +
  • -

#7 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 209
  • View blog
  • Posts: 1,182
  • Joined: 05-December 13

Re: run a program on windows startup

Posted 22 March 2019 - 08:25 AM

Create a reference to Windows Script Host Object Model by going to Your Project Name / Add Reference / Com Library or something to that effect / Windows Script Host Object Model. / Tick it and add it. Then ::
Option Strict On
Option Explicit On
Imports System.IO
Imports System.Environment
Imports IWshRuntimeLibrary

Public Class Form1
    Public PdName As String = Application.ProductName
    Private Sub PopulateBtn_Click(sender As Object, e As EventArgs) Handles PopulateBtn.Click
        CreateSCut(PdName, "MyApp")
    End Sub
    Public Sub CreateSCut(ByVal pdtName As String, ByVal Descrip As String)
        Dim ShellSrpt As WshShell = New WshShell()
        Dim startupPath As String = GetFolderPath(SpecialFolder.Startup)
        Dim myShortcut As IWshShortcut = CType(ShellSrpt.CreateShortcut(Path.Combine(startupPath, PdName) & ".lnk"), IWshShortcut)
        myShortcut.TargetPath = Application.ExecutablePath
        myShortcut.WorkingDirectory = Application.StartupPath
        myShortcut.Description = Descrip
        myShortcut.Save()
    End Sub
End Class

Remember to import Imports IWshRuntimeLibrary after you've done it - adding the reference is not enough. Public PdName As String = Application.ProductName gives you your product name, whatever you've called your app will be set to this string here. This CreateSCut(PdName, "MyApp") calls the subroutine, and passes the parameters of the product name and your description of your applications shortcut to the method to execute.

Hope it helps.

Also, I may be wrong, but I don't think your current method will allow you to copy a running executable. (That may depend on your PC permissions.) So the way forward is to use the Windows Script Host Object Model.

There is also no need to write in red text, it just burns my eyes, and welcome to the site. ;)
Was This Post Helpful? 0
  • +
  • -

#8 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 209
  • View blog
  • Posts: 1,182
  • Joined: 05-December 13

Re: run a program on windows startup

Posted 22 March 2019 - 09:19 AM

Hi, please do not PM me for help or about your posts. I will check your topic if or when I have time. Meanwhile paste a screenshot of the code you tried to implement. I want to see this section of your VS UI - If I don't reply, I am sure others will help you implement my code. I've also tested it before giving it, and it works fine for me.

Attached Image

Post your code or what you've changed including any errors you have.
Was This Post Helpful? 0
  • +
  • -

#9 miladzz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-March 19

Re: run a program on windows startup

Posted 22 March 2019 - 11:48 AM

error : http://prntscr.com/n1l9dd
Was This Post Helpful? 0
  • +
  • -

#10 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 209
  • View blog
  • Posts: 1,182
  • Joined: 05-December 13

Re: run a program on windows startup

Posted 22 March 2019 - 12:10 PM

I will assume you simply copied the code and expected it to work. I also assume you need a button on your form with the name (type sensitive) as it is named in the error. Simply drag a button to your form, and name it :: PopulateBtn

Double click the button. Paste this line into the buttons click event ::
CreateSCut(PdName, "MyApp")


Working?
Was This Post Helpful? 0
  • +
  • -

#11 miladzz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-March 19

Re: run a program on windows startup

Posted 22 March 2019 - 12:20 PM

ahahh sorry friend i'm new and i know nothing in program language

build OK but when i click on button1 = http://prntscr.com/n1lozd

source = http://prntscr.com/n1lpab
Was This Post Helpful? 0
  • +
  • -

#12 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 209
  • View blog
  • Posts: 1,182
  • Joined: 05-December 13

Re: run a program on windows startup

Posted 22 March 2019 - 12:23 PM

Posted Image
Was This Post Helpful? 0
  • +
  • -

#13 miladzz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-March 19

Re: run a program on windows startup

Posted 22 March 2019 - 12:23 PM

update : work only in folder when i drag on desktop don't work because Interop.IWshRuntimeLibrary.dll need be here i understand :)

work when i open startup the folder is not startup, the folder is

C:\Users\User\Documents\Visual Studio 2015\Projects\WindowsApplication3\WindowsApplication3\bin\Debug
Was This Post Helpful? 0
  • +
  • -

#14 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14925
  • View blog
  • Posts: 59,590
  • Joined: 12-June 08

Re: run a program on windows startup

Posted 22 March 2019 - 12:23 PM

Please copy/paste the code into your post as well as the error message.
Was This Post Helpful? 0
  • +
  • -

#15 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 209
  • View blog
  • Posts: 1,182
  • Joined: 05-December 13

Re: run a program on windows startup

Posted 22 March 2019 - 12:25 PM

No bother, but please translate the error you are getting into English. You can use Google translate.

As seen in the gif I just tested it and it works.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2