Results 1 to 28 of 28

Thread: How To Make My Project Run While Every Time Windows Start ?

  1. #1

    Thread Starter
    Lively Member Satangel's Avatar
    Join Date
    Aug 2000
    Location
    KL,Malaysia
    Posts
    85

    Wink How To Make My Project Run While Every Time Windows Start ?

    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

  2. #2
    scoutt
    Guest
    just put a short cut to your program in your windows startup folder.

    Scoutt

  3. #3
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    Calgary, Canada
    Posts
    453
    Or update the windows registry so that the

    HKEY_LOCAL_MACHINE\software\Microsoft\Windows\CurrentVersion\Run

    contains an entry for your program.

    SD
    "I'd rather have a full bottle in front of me than a full frontal lobotomy!"

  4. #4
    Lively Member
    Join Date
    Jan 2001
    Location
    Perth, Western Australia
    Posts
    108
    To minimize it to the system tray go here,

    http://www.vbsquare.com/tips/tip178.html

  5. #5

    Thread Starter
    Lively Member Satangel's Avatar
    Join Date
    Aug 2000
    Location
    KL,Malaysia
    Posts
    85

    Question Reply

    Then how to add in my application registry in that?

    i mean by vb?please show me the code....


  6. #6
    Lively Member
    Join Date
    Jan 2001
    Location
    Perth, Western Australia
    Posts
    108
    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.

  7. #7

    Thread Starter
    Lively Member Satangel's Avatar
    Join Date
    Aug 2000
    Location
    KL,Malaysia
    Posts
    85

    Unhappy

    I really don't know how to make shortcut using VB?
    anyone teach me??
    i am so stupid...........

  8. #8
    Lively Member
    Join Date
    Jan 2001
    Location
    Perth, Western Australia
    Posts
    108
    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.

  9. #9
    Lively Member
    Join Date
    Jan 2001
    Location
    Perth, Western Australia
    Posts
    108
    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

  10. #10

    Thread Starter
    Lively Member Satangel's Avatar
    Join Date
    Aug 2000
    Location
    KL,Malaysia
    Posts
    85

    Talking

    Finally u have lerned how to do?
    haha...
    thanks....>
    you are down to earth person lah.....

  11. #11
    Lively Member
    Join Date
    Jan 2001
    Location
    Perth, Western Australia
    Posts
    108
    Does it work though?... i wrote this code without testing it...

  12. #12

    Thread Starter
    Lively Member Satangel's Avatar
    Join Date
    Aug 2000
    Location
    KL,Malaysia
    Posts
    85

    Talking

    Not Yet testing but will test soon....
    just thanks for your coding first........

  13. #13
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Originally posted by Neronis2000
    Does it work though?... i wrote this code without testing it...
    I'm pretty sure it doesn't work...

    Ways to do what you want:

    Method 1:

    Using the OSfCreateShellLink API

    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
    This example would create a shortcut to "C:\hello.exe", in the Start Menu's Startup folder, with a caption of "Hello"

    Method 2:

    Using the registry

    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"
    You can manipulate the last 2 variables, but you will not achieve the result you want unless you leave the rest

    Replace c:\myprog.exe with the path to your program or you can use:

    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
    I would recommend using the registry as the user cannot as easily manipulate it

  14. #14
    Lively Member
    Join Date
    Jan 2001
    Location
    Perth, Western Australia
    Posts
    108
    Yeah i knew there was more to it... just didnt know what it was...

  15. #15
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Yeah, You need the code from the Registry Tutorial for that i think

  16. #16
    Lively Member
    Join Date
    Jan 2001
    Location
    Perth, Western Australia
    Posts
    108
    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.

  17. #17
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    I'm an Aussie too

    a bit off the subject but anyway

    The msdn can be a bit dodgy at times i have found

  18. #18
    Lively Member
    Join Date
    Jan 2001
    Location
    Perth, Western Australia
    Posts
    108
    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?

  19. #19
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    no not really

    i don't do cgi, asp is better

  20. #20
    Lively Member
    Join Date
    Jan 2001
    Location
    Perth, Western Australia
    Posts
    108
    Too bad

  21. #21
    Lively Member
    Join Date
    Jan 2001
    Location
    Perth, Western Australia
    Posts
    108
    Sorry we were so close to 20 posts i just felt i had to tip it over

  22. #22
    Lively Member
    Join Date
    Jan 2001
    Location
    Perth, Western Australia
    Posts
    108
    Ok were there now.... hehe

  23. #23
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    That's good


    He hasn't even replied for all the effort i put into my post

  24. #24
    Lively Member
    Join Date
    Jan 2001
    Location
    Perth, Western Australia
    Posts
    108
    Im sure he is busy implementing it all... You gave him alot of code to play with!

  25. #25

    Thread Starter
    Lively Member Satangel's Avatar
    Join Date
    Aug 2000
    Location
    KL,Malaysia
    Posts
    85

    Unhappy Sorry~~

    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"

  26. #26
    scoutt
    Guest
    first you need to keep the ProgPath and ProgTitle in the code, (bold)

    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"
    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()

    Scoutt

  27. #27
    Lively Member
    Join Date
    Jan 2001
    Location
    Perth, Western Australia
    Posts
    108
    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...

  28. #28

    Thread Starter
    Lively Member Satangel's Avatar
    Join Date
    Aug 2000
    Location
    KL,Malaysia
    Posts
    85

    I haven't post a topic like this b4, it's more than 20 replies~ Wooh

    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.



    Last edited by Satangel; Apr 29th, 2001 at 08:27 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width