HOW TO MAKE MY PROJECT RUN WHILE EVERY TIME WINDOWS START ?
SHALL I NEED TO WRITE INTO WIN.INI FILE?
HOW TO DO IT?
BESIDES I WOULD LIKE TO HIDE MY PROJECT AS A ICON IN SYSYRAY. HOW TO DO THAT?
ANYONE KNOWS, PLEASE SHOW ME THE CODE .....
:) :P :) :P
Printable View
HOW TO MAKE MY PROJECT RUN WHILE EVERY TIME WINDOWS START ?
SHALL I NEED TO WRITE INTO WIN.INI FILE?
HOW TO DO IT?
BESIDES I WOULD LIKE TO HIDE MY PROJECT AS A ICON IN SYSYRAY. HOW TO DO THAT?
ANYONE KNOWS, PLEASE SHOW ME THE CODE .....
:) :P :) :P
just put a short cut to your program in your windows startup folder.
Scoutt
Or update the windows registry so that the
HKEY_LOCAL_MACHINE\software\Microsoft\Windows\CurrentVersion\Run
contains an entry for your program.
SD
To minimize it to the system tray go here,
http://www.vbsquare.com/tips/tip178.html
Then how to add in my application registry in that?
i mean by vb?please show me the code....
:)
so you want the code to make your program run everytime windows starts... just make it create a shortcut to your program in the startup folder or if it already exists it does nothing.
I really don't know how to make shortcut using VB?
anyone teach me??
i am so stupid...........
nah ya aint stupid... just learning... and to be honest i dont know how to do shortcuts in vb either... thats why i didnt write the code... does anyone know how to make a shortcut from a command line... as then you could just call it with shell.
ok lets d othe registry bit that seems a bit easier... what would your program be called... when the program loads this will check to see if your program is being run on startup if it isnt it will make it run on startup...
Code:Private Sub Form_Load()
Dim ppath As String
Dim rpath As String
Dim intvalue As Integer
ppath = App.Path & App.EXEName
rpath = "HKEY_LOCAL_MACHINE\software\Microsoft\Windows\CurrentVersion\"
intvalue = GetSetting(rpath, "run", "Program Name", ppath)
End Sub
Finally u have lerned how to do?
haha...
thanks....>
you are down to earth person lah.....
:) :) :) :) :) :)
Does it work though?... i wrote this code without testing it...
Not Yet testing but will test soon....
just thanks for your coding first........
:) :) :) :) :D :D :D ;) ;) ;) :o :o :o :( :( :( :p :p :p :rolleyes: :cool: :eek: :confused: :mad:
I'm pretty sure it doesn't work... :(Quote:
Originally posted by Neronis2000
Does it work though?... i wrote this code without testing it...
Ways to do what you want:
Method 1:
Using the OSfCreateShellLink API
This example would create a shortcut to "C:\hello.exe", in the Start Menu's Startup folder, with a caption of "Hello"Code:'In a module
Option Explicit
Option Base 1
Public Declare Function OSfCreateShellLink Lib "vb6stkit.dll" Alias "fCreateShellLink" _
(ByVal lpstrFolderName As String, _
ByVal lpstrLinkName As String, _
ByVal lpstrLinkPath As String, _
ByVal lpstrLinkArguments As String, _
ByVal fPrivate As Long, _
ByVal sParent As String) As Long
Public Const gstrQUOTE$ = """"
Public Sub CreateShellLink(ByVal strLinkPath As String, _
ByVal strGroupName As String, _
ByVal strLinkArguments As String, _
ByVal strLinkName As String, _
ByVal fPrivate As Boolean, _
sParent As String, _
Optional ByVal fLog As Boolean = True)
Dim fSuccess As Boolean
Dim intMsgRet As Integer
Dim lREt As Boolean
strLinkName = strUnQuoteString(strLinkName)
strLinkPath = strUnQuoteString(strLinkPath)
If StrPtr(strLinkArguments) = 0 Then strLinkArguments = ""
lREt = OSfCreateShellLink(strGroupName, strLinkName, strLinkPath, strLinkArguments, _
fPrivate, sParent) 'the path should never be enclosed in double quotes
End Sub
Public Function strUnQuoteString(ByVal strQuotedString As String)
'
' This routine tests to see if strQuotedString is wrapped in quotation
' marks, and, if so, remove them.
'
strQuotedString = Trim$(strQuotedString)
If Mid$(strQuotedString, 1, 1) = gstrQUOTE Then
If Right$(strQuotedString, 1) = gstrQUOTE Then
'
' It's quoted. Get rid of the quotes.
'
strQuotedString = Mid$(strQuotedString, 2, Len(strQuotedString) - 2)
End If
End If
strUnQuoteString = strQuotedString
End Function
'On a form
On Error GoTo EH
CreateShellLink "c:\hello.exe", "Startup", , "Hello", True, "$(Programs)"
'CreateShellLink strProgramPath, strGroup, strProgramArgs, strProgramIconTitle, True, sParent
Exit Sub
EH:
MsgBox Err.Description
Exit Sub
Method 2:
Using the registry
You can manipulate the last 2 variables, but you will not achieve the result you want unless you leave the rest :)Code:
'In a module
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_DYN_DATA = &H80000006
Public Const REG_SZ = 1 'Unicode nul terminated string
Public Const REG_BINARY = 3 'Free form binary
Public Const REG_DWORD = 4 '32-bit number
Public Const ERROR_SUCCESS = 0&
Public Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Public Declare Function RegCreateKey Lib "advapi32.dll" _
Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey _
As String, phkResult As Long) As Long
Public Declare Function RegSetValueEx Lib "advapi32.dll" _
Alias "RegSetValueExA" (ByVal hKey As Long, ByVal _
lpValueName As String, ByVal Reserved As Long, ByVal _
dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Public Sub SaveSettingString(hKey As Long, strPath _
As String, strValue As String, strData As String)
Dim hCurKey As Long
Dim lRegResult As Long
lRegResult = RegCreateKey(hKey, strPath, hCurKey)
lRegResult = RegSetValueEx(hCurKey, strValue, 0, REG_SZ, _
ByVal strData, Len(strData))
If lRegResult <> ERROR_SUCCESS Then
'there is a problem
End If
lRegResult = RegCloseKey(hCurKey)
End Sub
'In a sub
SaveSettingString HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", "MyProg", "c:\myprog.exe"
Replace c:\myprog.exe with the path to your program or you can use:
I would recommend using the registry as the user cannot as easily manipulate it :)Code:Dim ProgPath As String, ProgTitle As String
ProgPath = App.Path & "\" & App.EXEName & ".exe"
ProgTitle = App.Title
SaveSettingString HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", ProgTitle, ProgPath
Yeah i knew there was more to it... just didnt know what it was...
Yeah, You need the code from the Registry Tutorial for that i think ;)
Yeah i grabbed that code from the msdn help file... i knew you would have to make reference or call something but msdn said nuthing about it so i just sent the code.. which is why i said that i wasnt sure if it would work.
I'm an Aussie too :)
a bit off the subject but anyway :p
The msdn can be a bit dodgy at times i have found :(
Yeah which part of australia are ya in (you already know where i am, <=).
Yeah i dont like msdn that much... do u remember, or ever known about the help program that came with vb5... it was Visual Books or something... i really liked that program... really helpful but i dont think they made one for vb6 :(
Even furthur off the subject now, do u know any CGI?
no not really
i don't do cgi, asp is better :)
Too bad
Sorry we were so close to 20 posts i just felt i had to tip it over :D
Ok were there now.... hehe :p
That's good
He hasn't even replied for all the effort i put into my post :(
Im sure he is busy implementing it all... You gave him alot of code to play with!
da_silvy:
your complicated code has been confusing me.... :P no offence
anyway, i also trying to test you code.i am intent ti listen to your suggestion. so i would like to use method to to savechanges for my registry for the application shortcut.
i am trying to arrange you code back into my vb,therefore take some time to finish.Last, i want to asked a dummy question.
(sorry i am just a stupid beginner~) :) :P
if my program name Keycode Tracker and the path is "c:\windows\desktop\keycode tracker.exe"
then which variable i need to change??
Shall i change like this?
Private Sub Command1_Click()
Dim ProgPath As String, ProgTitle As String
ProgPath = App.Path & "\" & App.EXEName & ".exe"
ProgTitle = App.Title
SaveSettingString HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run","Keycode Tracker","c:\windows\desktop\keycode tracker.exe"
End Sub
and where shall i put this in?in my form or module?
'In a sub
SaveSettingString HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", "MyProg", "c:\myprog.exe"
first you need to keep the ProgPath and ProgTitle in the code, (bold)
they are already setup to get the path and file name. As far as I know this code is in your Form under Command_Click()Code:Private Sub Command1_Click()
Dim ProgPath As String, ProgTitle As String
ProgPath = App.Path & "\" & App.EXEName & ".exe"
ProgTitle = App.Title
SaveSettingString HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run","ProgTitle","ProgPath"
Scoutt
ergh you dont need to change prog path and the likes all those app things are automatic... this way it will enter the correct data regardless on where it is kept in the system... this probably just confused you more :)
Basicly stick all that code into a module and then just stick the code that runs the reg check into form_load... then you should be set...
What i need to say is this really a significant vb forum that i haven't seen before. it really help me a lot and efficiently to undesrtand vb.
This is the first time i have seen my topic has been viewed more than dozen time and get more than 20 replies, i am so glad , and this show that they still many ppl here around to help ppl and care for others.
Anyway, i really appreciate it.
NICE TO MEET YOU ALL.
:D :) :p :D :) :p :D :) :p :D :) :p :D :) :p :D :) :p :D :) :p :D :) :p