|
-
Aug 14th, 2000, 12:26 PM
#1
Thread Starter
Hyperactive Member
I'm writing a utility program that simply starts other setup programs, some of the setup programs require a restart after the installation is complete, how can i make my application start back up automatically after the restart?
Any help is appreciated,THANX
Pete Butler
-
Aug 14th, 2000, 12:29 PM
#2
Add a registry entry in the following path:
HKEY_LOCAL_MAHCINE\Software\Microsoft\CurrentVersion\Run.
For the Value, enter your App name (ie MyApp) and for the Data, enter your App path (ie C:\Myapp.exe)
-
Aug 14th, 2000, 12:57 PM
#3
Hi, sorry to hijack a topic, but...
Megatron, could you give me a quick bit of code to add that value to the registry (if possible in the form that you have written above).
Thanks
-
Aug 14th, 2000, 12:57 PM
#4
Thread Starter
Hyperactive Member
The program will be running on numerous new pc's(it's a silly little program to install drivers), so it's not something that will be installed on the c: drive, will this work from cdrom?
-
Aug 14th, 2000, 01:37 PM
#5
Wossname: Insert the following code into a module.
Code:
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
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
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
Function RegQueryStringValue(ByVal hkey As Long, ByVal strValueName As String)
Dim lResult As Long
Dim lValueType As Long
Dim strBuf As String
Dim lDataBufSize As Long
On Error GoTo 0
lResult = RegQueryValueEx(hkey, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
If lResult = ERROR_SUCCESS Then
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(hkey, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
RegQueryStringValue = StripTerminator(strBuf)
End If
End If
End If
End Function
Public Function GetString(hkey As Long, strpath As String, strvalue As String)
Dim keyhand&
Dim datatype&
r = RegOpenKey(hkey, strpath, keyhand&)
GetString = RegQueryStringValue(keyhand&, strvalue)
r = RegCloseKey(keyhand&)
End Function
Function StripTerminator(ByVal strString As String) As String
Dim intZeroPos As Integer
intZeroPos = InStr(strString, Chr$(0))
If intZeroPos > 0 Then
StripTerminator = Left$(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function
Public Sub savestring(hkey As Long, strpath As String, strvalue As String, strdata As String)
Dim keyhand&
r = RegCreateKey(hkey, strpath, keyhand&)
r = RegSetValueEx(keyhand&, strvalue, 0, REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(keyhand&)
End Sub
Insert the following in a Form with 2 CommandButtons
Code:
Private Sub Command1_Click()
'Save a Value to the Registry
savestring HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", "MyApp", "C:\MyApp.exe"
End Sub
Private Sub Command2_Click()
'Get a value from the Registry
Retval = GetString(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", "MyApp")
Print Retval
End Sub
PJB: Yes, it should work if it's in the CD-ROM drive. Just specify the path as D:\MyApp.exe.
-
Aug 14th, 2000, 02:30 PM
#6
Fanatic Member
Unless I misuderstand!!!
Unless I misunderstand the question but all
on has to do is to create a shortcut to your app
and place it under the StartUp menu of windows
It will ensure that the applicattion starts after
restart
There is absolutely no need for any code at all
anywhere for this (unless I fail to understand the
question)
Vale!
-
Aug 14th, 2000, 02:43 PM
#7
Thread Starter
Hyperactive Member
Lafor: That would work but i don't want it to startup everytime they restart the computer, only while they have the CD in and are using the utility.
-
Aug 14th, 2000, 02:45 PM
#8
Monday Morning Lunatic
I think the registry entries get processed before those in the StartUp group.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 14th, 2000, 02:59 PM
#9
if you only want it to run once than add an entry to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
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
|