• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • Last Modified:

Automatic Start Access MDE Application WIth the Help Of Adding Key To WinXP Registry

I have an application in office 2003. I need to run this application at WinXP startUp. I need to add key to registry.

Post for tested Code sample required.

0
Sayedaziz
Asked:
Sayedaziz
  • 9
  • 8
  • 2
1 Solution
 
Kelvin SparksCommented:
Just add the mde name to the C:\Documents and Settings\username\Start Menu\Programs folder. Use the All users if to started by all.
0
 
SayedazizAuthor Commented:
this i know ......... i need code to add programatically.
0
 
Kelvin SparksCommented:
Can't help I'm sorry. May be a better question to ask in one of the OS  sections. It's really an OS issue.
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
SayedazizAuthor Commented:
no vb can do it.
0
 
sirbountyCommented:
Would a batch file suffice?

REG.EXE is included with XP

Try this in a batch file:

REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\Run /v "My MDE App" /d "C:\\Program Files\\Microsoft Office\\MSAccess.exe -parameters"

This adds the startup entry in the Local Machine - if you need it in Current User, replace HKLM with HKCU
0
 
sirbountyCommented:
My solution will work.
If it's not what the autor is after, I'm sure we can find a programmatic solution that will work.
REG.EXE is just the easiest with the way it the question was posed.
0
 
SayedazizAuthor Commented:
hi sirbounty,

i need to this from another access installation form which will copy file to the specified location in the user pc and would run function once from this application to write to the registry. so that i would require to send the self-created installation wizard in access helping user to install my application at desired location.

hope the above will clear the purpose of VB code required to write to the registry.

Aziz
0
 
sirbountyCommented:
No, I think I'm confused by that statement.
You need a form in Access to modify the registry?
If so, you can SHELL using VBA and run the REG command above (just let me know what you're trying to add, where).
0
 
SayedazizAuthor Commented:
ok

i need to add to registry key ...... so that when windows starts my programme will also launch w/o user need to click anything i.e. shortcut .

as the window log on completes my application should itself execute from the registry. So i need a VB code to add key to the registry. so my installation form wizard will write such key to the registry.

I m increasing points to 250.

Aziz
0
 
sirbountyCommented:
Did you try my previous suggestion?

In your code, add this line: (depending on your app and its parameters)

Shell "CMD /C REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\Run /v " & chr(34) & "My MDE App" & chr(34) & " /d " & chr(34) & "C:\Program Files\Microsoft Office\MSAccess.exe -parameters"

===============

Or modify this code for your purposes:

   Private Const cPGM = "C:\VB Forum\startup\TestStartup.exe"

   Dim oShell As IWshShell_Class
   Set oShell = New IWshShell_Class
   oShell.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyVBApp", _
                   cPGM, "REG_SZ"

Adjusted from ref: http://www.windowsdevcenter.com/oreilly/windows/ron/startup_code1.html

0
 
SayedazizAuthor Commented:
I need some clarification :

variable cPGM will execute .exe file whereas i need to execute .mde/.mdb file

in oShell no dropdown window is available to select RegWrite, do i need some reference ?

HKLM will be sufficient or should i replace this with H_KEY_LOCAL_MACHINE ?

I need to start my app SalesDB.mde in D:\Sales

How can i change above code to get the desired result ?

thx for ur prompt response

Aziz

0
 
sirbountyCommented:
The vbs method is not my preferred, but I use VB more than VBS.

>>variable cPGM will execute .exe file whereas i need to execute .mde/.mdb file<<

You would need to precede the mde with the path to msaccess.exe

"C:\Program Files\Office\MSaccess.exe D:\Sales\MyFile.MDE"

>>in oShell no dropdown window is available to select RegWrite, do i need some reference ?<<
No, you just won't see the dropdown...

>>HKLM will be sufficient or should i replace this with H_KEY_LOCAL_MACHINE ?<<
HKLM is sufficient
0
 
SayedazizAuthor Commented:
In this line of code :

oShell.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyVBApp", _
                   cPGM, "REG_SZ"

MyVBApp should be replaced with ... ? since cPGM already contains the complete path to my db.

thx

aziz
0
 
sirbountyCommented:
The MyVBApp part is a descriptor only...
THe cPGM is where you'd place the executable portion..."C:\...\...\MSAccess D:\Sales\MyFile.MDE"
0
 
SayedazizAuthor Commented:
in this line i m getting Compile error message
 Dim oShell As IWshShell_Class

msg .........  User-defined type not defined

Aziz


0
 
sirbountyCommented:
I'm not sure - I'll see what I can dig up on that..
Did you try the shell command from http:#14103776 ?
0
 
sirbountyCommented:
http://www.codetoad.com/vb_modify_registry.asp is another exhaustive method to modify the registry...

or I found this which is a bit shorter...

Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
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
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
Const REG_SZ = 1
Const HKEY_LOCAL_MACHINE = &H80000002
'HKEY_CLASSES_ROOT = &H80000000
'HKEY_CURRENT_CONFIG = &H80000005
'HKEY_LOCAL_MACHINE = &H80000002
'HKEY_USERS = &H80000003
'HKEY_CURRENT_USER = &H80000001
'HKEY_DYN_DATA = &H80000006
' each of the above values represent diffrent registry place

Const REGKEY = "Software\Microsoft\Windows\CurrentVersion\Run"
Const KEY_WRITE = &H20006
Dim Path As Long

Private Sub Command1_Click()
If RegOpenKeyEx(HKEY_LOCAL_MACHINE , REGKEY, 0, KEY_WRITE, Path) Then Exit Sub
'Now the Path Variable knows where is our path(for instance c:\program\proggy.exe) and he writes it to there
'VERY IMPORTANT: Do not replace it with the constants of the path!!!
'It says to write a new string value with our App title and App Name and path
'Our path is imprtant else it will start other programs or will not
'start at all if the value is invaild
RegSetValueEx Path, App.Title, 0, REG_SZ, ByVal App.Path & "\" & App.EXEName & ".exe", Len(App.Path & "\" & App.EXEName & ".exe")
'app.title will get automaticly the title of your program and put it in the registry as one.
End Sub

Public Sub addreg()
If RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGKEY, 0, KEY_WRITE, Path) Then Exit Sub
RegSetValueEx Path, App.Title, 0, REG_SZ, ByVal App.Path & "\" & App.EXEName & ".exe", Len(App.Path & "\" & App.EXEName & ".exe")
'just change app.title,path,app.path and other of the variables-to your case of the program
End Sub

Taken from http://www.flexbeta.net/forums/lofiversion/index.php/t591.html
0
 
sirbountyCommented:
How's it coming?
0
 
SayedazizAuthor Commented:
i was busy so i couldn't go thru it ...i will check shortly and respond accordingly.

thx for ur patience and support

Aziz
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 9
  • 8
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now