Results 1 to 22 of 22

Thread: VB6, couple questions

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    VB6, couple questions

    Hello,

    1) Can I edit the Windows registery with a visual basic app?
    Make, delete, add, change keys?

    2) How can i write mutiple lines to a textfile?

    Thanks

  2. #2
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: VB6, couple questions

    for the 1st one: yes you can, but you need to use API calls.
    Make a search for "Edit registry" or something like that and you'll find lot of topics.

    For the 2nd one: try opening the file for append instead of output. and then just use the print command.

  3. #3
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: VB6, couple questions

    To save the settings/values in Registry
    VB Code:
    1. SaveSetting App.EXEName, "Options", "Y", Me.Top 'Saves the value of me.top to Y
    To retrieve the settings/values from Registry
    VB Code:
    1. Me.Top = GetSetting(App.EXEName, "Options", "Y")'Retrieves the value of Y
    CS

  4. #4

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: VB6, couple questions

    I have this:

    VB Code:
    1. Dim file As Integer
    2. file = FreeFile
    3. Open "C:\test\test.txt" For Output As #file
    4. Print #file, tekst to write
    5. Close #file

    But when I run it, the textfile only contain 1 empty line

  6. #6
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: VB6, couple questions

    VB Code:
    1. Dim file As Integer
    2. dim Data as String
    3.  
    4. Data = "This is in the textfile" & vbcrlf & "This is line 2 of the file"
    5.  
    6. file = FreeFile
    7. Open "C:\test\test.txt" For Output As #file
    8. Print #file, strData
    9. Close #file
    Chris

  7. #7
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: VB6, couple questions

    you dont need API to edit the registry...
    VB Code:
    1. Set wshshell = CreateObject("WScript.Shell")
    2. wshshell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\YOUR_APP_NAME", App.Path & "\" & App.EXEName & ".exe"
    that will add your app path to the windows run folder

    also you can use RegRead to read the registry
    Chris

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: VB6, couple questions

    And can I delete keys from the registery like that?

  9. #9
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: VB6, couple questions

    Not sure, maybe, but you could write to the key with nothing which will remove its current value, but I dont think thsat would actually delete the key
    Chris

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: VB6, couple questions

    I googled a bit with your code and found this:
    WshShell.RegDelete "HKCU\MyNewKey\"

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: VB6, couple questions

    Be aware that the scripting method is inherently slower and will trigger security alerts from software such as antivirus programs as some malicirous programs use shell scripting. It's convenient, but not advisable.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: VB6, couple questions

    I now use this:
    http://www.vbforums.com/showthread.p...light=registry

    I added a module registery with the script in that topic, to delete values I must use:

    deletevalue ()

    Bur what must i put between ()?

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: VB6, couple questions

    The folowing code won' t work, strPath stays
    c:\WINDOWS\sytem32 but it should be c:\WINDOWS\sytem32\test.txt

    VB Code:
    1. Dim strPath As String
    2. strPath = String(MAX_PATH, 0)
    3. SHGetFolderPath 0&, CSIDL_SYSTEM, 0&, 0&, strPath
    4. strPath = strPatch + "\test.txt"

  14. #14
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: VB6, couple questions

    Quote Originally Posted by penagate
    Be aware that the scripting method is inherently slower and will trigger security alerts from software such as antivirus programs as some malicirous programs use shell scripting. It's convenient, but not advisable.
    Why would you want to hide your activity from anti-virus or firewall software? The app shouldnt really be doing anything unless the user gives it permission, or 'pushes the button' so if the user gets a popup from FW saying xxx is trying to add itself to startup folder they can accept/deny

    It depends what you change in the registry, my firewall alerts me when something tries to edit the software\ms\windows\currentver\run folder, and other system entires, be it via API or shell or even if I do it manually using regedit.exe

    I would go with API if there is a lot of registry editting such as a anti spyware program

    @Martijnc - what are you trying to do in post #13?
    VB Code:
    1. Dim strPath As String
    2. strPath = String(MAX_PATH, 0)
    3. SHGetFolderPath 0&, CSIDL_SYSTEM, 0&, 0&, strPath
    4. strPath = [B]strPatch [/B]+ "\test.txt"
    is that a typo mistake? I think that is the problem
    Chris

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: VB6, couple questions

    Yes that should be:

    VB Code:
    1. Dim strPath As String
    2. strPath = String(MAX_PATH, 0)
    3. SHGetFolderPath 0&, CSIDL_SYSTEM, 0&, 0&, strPath
    4. strPath = strPath + "\test.txt"
    5. MsgBox strPath

    But it still don' t work

  16. #16
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB6, couple questions

    Quote Originally Posted by Martijnc
    Yes that should be:

    VB Code:
    1. Dim strPath As String
    2. strPath = String(MAX_PATH, 0)
    3. SHGetFolderPath 0&, CSIDL_SYSTEM, 0&, 0&, strPath
    4. strPath = strPath + "\test.txt"
    5. MsgBox strPath

    But it still don' t work
    Don't use the + sign unless you want to add a couple of numbers together. Use the & instead
    VB Code:
    1. strPath = strPath & "\test.txt"

  17. #17
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: VB6, couple questions

    Quote Originally Posted by the182guy
    Why would you want to hide your activity from anti-virus or firewall software?
    I never suggested to hide anything. My point is that if you are using the registry legitemately it is annoying for the user to have to confirm it, when there is an alternative option that does not require them to. Also, scripting is unnecessary bloat, all the script does is use the same API functions that you could call yourself anyway, whilst incurring a large overhead at the same time.

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: VB6, couple questions

    Nope doesn' t work

    But already thanks for the help

  19. #19
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB6, couple questions

    Quote Originally Posted by Martijnc
    Nope doesn' t work

    But already thanks for the help
    Is this for penagate or me?

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: VB6, couple questions

    Quote Originally Posted by Hack
    Is this for penagate or me?
    For you

  21. #21
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB6, couple questions

    Quote Originally Posted by Martijnc
    For you
    It worked just fine for me.

    What is the contents of strPath? (I know what you said what it is supposed to be but what really is there?)

    Do this
    VB Code:
    1. Dim strPath As String
    2. strPath = String(MAX_PATH, 0)
    3. Msgbox strPath
    4. SHGetFolderPath 0&, CSIDL_SYSTEM, 0&, 0&, strPath
    5. MsgBox strPath
    6. strPath = strPath & "\test.txt"
    7. MsgBox strPath

  22. #22

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: VB6, couple questions

    Hello,

    The first msgbox was empty, the second contain 'c:\WINDOWS\system32' and the third 'c:\WINDOWS\system32'

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