Solved

automatically activate logoff startup scripts without gpedit.msc

Posted on 2003-11-12
5
1,390 Views
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.
0
Comment
Question by:Fubyou
5 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
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.
0
 

Author Comment

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

cath?
0
 
LVL 26

Expert Comment

by:EDDYKT
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.

AFAIK
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?
0
 
LVL 1

Accepted Solution

by:
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
Const REG_RESOURCE_LIST As Long = 8
' Registry section definitions
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_PERFORMANCE_DATA = &H80000004
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_OUTOFMEMORY = 6
Private Const ERROR_INVALID_PARAMETER = 7
Private Const ERROR_ACCESS_DENIED = 8
Private Const ERROR_INVALID_PARAMETERS = 87
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\YourScript.xyz"   ' 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
0
 

Author Comment

by:Fubyou
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.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now