Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


automatically activate logoff startup scripts without gpedit.msc

Posted on 2003-11-12
Medium Priority
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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

705 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