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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month5 days, 11 hours left to enroll

627 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