Link to home
Start Free TrialLog in
Avatar of justinbh3
justinbh3Flag for Canada

asked on

How do you define a logon script through the registry?

How do you define a logon script through the registry?

I am trying to automate a process that uses dynamic logon scripts. Once a script is created via some interface I would like to define it as a logon script directly through the interface.

I am aware of using gpedit and other user interactive ways of accomplishing this task, however, I am automating this task.

Thanks,

Justin.
Avatar of andrew_aj1
andrew_aj1
Flag of United States of America image

You should be able to add any programs/scripts at the following registry location to have them run at logon.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
I hope this helps. Good luck.
Avatar of justinbh3

ASKER

I would actually prefer not to have this script run for every user. Which is why a logon script works better. logon scripts inherit the permissions from the user that is logging on. I am trying to exploit that feature. I also dont want the script run on every user that logs in.

thanks though.
If you want you can place the script into each users startup folder that you want to use this script for or you can write the script where it checks the username and will continue based on that.
Good luck.
I have never really trusted the startup folder as the user has direct access to it. I am trying to keep this as behind the scenes as possible. The username cant be hard coded as this is being shipped to many different customers.

Is there anyone who is familiar here with using logon scripts. They can be used through gpedit.msc within userconfiguration/windows/scripts. What I want is to automate this functionality by directly writing to the registry the necc. values that gpedit would write.
I tried something like this below, without success.
 
Windows Registry Editor Version 5.00
 
[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts]
 
[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff]
 
[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logon]
 
[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logon\0]
"GPO-ID"="LocalGPO"
"SOM-ID"="Local"
"FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User"
"DisplayName"="Local Group Policy"
"GPOName"="Local Group Policy"
 
[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logon\0\0]
"Script"="C:\\admin\\logon.cmd"
"Parameters"=""
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

Open in new window

Avatar of paul_knapp
paul_knapp

I assume you are working on a Network using Active Directory with a Domain Controller. This what I do on my LAN. On the Domain Controller there is a share called 'netlogon'. Place logon scripts in this directory. Now in Active Directory, locate the user/users you want to have run a script. Goto Properties & locate the tab called  Profile. You will see a filed called logon script. Type in here the file name ie logon.bat. I use unique names depending on the user. If you are wondering the field called profile path is if you want to store scripts in a location other than the netlogon share. This avoids using the registry where you can also call the script. I just dont like messing with the registry too much.The only drawback to my method is that if for some reason a PC does not authenticate to the Server on logon, the logon script does not run. Rarely happens but u should be aware of this.
This will be in a workgroup situation. This is restuarant POS software and restaurants typically operate using a workgroup on windowx xp. So thats what we ship. Also the method you have described for a domain can it be implemented programically? Also, I am quite comfortable with the registry and have been for years.

This solution needs to be programmatic in nature. I write everything in java and grab an instance of the runtime to execute any native commands within the environment(ie REG ADD ). The user will be the one who uses the utility that wraps up these cumbersome admin jobs. My job is to make it easy for them with an easy Touch screen interface(  for our touch screen computers ) which has already been created. One of the functions is to map a drive with persistance turned off and but have it run everytime the user logs on. I have read about network map drive problems when persistence=yes so i would rather manually persist the mapped drive through the use of a logon script for a particular user.

This would all happen behind the scenes at the press of a button from my utility. Afterwords, the script would always run at logon and the mapped drive would persist w/o persistence problems. I chose logon scripts because I know that their information is persisted somehow in the registry and it is at the per user level of being run. I just dont know where that info is stored and that is the key. As soon as I know where, I can write the entries myself w/o the use of gpedit.msc.

Again it isnt an active dir. scenario. but I truly appreciate the help.
OK I think I understand what u need. I know our Java Pgm uses a method that writes an entry to the registry in particular to the 'run' key. We are off for Thanksgiving until Monday. I will talk with him then & see how he does it. Hopefully this might be a solution for you. Will get back to u on Monday.

Would there be a common place where logon scripts would stored in your environment?. If so then I believe that what our programmer does would work for you.

Be in touch soon
As long as doesent run globally(ie everytime a user logs on). It needs to run with a certain user logging on. I cant hardcode the username into the script because this ships to many different customers.

The idea is that the end user touches "Add Mapped Drive" and enters paramters for it then presses ok. This is all done through a touch keyboard and touch list boxes to pick the drive. After submitting the parameters my program will create the network drive and a logon script. This logon script must get executed everytime that particular user logs on and not when any other logs on(for security reasons). Windows xp provides the option of using logon scripts on a per user basis. The idea was to add this dynamically created script to that users logon script routine so xp will execute it only when that user logs on.

I know how to do this using gpedit.msc. I am assuming there must be a way to do it directly through the registry since thats where all windows config is saved.
also,

thanks for any further assitance
ASKER CERTIFIED SOLUTION
Avatar of justinbh3
justinbh3
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial