-
Apr 8th, 2006, 02:50 PM
#1
Thread Starter
Junior Member
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
-
Apr 8th, 2006, 04:22 PM
#2
Hyperactive Member
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.
-
Apr 8th, 2006, 08:42 PM
#3
Re: VB6, couple questions
To save the settings/values in Registry
VB Code:
SaveSetting App.EXEName, "Options", "Y", Me.Top 'Saves the value of me.top to Y
To retrieve the settings/values from Registry
VB Code:
Me.Top = GetSetting(App.EXEName, "Options", "Y")'Retrieves the value of Y
-
Apr 8th, 2006, 08:52 PM
#4
Re: VB6, couple questions
-
Apr 9th, 2006, 06:25 AM
#5
Thread Starter
Junior Member
Re: VB6, couple questions
I have this:
VB Code:
Dim file As Integer
file = FreeFile
Open "C:\test\test.txt" For Output As #file
Print #file, tekst to write
Close #file
But when I run it, the textfile only contain 1 empty line
-
Apr 9th, 2006, 06:29 AM
#6
Re: VB6, couple questions
VB Code:
Dim file As Integer
dim Data as String
Data = "This is in the textfile" & vbcrlf & "This is line 2 of the file"
file = FreeFile
Open "C:\test\test.txt" For Output As #file
Print #file, strData
Close #file
-
Apr 9th, 2006, 06:34 AM
#7
Re: VB6, couple questions
you dont need API to edit the registry...
VB Code:
Set wshshell = CreateObject("WScript.Shell")
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
-
Apr 9th, 2006, 06:37 AM
#8
Thread Starter
Junior Member
Re: VB6, couple questions
And can I delete keys from the registery like that?
-
Apr 9th, 2006, 06:40 AM
#9
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
-
Apr 9th, 2006, 06:45 AM
#10
Thread Starter
Junior Member
Re: VB6, couple questions
I googled a bit with your code and found this:
WshShell.RegDelete "HKCU\MyNewKey\"
-
Apr 9th, 2006, 06:46 AM
#11
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.
-
Apr 9th, 2006, 07:04 AM
#12
Thread Starter
Junior Member
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 ()?
-
Apr 9th, 2006, 01:31 PM
#13
Thread Starter
Junior Member
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:
Dim strPath As String
strPath = String(MAX_PATH, 0)
SHGetFolderPath 0&, CSIDL_SYSTEM, 0&, 0&, strPath
strPath = strPatch + "\test.txt"
-
Apr 10th, 2006, 08:07 AM
#14
Re: VB6, couple questions
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:
Dim strPath As String
strPath = String(MAX_PATH, 0)
SHGetFolderPath 0&, CSIDL_SYSTEM, 0&, 0&, strPath
strPath = [B]strPatch [/B]+ "\test.txt"
is that a typo mistake? I think that is the problem
-
Apr 10th, 2006, 08:25 AM
#15
Thread Starter
Junior Member
Re: VB6, couple questions
Yes that should be:
VB Code:
Dim strPath As String
strPath = String(MAX_PATH, 0)
SHGetFolderPath 0&, CSIDL_SYSTEM, 0&, 0&, strPath
strPath = strPath + "\test.txt"
MsgBox strPath
But it still don' t work
-
Apr 10th, 2006, 08:29 AM
#16
Re: VB6, couple questions
Originally Posted by Martijnc
Yes that should be:
VB Code:
Dim strPath As String
strPath = String(MAX_PATH, 0)
SHGetFolderPath 0&, CSIDL_SYSTEM, 0&, 0&, strPath
strPath = strPath + "\test.txt"
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:
strPath = strPath & "\test.txt"
-
Apr 10th, 2006, 08:33 AM
#17
Re: VB6, couple questions
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.
-
Apr 10th, 2006, 08:42 AM
#18
Thread Starter
Junior Member
Re: VB6, couple questions
Nope doesn' t work
But already thanks for the help
-
Apr 10th, 2006, 08:49 AM
#19
Re: VB6, couple questions
Originally Posted by Martijnc
Nope doesn' t work
But already thanks for the help
Is this for penagate or me?
-
Apr 10th, 2006, 08:51 AM
#20
Thread Starter
Junior Member
Re: VB6, couple questions
Originally Posted by Hack
Is this for penagate or me?
For you
-
Apr 10th, 2006, 08:54 AM
#21
Re: VB6, couple questions
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:
Dim strPath As String
strPath = String(MAX_PATH, 0)
Msgbox strPath
SHGetFolderPath 0&, CSIDL_SYSTEM, 0&, 0&, strPath
MsgBox strPath
strPath = strPath & "\test.txt"
MsgBox strPath
-
Apr 10th, 2006, 09:05 AM
#22
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|