Page 1 of 2 12 LastLast
Results 1 to 40 of 52

Thread: create/save txt to notepad.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Resolved create/save txt to notepad.

    How do I createor save txt from like a textbox text to a notepad.txt with or withought openning it (if you can give me both ^.^ I Searched all over this forum, and didn't find anything like this question, if there is one, please give me the link. Thanks~

    (idk if I not make sence is sentence, just really baked)
    Last edited by Snow420; Dec 20th, 2005 at 12:33 PM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: create/save txt to notepad.

    Welcome to the forums!

    Try the FAQ forum:

    http://www.vbforums.com/showthread.php?t=348141#file

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

    Re: create/save txt to notepad.

    Quote Originally Posted by Snow420
    How do I createor save txt from like a textbox text to a notepad.txt with or withought openning it
    You can't. It is actually pretty simple, but if you are going to save the contents of a textbox to Notepad, you have to open Notepad to do it.

  4. #4
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: create/save txt to notepad.

    do you mean save what you place in a text box to a text file? if so try this

    VB Code:
    1. dim b as integer
    2. b=freefile
    3. open app.path & /save.txt for output as #b
    4. print #b,text1.text

  5. #5
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346

    Re: create/save txt to notepad.

    @ DarkShadow... just to make a few changes to your code....

    VB Code:
    1. dim b as integer
    2. b=freefile
    3. open app.path & "\save.txt" for output as #b
    4. print #b,text1.text
    5. close #b

    And to open it from VB in note pad use the Shell function...

    VB Code:
    1. Shell "notepad.exe " & app.path & "\save.txt"
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  6. #6
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: create/save txt to notepad.

    lol oops forgot to add those nice catch

  7. #7
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346

    Re: create/save txt to notepad.

    No biggie...

    And to add as an important note to all the newbies... when you open file to write, make sure and close it afterwards, cause I've noticed that sometimes windows would not allow you to delete the file and they would tell you that it is already in use...

    And easy way to bypass this 90% of the time is to just open up vb and use the simple Kill statement... apparently that deletes the file (even DOS Del command refuses to)....
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  8. #8
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: create/save txt to notepad.

    hmmm i've never tried to use the kill statment to do that i'll give it a try at home

  9. #9
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: create/save txt to notepad.

    Quote Originally Posted by Protocol
    And to add as an important note to all the newbies... when you open file to write, make sure and close it afterwards, cause I've noticed that sometimes windows would not allow you to delete the file and they would tell you that it is already in use...
    I have seen this problem only in Win98. I've found that, in Win2K/XP, windows releases the file as soon as the process, that created it, gets destroyed. Not 100% sure though.

    Quote Originally Posted by Protocol
    And easy way to bypass this 90% of the time is to just open up vb and use the simple Kill statement... apparently that deletes the file (even DOS Del command refuses to)....
    Nice idea. I'll try it when in 9x.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  10. #10

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    Wow, Thanks. I got it working perfectly Now, I'll try to discover on my own how to make it so when I redo it, it doesn't erase my old entry. This forum is very quick and helpful, Thanks Again~

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

    Re: create/save txt to notepad.

    Quote Originally Posted by Snow420
    Wow, Thanks. I got it working perfectly Now, I'll try to discover on my own how to make it so when I redo it, it doesn't erase my old entry. This forum is very quick and helpful, Thanks Again~
    Use Append instead of Output and your new entry will just be added to your old.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    haha, thanks. You guys are soo fast.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    inkey$ is to Qbasic, As ???? is to VB?

    Also, where would I put my statement so I can keydown or w/e. at any time? and it will work?

    I am full of questions, I checked out how to see if a file exsits, but if it doesn't is there a way to create a .txt file?
    Last edited by Snow420; Dec 20th, 2005 at 12:44 PM.

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

    Re: create/save txt to notepad.

    Quote Originally Posted by Snow420
    inkey$ is to Qbasic, As ???? is to VB?
    No clue. What does inkey do?
    Quote Originally Posted by Snow420
    Also, where would I put my statement so I can keydown or w/e. at any time? and it will work?
    Gut reaction would be the keypress event of a control, such as a text box[quote=Snow420]I checked out how to see if a file exsits, but if it doesn't is there a way to create a .txt file
    VB Code:
    1. Private Sub Command1_Click()
    2. If Dir$("c:\Snow420.txt") = vbNullString Then
    3.    'file does not exist
    4.    Open "c:\Snow420.txt" For Append As #1
    5.    'do stuff
    6.    Close #1
    7. End If
    8. End Sub

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    oh and the inkey$ is like this.
    if inkey$ = " " then do something

    and when ever I press space bar, it does something.

    so the open command will create one?

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

    Re: create/save txt to notepad.

    Quote Originally Posted by Snow420
    so the open command will create one?
    Yes.

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    I don't want to flood this Forum, Do you have MSN?

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

    Re: create/save txt to notepad.

    Quote Originally Posted by Snow420
    I don't want to flood this Forum, Do you have MSN?
    First and foremost, That is why this forum exists. People ask questions. Other people answer them.

    Second and secondmost I don't answer questions in PMs, Emails on any other form of communcation except in the open, where everyone can read it, on this forum.

    If you have another question related to this topic, then please post it.

    If you have any question on a different topic, then create a new thread for that question.

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    Well, must I make a new thread, on the question about inkey$?

    "the inkey$ is like this.
    if inkey$ = " " then do something

    and when ever I press space bar, it does something."

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

    Re: create/save txt to notepad.

    Quote Originally Posted by Snow420
    Well, must I make a new thread, on the question about inkey$?

    "the inkey$ is like this.
    if inkey$ = " " then do something

    and when ever I press space bar, it does something."
    That would depend on where you pressed it. I'll give example using a textbox
    VB Code:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2. If KeyAscii = vbKeyBack Then 'backspace key
    3.    'do something
    4. End If
    5. End Sub
    Is this what you mean?

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    That's good, but I want it where at any time, even if the program is not select (like it's behind another program) and I press backspace, it will still detect it, and do sometihng.

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

    Re: create/save txt to notepad.

    Quote Originally Posted by Snow420
    That's good, but I want it where at any time, even if the program is not select (like it's behind another program) and I press backspace, it will still detect it, and do sometihng.
    No event on a form will fire unless the form has focus. If it is hidden behind something else, and that something else is the active window, the application will just sit there.

    What is your goal for this?

  23. #23
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: create/save txt to notepad.

    That was the DOS world. Now there are many programs runnng, and any one of them could have focus. What are you trying to do? There might be a Windows method to do what you want.

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

    Re: create/save txt to notepad.

    Quote Originally Posted by Snow420
    I want it invisible, then when I click a certain key combo, it comes visible again /gg
    Then I would suggest you create a system wide Hotkey

  25. #25

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    Well that seems way too complicated, Maybe I don't need it to come visible, What about Closing it? Like if I go to 'run' and type in sometihng, it will close the .exe? is there anything like that? and how do I make it load on start-up?

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

    Re: create/save txt to notepad.

    Quote Originally Posted by Snow420
    Well that seems way too complicated, Maybe I don't need it to come visible, What about Closing it? Like if I go to 'run' and type in sometihng, it will close the .exe?
    No...there is nothing you can type into the Run dialog box that will close it. (At least nothing I'm aware of)
    Quote Originally Posted by Snow420
    and how do I make it load on start-up?
    You would need to place your .Exe's name in this registry key
    Code:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

  27. #27

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    key
    Code:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
    How do I do this ^.~?
    Can I make it to it, when I run the program like in form1_load?

    Also, how do I make it not show up in the task manager?
    Last edited by Snow420; Dec 20th, 2005 at 01:50 PM.

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

    Re: create/save txt to notepad.

    Quote Originally Posted by Snow420
    How do I do this ^.~?
    Can I make it to it, when I run the program like in form1_load?
    Here is an example
    VB Code:
    1. 'in a module
    2. Public Type SECURITY_ATTRIBUTES
    3. nLength As Long
    4. lpSecurityDescriptor As Long
    5. bInheritHandle As Long
    6. End Type
    7.  
    8. Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
    9. (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
    10. ByVal samDesired As Long, phkResult As Long) As Long
    11. Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    12. Public Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" _
    13. (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As _
    14. Long, ByRef lpType As Long, ByVal lpData As String, ByRef lpcbData As Long) As Long
    15. Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal _
    16. hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal _
    17. dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
    18. Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" _
    19. (ByVal hKey As Long, ByVal lpValueName As String) As Long
    20.  
    21. Public Enum T_KeyClasses
    22. HKEY_CLASSES_ROOT = &H80000000
    23. HKEY_CURRENT_CONFIG = &H80000005
    24. HKEY_CURRENT_USER = &H80000001
    25. HKEY_LOCAL_MACHINE = &H80000002
    26. HKEY_USERS = &H80000003
    27. End Enum
    28.  
    29. Public Const SYNCHRONIZE = &H100000
    30. Public Const STANDARD_RIGHTS_ALL = &H1F0000
    31. Public Const KEY_QUERY_VALUE = &H1
    32. Public Const KEY_SET_VALUE = &H2
    33. Public Const KEY_CREATE_LINK = &H20
    34. Public Const KEY_CREATE_SUB_KEY = &H4
    35. Public Const KEY_ENUMERATE_SUB_KEYS = &H8
    36. Public Const KEY_EVENT = &H1
    37. Public Const KEY_NOTIFY = &H10
    38. Public Const READ_CONTROL = &H20000
    39. Public Const STANDARD_RIGHTS_READ = (READ_CONTROL)
    40. Public Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
    41. Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or _
    42. KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY _
    43. Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) _
    44. And (Not SYNCHRONIZE))
    45. Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or _
    46. KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) _
    47. And (Not SYNCHRONIZE))
    48. Public Const KEY_EXECUTE = (KEY_READ)
    49. Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or _
    50. KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
    51. Public Const REG_BINARY = 3
    52. Public Const REG_CREATED_NEW_KEY = &H1
    53. Public Const REG_DWORD = 4
    54. Public Const REG_DWORD_BIG_ENDIAN = 5
    55. Public Const REG_DWORD_LITTLE_ENDIAN = 4
    56. Public Const REG_EXPAND_SZ = 2
    57. Public Const REG_FULL_RESOURCE_DESCRIPTOR = 9
    58. Public Const REG_LINK = 6
    59. Public Const REG_MULTI_SZ = 7
    60. Public Const REG_NONE = 0
    61. Public Const REG_SZ = 1
    62. Public Const REG_NOTIFY_CHANGE_ATTRIBUTES = &H2
    63. Public Const REG_NOTIFY_CHANGE_LAST_SET = &H4
    64. Public Const REG_NOTIFY_CHANGE_NAME = &H1
    65. Public Const REG_NOTIFY_CHANGE_SECURITY = &H8
    66. Public Const REG_OPTION_BACKUP_RESTORE = 4
    67. Public Const REG_OPTION_CREATE_LINK = 2
    68. Public Const REG_OPTION_NON_VOLATILE = 0
    69. Public Const REG_OPTION_RESERVED = 0
    70. Public Const REG_OPTION_VOLATILE = 1
    71. Public Const REG_LEGAL_CHANGE_FILTER = (REG_NOTIFY_CHANGE_NAME _
    72. Or REG_NOTIFY_CHANGE_ATTRIBUTES Or _
    73. REG_NOTIFY_CHANGE_LAST_SET Or _
    74. REG_NOTIFY_CHANGE_SECURITY)
    75. Public Const REG_LEGAL_OPTION = (REG_OPTION_RESERVED Or _
    76. REG_OPTION_NON_VOLATILE Or REG_OPTION_VOLATILE Or _
    77. REG_OPTION_CREATE_LINK Or REG_OPTION_BACKUP_RESTORE)
    78.  
    79. Public Sub DeleteValue(rClass As T_KeyClasses, Path As String, sKey As String)
    80. Dim hKey As Long
    81. Dim res As Long
    82. res = RegOpenKeyEx(rClass, Path, 0, KEY_ALL_ACCESS, hKey)
    83. res = RegDeleteValue(hKey, sKey)
    84. RegCloseKey hKey
    85. End Sub
    86.  
    87. Public Function SetRegValue(KeyRoot As T_KeyClasses, Path As String, sKey As _
    88. String, NewValue As String) As Boolean
    89. Dim hKey As Long
    90. Dim KeyValType As Long
    91. Dim KeyValSize As Long
    92. Dim KeyVal As String
    93. Dim tmpVal As String
    94. Dim res As Long
    95. Dim i As Integer
    96. Dim x As Long
    97. res = RegOpenKeyEx(KeyRoot, Path, 0, KEY_ALL_ACCESS, hKey)
    98. If res <> 0 Then GoTo Errore
    99. tmpVal = String(1024, 0)
    100. KeyValSize = 1024
    101. res = RegQueryValueEx(hKey, sKey, 0, KeyValType, tmpVal, KeyValSize)
    102. Select Case res
    103. Case 2
    104. KeyValType = REG_SZ
    105. Case Is <> 0
    106. GoTo Errore
    107. End Select
    108. Select Case KeyValType
    109. Case REG_SZ
    110. tmpVal = NewValue
    111. Case REG_DWORD
    112. x = Val(NewValue)
    113. tmpVal = ""
    114. For i = 0 To 3
    115. tmpVal = tmpVal & Chr(x Mod 256)
    116. x = x \ 256
    117. Next
    118. End Select
    119. KeyValSize = Len(tmpVal)
    120. res = RegSetValueEx(hKey, sKey, 0, KeyValType, tmpVal, KeyValSize)
    121. If res <> 0 Then GoTo Errore
    122. SetRegValue = True
    123. RegCloseKey hKey
    124. Exit Function
    125. Errore:
    126. SetRegValue = False
    127. RegCloseKey hKey
    128. End Function
    129.  
    130. 'Insert the following code to your form:
    131. Private Sub Command1_Click()
    132. 'Replace the two 'NotePad' below with your application name, and the two
    133. 'c:\windows\notepad.exe' below with your application file.
    134. SetRegValue HKEY_LOCAL_MACHINE, _
    135. "Software\Microsoft\Windows\CurrentVersion\Run", "NotePad", "c:\windows\notepad.exe"
    136. End Sub
    Why don't you want it to show up in Task Manager?

  29. #29

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    so where does the big function go? And can I make it instead of command1_click to form1_load?

    And I was searching a bit, does this work?

    Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)

    and would Productname = my blah.exe name? and the executablePath = c:\blahblah\blah\blah.exe?

    (lol blah isn't the exe's name haha.)

    I don't want it to show up in Applications, but it can show up in processes.

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

    Re: create/save txt to notepad.

    Quote Originally Posted by Snow420
    so where does the big function go? And can I make it instead of command1_click to form1_load?
    If you put it in form load, which you certainly can, then this will make the exact same registry write every single time your application is launched. That seems like a waste for something you only need to do once.

    I would make it an option, and put it under a menu.

  31. #31

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    In my instance, it's better to make it happen every time, But where do I put all the function stuff? I tried putting it in form1_load and half of it went red.

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

    Re: create/save txt to notepad.

    Quote Originally Posted by Snow420
    In my instance, it's better to make it happen every time, But where do I put all the function stuff? I tried putting it in form1_load and half of it went red.
    *smile* Yes, I'm certain it did.

    If you see something declared Public, then typically, it will go in a module.

    If you don't have a module with your application, then change all of the Publics to Privates and put it on the form itself.

    Everything, except the code in the command button click (or Form Load) goes in the General Declarations section of either your form (as Private) or your module (as Public)

  33. #33

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    thank you, again I am very noob, I have added the stuff to the module, but do i have to put it anywhere like
    form1_load
    module1
    end sub
    ??

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

    Re: create/save txt to notepad.

    You add code to a module, or the declaration section of your form, then then call it from a Form.

    The only thing you need in your form is
    VB Code:
    1. Private Sub Form_Load()
    2. SetRegValue HKEY_LOCAL_MACHINE, _
    3. "Software\Microsoft\Windows\CurrentVersion\Run", "NotePad", "c:\windows\notepad.exe"
    4. End Sub
    Where the .exe is the name of your program.

  35. #35
    Banned
    Join Date
    Dec 2005
    Location
    india
    Posts
    35

    Re: create/save txt to notepad.

    started from textboxes to notepad and ended up in registry games i think snow is planning to write a keylogger (all that hiding stuff) to trap passwords am i right snow 420

  36. #36

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    well, looks like I'm not allowed to ask about keyloggers, lol I did a little search and I hear bad things >_> sorry for not tellingyou earlier... (I sdidn't know I wasn't allowed to)

  37. #37
    Banned
    Join Date
    Dec 2005
    Location
    india
    Posts
    35

    Re: create/save txt to notepad.

    i have a similar story but i got the admin password by cracking the sam file .anyway happy coding
    p.s:we joined the forum on the same day

  38. #38
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: create/save txt to notepad.

    Quote Originally Posted by Hack
    Here is an example
    VB Code:
    1. 'in a module
    2. Public Type SECURITY_ATTRIBUTES
    3. nLength As Long
    4. lpSecurityDescriptor As Long
    5. bInheritHandle As Long
    6. End Type
    7.  
    8. Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
    9. (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
    10. ByVal samDesired As Long, phkResult As Long) As Long
    11. Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    12. Public Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" _
    13. (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As _
    14. Long, ByRef lpType As Long, ByVal lpData As String, ByRef lpcbData As Long) As Long
    15. Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal _
    16. hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal _
    17. dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
    18. Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" _
    19. (ByVal hKey As Long, ByVal lpValueName As String) As Long
    20.  
    21. Public Enum T_KeyClasses
    22. HKEY_CLASSES_ROOT = &H80000000
    23. HKEY_CURRENT_CONFIG = &H80000005
    24. HKEY_CURRENT_USER = &H80000001
    25. HKEY_LOCAL_MACHINE = &H80000002
    26. HKEY_USERS = &H80000003
    27. End Enum
    28.  
    29. Public Const SYNCHRONIZE = &H100000
    30. Public Const STANDARD_RIGHTS_ALL = &H1F0000
    31. Public Const KEY_QUERY_VALUE = &H1
    32. Public Const KEY_SET_VALUE = &H2
    33. Public Const KEY_CREATE_LINK = &H20
    34. Public Const KEY_CREATE_SUB_KEY = &H4
    35. Public Const KEY_ENUMERATE_SUB_KEYS = &H8
    36. Public Const KEY_EVENT = &H1
    37. Public Const KEY_NOTIFY = &H10
    38. Public Const READ_CONTROL = &H20000
    39. Public Const STANDARD_RIGHTS_READ = (READ_CONTROL)
    40. Public Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
    41. Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or _
    42. KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY _
    43. Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) _
    44. And (Not SYNCHRONIZE))
    45. Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or _
    46. KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) _
    47. And (Not SYNCHRONIZE))
    48. Public Const KEY_EXECUTE = (KEY_READ)
    49. Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or _
    50. KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
    51. Public Const REG_BINARY = 3
    52. Public Const REG_CREATED_NEW_KEY = &H1
    53. Public Const REG_DWORD = 4
    54. Public Const REG_DWORD_BIG_ENDIAN = 5
    55. Public Const REG_DWORD_LITTLE_ENDIAN = 4
    56. Public Const REG_EXPAND_SZ = 2
    57. Public Const REG_FULL_RESOURCE_DESCRIPTOR = 9
    58. Public Const REG_LINK = 6
    59. Public Const REG_MULTI_SZ = 7
    60. Public Const REG_NONE = 0
    61. Public Const REG_SZ = 1
    62. Public Const REG_NOTIFY_CHANGE_ATTRIBUTES = &H2
    63. Public Const REG_NOTIFY_CHANGE_LAST_SET = &H4
    64. Public Const REG_NOTIFY_CHANGE_NAME = &H1
    65. Public Const REG_NOTIFY_CHANGE_SECURITY = &H8
    66. Public Const REG_OPTION_BACKUP_RESTORE = 4
    67. Public Const REG_OPTION_CREATE_LINK = 2
    68. Public Const REG_OPTION_NON_VOLATILE = 0
    69. Public Const REG_OPTION_RESERVED = 0
    70. Public Const REG_OPTION_VOLATILE = 1
    71. Public Const REG_LEGAL_CHANGE_FILTER = (REG_NOTIFY_CHANGE_NAME _
    72. Or REG_NOTIFY_CHANGE_ATTRIBUTES Or _
    73. REG_NOTIFY_CHANGE_LAST_SET Or _
    74. REG_NOTIFY_CHANGE_SECURITY)
    75. Public Const REG_LEGAL_OPTION = (REG_OPTION_RESERVED Or _
    76. REG_OPTION_NON_VOLATILE Or REG_OPTION_VOLATILE Or _
    77. REG_OPTION_CREATE_LINK Or REG_OPTION_BACKUP_RESTORE)
    78.  
    79. Public Sub DeleteValue(rClass As T_KeyClasses, Path As String, sKey As String)
    80. Dim hKey As Long
    81. Dim res As Long
    82. res = RegOpenKeyEx(rClass, Path, 0, KEY_ALL_ACCESS, hKey)
    83. res = RegDeleteValue(hKey, sKey)
    84. RegCloseKey hKey
    85. End Sub
    86.  
    87. Public Function SetRegValue(KeyRoot As T_KeyClasses, Path As String, sKey As _
    88. String, NewValue As String) As Boolean
    89. Dim hKey As Long
    90. Dim KeyValType As Long
    91. Dim KeyValSize As Long
    92. Dim KeyVal As String
    93. Dim tmpVal As String
    94. Dim res As Long
    95. Dim i As Integer
    96. Dim x As Long
    97. res = RegOpenKeyEx(KeyRoot, Path, 0, KEY_ALL_ACCESS, hKey)
    98. If res <> 0 Then GoTo Errore
    99. tmpVal = String(1024, 0)
    100. KeyValSize = 1024
    101. res = RegQueryValueEx(hKey, sKey, 0, KeyValType, tmpVal, KeyValSize)
    102. Select Case res
    103. Case 2
    104. KeyValType = REG_SZ
    105. Case Is <> 0
    106. GoTo Errore
    107. End Select
    108. Select Case KeyValType
    109. Case REG_SZ
    110. tmpVal = NewValue
    111. Case REG_DWORD
    112. x = Val(NewValue)
    113. tmpVal = ""
    114. For i = 0 To 3
    115. tmpVal = tmpVal & Chr(x Mod 256)
    116. x = x \ 256
    117. Next
    118. End Select
    119. KeyValSize = Len(tmpVal)
    120. res = RegSetValueEx(hKey, sKey, 0, KeyValType, tmpVal, KeyValSize)
    121. If res <> 0 Then GoTo Errore
    122. SetRegValue = True
    123. RegCloseKey hKey
    124. Exit Function
    125. Errore:
    126. SetRegValue = False
    127. RegCloseKey hKey
    128. End Function
    129.  
    130. 'Insert the following code to your form:
    131. Private Sub Command1_Click()
    132. 'Replace the two 'NotePad' below with your application name, and the two
    133. 'c:\windows\notepad.exe' below with your application file.
    134. SetRegValue HKEY_LOCAL_MACHINE, _
    135. "Software\Microsoft\Windows\CurrentVersion\Run", "NotePad", "c:\windows\notepad.exe"
    136. End Sub
    Why don't you want it to show up in Task Manager?
    hack in why make it so complicated for the noobie ? why not jusy have this:

    VB Code:
    1. 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
    2. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
    3. Const REG_SZ = 1
    4. Const HKEY_CURRENT_USER = &H80000001
    5. Const REGKEY = "Software\Microsoft\Windows\CurrentVersion\Run"
    6. Const KEY_WRITE = &H20006
    7. Dim Path As Long
    8.  
    9. in form_load
    10. If RegOpenKeyEx(HKEY_CURRENT_USER, REGKEY, 0, KEY_WRITE, Path) Then Exit Sub
    11. RegSetValueEx Path, App.Title, 0, REG_SZ, ByVal App.Path & "\" & App.EXEName & ".exe", Len(App.Path & "\" & App.EXEName & ".exe")

  39. #39
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: create/save txt to notepad.

    Quote Originally Posted by tux_newbie
    i have a similar story but i got the admin password by cracking the sam file .anyway happy coding
    p.s:we joined the forum on the same day
    there was a much easier way to get the admin pass than cracking the sam but this is not to be discussed on the forums besides why would you possable want to do that? if you dont have an admin its for a reason

  40. #40

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    77

    Re: create/save txt to notepad.

    Umm, Dark_Shadow, does your code check to see if it' already written, and if it is, it doesn't rewrite?

Page 1 of 2 12 LastLast

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