Results 1 to 6 of 6

Thread: Several Questions

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Several Questions

    I have two questions, all replies are helpful :

    1. What is the code to make a file run on startup? I know the directory in the registry but I dont know how to add it.

    2. How do I make a copy of the program? For instance the user downloads to desktop and I promt for them to sace to C:/Program Files.
    Last edited by Steve_F; Jan 26th, 2004 at 02:11 AM.
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782
    No one?
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    1.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
    4. Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    5. Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
    6. Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long
    7. Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    8. Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
    9. Private 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
    10. Private Const REG_SZ = 1                         ' Unicode nul terminated string
    11. Private Const REG_DWORD = 4                      ' 32-bit number
    12. Private Const ERROR_SUCCESS = 0&
    13.  
    14.  
    15. Public Enum pvpHK
    16.     HKEY_CLASSES_ROOT = &H80000000
    17.     HKEY_CURRENT_USER = &H80000001
    18.     HKEY_LOCAL_MACHINE = &H80000002
    19.     HKEY_USERS = &H80000003
    20.     HKEY_PERFORMANCE_DATA = &H80000004
    21. End Enum
    22.  
    23. Private Const pvpRunHKey = "Software\Microsoft\Windows\CurrentVersion\Run"
    24.  
    25.  
    26. Private Sub savestring(ByVal Hkey As Long, strPath As String, strValue As String, strData As String)
    27.     Dim keyhand As Long
    28.     Dim r As Long
    29.     r = RegCreateKey(Hkey, strPath, keyhand)
    30.     r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strData, Len(strData))
    31.     If r = 87 Then
    32.         'Tom streng! -> må slettes
    33.         DeleteValue Hkey, strPath, strValue
    34.     End If
    35.     r = RegCloseKey(keyhand)
    36. End Sub
    37.  
    38. Private Function DeleteValue(ByVal Hkey As Long, ByVal strPath As String, ByVal strValue As String)
    39.     Dim keyhand As Long
    40.     Dim r As Long
    41.     r = RegOpenKey(Hkey, strPath, keyhand)
    42.     r = RegDeleteValue(keyhand, strValue)
    43.     r = RegCloseKey(keyhand)
    44. End Function
    45.  
    46. Public Function RunAtStartup(sAppTitle As String, strsAppName As String)
    47.          savestring pvpHK.HKEY_CURRENT_USER, pvpRunHKey, sAppTitle, sAppName
    48. End Function
    49.  
    50. 'usage
    51. Private Sub Command1_Click()
    52.     RunAtStartup App.Title, App.Path & "\" & App.EXEName & ".EXE"
    53. End Sub



    2.

    don't understand your question, can you elaborate a bit ?
    -= a peet post =-

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    With FileCopy?


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782
    Say the user downloads the file to "C:/Program.exe" I want it so that when the program loads, it checks if Program.exe exists in "C:/Hello" and if it doesn't there is a copy of "C:/Program.exe" put in "C:/Hello". Hope this helps clarify.
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  6. #6
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by Steve_F
    Say the user downloads the file to "C:/Program.exe" I want it so that when the program loads, it checks if Program.exe exists in "C:/Hello" and if it doesn't there is a copy of "C:/Program.exe" put in "C:/Hello". Hope this helps clarify.
    So is the problem detecting if it exists or to copy it? If you want to copy just use FileCopy and specify the 2 paths. If you want to check if it exists look at the codebank... There are several examples for it


    Has someone helped you? Then you can Rate their helpful post.

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