automatically activate logoff startup scripts without gpedit.msc

Here’s my question.
Read this carefully. I have two visual basic scripts and want to activate these scripts every time the computer Logs off and when the machine boots up. I DON'T WANT TO USE GPEDIT.MSC OR physically activate these scripts I want to write a program in Visual Basic or Vbscript that once I click on a button the scripts will be activated automatically. I have already written code that dumps the two scripts in the proper directories under C:\WINDOWS\SYSTEM32\GroupPolicy.
This question can be worth more than the posted points.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richie_SimonettiIT OperationsCommented:
To run at startup, you could add your app to registry under hkey_current_user\software\microsoft\windows\currentversion\run

To logoff, does your app use forms?, if so, you could cath when windows is shutting down at queryunload event of the form.
FubyouAuthor Commented:
Not sure what you mean about
"if so, you could cath when windows is shutting down at queryunload event of the form. "

>>To logoff, does your app use forms?, if so, you could cath when windows is shutting down at queryunload event of the form.

He's trying to say you have to create an app so that you can trap the windows shutdown on queryunload event and your app will perform your script.

Am I right?
Make appropriate change at two lines of the following code and execute on the Click_Event of the button.

'Registry value type definitions
Const REG_NONE As Long = 0
Const REG_SZ As Long = 1
Const REG_EXPAND_SZ As Long = 2
Const REG_BINARY As Long = 3
Const REG_DWORD As Long = 4
Const REG_LINK As Long = 6
Const REG_MULTI_SZ As Long = 7
' Registry section definitions
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006
' Codes returned by Reg API calls
Private Const ERROR_NONE = 0
Private Const ERROR_BADDB = 1
Private Const ERROR_BADKEY = 2
Private Const ERROR_CANTOPEN = 3
Private Const ERROR_CANTREAD = 4
Private Const ERROR_CANTWRITE = 5
Private Const ERROR_NO_MORE_ITEMS = 259
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) 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

Dim keyHand As Long
Dim r As Long
Dim strValue, strData As String

strValue = "YourValueForRegKeyName"                                       ' Change This Line
strData = "C:\WINDOWS\SYSTEM32\GroupPolicy\"   ' Change This Line

r = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", keyHand)
If r = 0 Then
    r = RegSetValueEx(keyHand, strValue, 0, REG_SZ, ByVal strData, Len(strData))
    r = RegCloseKey(keyHand)
End If

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FubyouAuthor Commented:
       Well here is the answer (sort of). The way to solve this problem is by analyzing 3 computers. The first computer I would use GPEDIT.MSC to install the scripts (traditional way). The second computer would be compared to the first to determine the different registry keys that are produced. Then write the program that manually creates those registry entries and running it on computer 3.

What the scripts do...

I have 2 scripts one of them is what my question is centered around the other isn't but I need to explain both. Script one inputs the currently logged in users user name and domain into 2 custom registry keys.
The second script takes that info and applies it to the logon box when the user hits CTRL+ALT+DEL.
Script one runs once and I don't care about script one.

Script two runs every time the user starts the computer or logs off. It reads the two keys and sets the past successful logon name and domain to those keys.
There are no forms to these scripts; it's not a windows application. just a VB script

     My question was if there was a special line of code or way I can tell XP "hey I have a script it's in the Logon Scripts folder, please activate it." with out having to analyze keys and create them myself. Yea this might be a bad idea because of security or the fact that testing my app will blow way a couple computers registry’s. Oh well. I know how to ghost and once sms comes in a can delete those scripts from their GP directory.

I'm going to analyze MADisonMAN code but I think it might be a bit more. I found 10 changed keys when I did my analysis today.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.