Hi Everybody,

Sorry If i'm a bit of a noob at this. I'm wondering how to make a VB Program run in the background...If anybody knows how or has some code that would be great. Thanks for the help!

JBD2

you can make it run in the background by merely hiding the form. If you stick a timer on the form, then you can have it cycle to do something every so often. In the form load's procedure just add:

me.visible = false

Awesome!!Thanks!

Ok, Thanks for telling me that, and sorry these questions don't have anything to do with the topic but, what would I put in if I wanted my program to run when windows starts up? Thanks.

Ok, Thanks for telling me that, and sorry these questions don't have anything to do with the topic but, what would I put in if I wanted my program to run when windows starts up? Thanks.

You can make your program edit the registry on form load.... and then call your EXE. It's a good idea to give the user this option in an option form, or msgbox, so they know you are going to do this (I hate when programs try to force startup on me...)

dim wsh
set wsh = createobject("WScript.Shell")
Wsh.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyProgName", "c:\path2yourprogram.exe"

Obviously You need to change 2 things in the last line... you need to change "MyProgName" to whatever the name of your application is.... and you need to change "c:\path2yourprogram.exe" to the path where your program is installed. That should have it load on startup.

Thanks for the help.

Hi,

Sorry this is off topic but but i am quite a newbie to this. can i shell a program behind the VB Program? or make the shelled program hidden?


Tx

Jay

i do not wish to offend you or make any accusations
but it sounds as if you want the program to go undetected hmmmmm very suspicous

;D

You can make your program edit the registry on form load.... and then call your EXE. It's a good idea to give the user this option in an option form, or msgbox, so they know you are going to do this (I hate when programs try to force startup on me...)

dim wsh
set wsh = createobject("WScript.Shell")
Wsh.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyProgName", "c:\path2yourprogram.exe"

Obviously You need to change 2 things in the last line... you need to change "MyProgName" to whatever the name of your application is.... and you need to change "c:\path2yourprogram.exe" to the path where your program is installed. That should have it load on startup.

how do you remove it from the start-up list. because i wrote a program to annoy my friends little brother and i tried the startup thing and now i have a very annoying program that runs every time my computer starts. its not a huge deal 2 just close tthe program every time but i would prefer to not have to do that.

Go to start->run and type 'regedit'
Now find the folder in your registry: HKLM\Software\Microsoft\Windows\CurrentVersion\Run\ and remove the key that your program wrote here.

nick already answer your question. go to registry and delete the current file there.
or you can use msconfig manager.
go to start->run and type 'msconfig'.
click on startup tab then enable the files on list.

You can make your program edit the registry on form load.... and then call your EXE. It's a good idea to give the user this option in an option form, or msgbox, so they know you are going to do this (I hate when programs try to force startup on me...)

dim wsh
set wsh = createobject("WScript.Shell")
Wsh.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyProgName", "c:\path2yourprogram.exe"

Obviously You need to change 2 things in the last line... you need to change "MyProgName" to whatever the name of your application is.... and you need to change "c:\path2yourprogram.exe" to the path where your program is installed. That should have it load on startup.

Comatose: You have helped me out on this to. I am making a program that will clean up registry and is a sort of a script blocker for files....
I made it a feature where you can have it start when Windows starts or you can disable that. but i am having trouble disabling it. i used the code you gave to enable it (dim wsh
set wsh = createobject("WScript.Shell")
Wsh.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyProgName", "c:\path2yourprogram.exe")
but is there a code you undew that?

Go to start->run and type 'regedit'
Now find the folder in your registry: HKLM\Software\Microsoft\Windows\CurrentVersion\Run\ and remove the key that your program wrote here.

Ok, but is there a way to do it in visual basic? I am making a program that is like script blocking for files and i want the user to be able to enable or disable it at a click of a button with out going into regedit....
Is there a code to disable this is vb?

send me the entire code to run a application in background.

ummm how to you make it come back after this??????

Well I know this kinder old post but there are some horrible questions asked here, @sasankkanda there are so many ways to hide programs well I'm new in programming but I spend most of my time creating programs and learning new ways of dowing things, just the simple way to answer you Question, if your program is one form aka Form1 only then you will simply have to click the interface then go to properties then locate "Show Icon on ..." then both the above and bellow you have to change it to false this will just not show your applicaions icon on taskbar and on proccessor then the next thing you have to make your program run but it will be invissible so you just have to add any text editor tool e.g. Label, TextBox, ect, let say you choose Textbox now place your textBox on your Interface and since you want it to be Invissible that means there is nothing required from the user so the TextBox must be ontop of everything covering it all the Form1's Body then now you need to click this TextBox Then go to properties and Change Forecolor to Black, BackColor to Black and transparant to Black or to all you can just Choose the transparent color Note that all the color must be in the same name just like Black if you choose black then you have to work with it not Black and lite Balck. now Doble click the form1 to this codes

Private sub Form1_Load()

End Sub

now you just need to enter this codes.

Me.WindowState =FormWindowState.Minimized()
Me.Hide()

so your final code should look like this

 Private sub Form1_Load()
    Me.WindowState = FormWindowState.Minimized()
    Me.Hide()
    End Sub

or just use this code

Me.Visible = False

under the Private sub Form1_Load()

The OP hasn't been on DaniWeb for almost seven years. There is no need to revive this thread.

Ow jea, Well I don't know whether you can help me here I'm stuck, I've created a program and now I want to make it automatically run when a computer starts and if I do this manually it work perfectly but when I try to write codes to eigther copy or move my program from the installation Directory to the Startup Directory it giving me the error msg when debugging it. here is the code I'm using to copy it.

My.Computer.FileSystem.CopyFile(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData And ("\Roaming\Microsoft\Windows\Start Menu\Programs\The name of my program.exe"), My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData And ("\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"))

in the above line of code when I run the program it says conversion from string "C:\Users\my pc user name\AppData\Roamin" to type 'Long' is not valid
and if I put the + sign replacing the joining And world it says illegal Charectors in path and if I put the & sign to join it says Illegal Charectors in path, Please help me as soon as possible. or any better way I can instruct to read the Roaming Folder because my application is installed there when I install it on my computer.

You could change your code to this:

Dim Path As String =
    My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData _
    & "\Roaming\Microsoft\Windows\Start Menu\Programs\"

My.Computer.FileSystem.CopyFile(Path & "The name of my program.exe", _
    Path & "Startup\The name of my program.exe")

Or if your program already works just fine before moving it to the startup folder you could just:

  1. Right-Click on your program
  2. Copy
  3. Go to Startup folder and Right-Click in window
  4. Paste Shortcut

Then whenever your computer starts it will run your program exactly how it is in it's original directory. No need to complicate things more than need be.

Ow thanks but I manage to make it run or automatically start when a computer starts up, I wouldn't be able to use that method you gave me because if I wanted it to automatically run when a computer starts up so the code that I posted I was trying to locate and automatically copy once only the application file to a startup folder because I saw that by putting my applivcation file there on a startup folder it automatically runs it so I was trying to copy the program to a startup folder but I manage to get the right code for register because the program is going to be used by the puplic so it must do this automatically. but thank you for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.