Connecting Tech Pros Worldwide Forums | Help | Site Map

Windows startup program problem

shek124's Avatar
Member
 
Join Date: Oct 2007
Posts: 47
#1: Dec 4 '07
I want to run a windows startup program.
here my code:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
  3.     Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, ByVal phkResult As Long) As Long
  4.     Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
  5.     Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long
  6.     Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, ByVal phkResult As Long) As Long
  7.     Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByVal lpType As Long, ByVal lpData As String, ByVal lpcbData As Long) As Long
  8.     Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
  9.     Public Const REG_SZ = 1 ' Unicode nul terminated String 
  10.     Public Const REG_DWORD = 4 ' 32-bit number 
  11.     Public Const HKEY_CLASSES_ROOT = &H80000000
  12.     Public Const HKEY_CURRENT_USER = &H80000001
  13.     Public Const HKEY_LOCAL_MACHINE = &H80000002
  14.     Public Const HKEY_USERS = &H80000003
  15.     Public Const HKEY_PERFORMANCE_DATA = &H80000004
  16.     Public Const ERROR_SUCCESS = 0&
  17.  
  18.  Public Sub SaveString(ByVal Hkey As Long, ByVal strPath As String, ByVal strValue As String, ByVal strdata As String)
  19.         Dim keyhand As Long
  20.         Dim r As Long
  21.         r = RegCreateKey(Hkey, strPath, keyhand)
  22.         r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, strdata, Len(strdata))
  23.         r = RegCloseKey(keyhand)
  24.     End Sub
  25.  
  26.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  27.         'Process.Start("c:\\startup.exe", "startup.txt")
  28.         SaveString(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
  29.             "C:\Documents and Settings\vertical\Desktop\Startup\startup.txt", "C:\Documents and Settings\vertical\Desktop\Startup\startup.txt")
  30.  
  31.     End Sub

when the program runs in VB.net , i get the following error


Error 1 Unable to write to output file 'C:\Documents and Settings\vertical\My Documents\startup\startup\obj\Debug\startup.exe': Access is denied.


Plz help me, i want to view the text file , How do i convert it

Shashi Sadasivan's Avatar
Moderator
 
Join Date: Aug 2007
Location: Brisbane, Australia
Posts: 1,414
#2: Dec 4 '07

re: Windows startup program problem


probably you have already tried to run the program once.

does it end in anyway?

What you would need to do it go to task manager find the program and shut it down (it would already be running) and if it is running it is running the exe file as given in the path by you.

on building a project the exe file is created, and it can only be overwritten if it is not in use.
shek124's Avatar
Member
 
Join Date: Oct 2007
Posts: 47
#3: Dec 4 '07

re: Windows startup program problem


The exe file in not running in the task manger.


you arr not understand about my problem. when i click the start button , the error was occured directly.even not going to debug .


IN the program , when did the running path was written ? i dont know .. also i need to output in .txt file not in .exe file ,.. wat are the replacements i have do in my code. plz help me , thanks for yr reply
Reply