automatically activate logoff startup scripts without gpedit.msc

Posted on 2003-11-12
Last Modified: 2008-01-09
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.
Question by:Fubyou
LVL 16

Expert Comment

ID: 9732894
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.

Author Comment

ID: 9733737
Not sure what you mean about
"if so, you could cath when windows is shutting down at queryunload event of the form. "

LVL 26

Expert Comment

ID: 9734083
>>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?

Accepted Solution

MADisonMAN earned 250 total points
ID: 9734772
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

Author Comment

ID: 9736781
       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.

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question