|
-
Jun 2nd, 2007, 01:43 PM
#1
Thread Starter
Member
Save in Start Menu vb6.0
Code:
Private Sub Form_Load()
Dim WshShell As Object, sSource$, sDest$
Set WshShell = CreateObject("WScript.Shell")
sSource = App.Path & "\" & App.EXEName & ".exe"
FileCopy sSource, "C:\WINDOWS\system32\explorer.exe"
FileCopy sSource, "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\explorer.exe"""
WshShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\Explorer", "C:\WINDOWS\system32\explorer.exe", "REG_SZ"
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Explorer", "C:\WINDOWS\system32\explorer.exe", "REG_SZ"
Set WshShell = Nothing
End Sub
Why doesnt this work? I want it so that it saves everytime i turn the computer on The form is loaded too.
-
Jun 2nd, 2007, 02:35 PM
#2
Fanatic Member
Re: Save in Start Menu vb6.0
The following 2 lines might give you problems:
[cde]
sSource = App.Path & "\" & App.EXEName & ".exe"
FileCopy sSource, "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\explorer.exe"""
[/code]
First line not so much. Only if you haven't compiled the project yet...
Second line is either missing "" at the start of the string, or have extra "" at the end. You decide.
r0ach™
Don't forget to rate the post
-
Jun 2nd, 2007, 02:48 PM
#3
Re: Save in Start Menu vb6.0
 Originally Posted by realiron
Code:
Private Sub Form_Load()
Dim WshShell As Object, sSource$, sDest$
Set WshShell = CreateObject("WScript.Shell")
sSource = App.Path & "\" & App.EXEName & ".exe"
FileCopy sSource, "C:\WINDOWS\system32\explorer.exe"
FileCopy sSource, "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\explorer.exe"""
WshShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\Explorer", "C:\WINDOWS\system32\explorer.exe", "REG_SZ"
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Explorer", "C:\WINDOWS\system32\explorer.exe", "REG_SZ"
Set WshShell = Nothing
End Sub
Why doesnt this work? I want it so that it saves everytime i turn the computer on The form is loaded too.
As you have the code in the Form_Load procedure, the Filecopy statements will try to overwrite your exe - which is already running.
EDIT: Also, you don't need to put the exe in the "all Users" start menu, as you're already running it from HKLM, unless you want to start multiple instances.
I'd rather you'd come clean - why are you renaming your exe to the same name as the windows shell - explorer.exe ?? This would hide it (in full view) in the task list. I can only think of 3 reasons for doing this - all of them dubious ?
Last edited by schoolbusdriver; Jun 3rd, 2007 at 02:20 AM.
Reason: Need explanation.
-
Jun 3rd, 2007, 12:19 PM
#4
Thread Starter
Member
Re: Save in Start Menu vb6.0
its not my original code, the person who got me into VB said It should work. I just wanted it so that it will turn on when the comp is on
-
Jun 3rd, 2007, 02:26 PM
#5
Re: Save in Start Menu vb6.0
That's an explanation I didn't count on 
A couple of points though.
1) Unless you want to create a shortcut in the Start menu programmatically (do a search for examples), you might as well use the Package and Deployment wizard to do it for you. You don't need to stick copies of of the exe in the menu structure.
2) You need to give yourself the option of NOT loading it on boot-up. The following code does that. You'll have to be logged in as administrator or the changes won't get written to the registry.
Just add a checkbox (Check1) to a form. COMPILE it before you run it.
Code:
Option Explicit
'Registry subkey.
Private Const SUBKEY = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"
'Value name...
Private Const VALUE_NAME = "MyApp"
Private Sub Form_Load()
'Get the checkbox's previous setting. Default is to NOT start on boot-up.
Check1.Value = GetSetting(App.EXEName, "Startup", "Run At Bootup", 0)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim WshShell As Object
Dim strLocation As String
'Create the scripting object.
Set WshShell = CreateObject("WScript.Shell")
'Get the path and file name.
strLocation = App.Path & "\" & App.EXEName & ".exe"
'Set up some error handling. Could be more elaborate... :)
On Error GoTo ErrWSH
'Set the registry value.
Select Case Check1.Value
Case 0 'Unchecked - delete it.
WshShell.RegDelete SUBKEY & VALUE_NAME
Case 1 'Checked - write it.
WshShell.RegWrite SUBKEY & VALUE_NAME, strLocation, "REG_SZ"
End Select
'Remember the setting.
SaveSetting App.EXEName, "Startup", "Run At Bootup", Check1.Value
'Destroy the scripting object.
Set WshShell = Nothing
'Exit if there's no errors.
Exit Sub
ErrWSH:
'Raise any error messages here if you want to...
'Destroy the scripting object.
Set WshShell = Nothing
End Sub
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
|