Solved

Logon Script Brain Cramp

Posted on 2006-07-14
4
307 Views
Last Modified: 2010-08-05
I am having a bit of a brain cramp on my scripting abilities.

-------------------------------------------------------------------------------------------------

Below is the contents of a .reg file that is normally used to create a registry entry for users for a program we use. This has to be done for the logged on use.

[HKEY_CURRENT_USER\Software\Lilly Software\VISUAL Manufacturing\Configuration]
"Local Directory"="c:\\VISUAL\\vmfg_ini"
--------------------------------------------------------------------------------------------------

Below is the contents of a .vbs script I wrote to do the same as the above .reg file. Am I on the right path with my thinking?

This registry edit/entry is going to be used for Windows 2000 Pro, XP Pro, and Windows 2003 Terminal Server Clients.

 
Const HKEY_CURRENT_USER = &H80000002
strComputer = "."

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Lilly Software\VISUAL Manufacturing\Configuration"
strValueName = "Local Directory"
strValue = "%c:\VISUAL\vmfg_ini%"

objReg.SetExpandedStringValue _
    HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

---------------------------------------------------------------------------------------------------------------

TIA
Dave
0
Comment
Question by:TheMetrix
  • 3
4 Comments
 
LVL 26

Expert Comment

by:Pber
ID: 17107777
Instead of writing it in VB, why not just batch out the reg file

regedit -s YourRegfile.reg

You could also do the same thing with reg.exe
reg add "HKCU\Software\Lilly Software\VISUAL Manufacturing\Configuration" /v "Local Directory" /t REG_SZ /d c:\VISUAL\vmfg_ini /f


0
 
LVL 26

Expert Comment

by:Pber
ID: 17107898
If you really want to do it in VB:

Const HKEY_CURRENT_USER = &H80000001  '<- changed this to 1 from 2
strComputer = "."

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Lilly Software\VISUAL Manufacturing\Configuration"
strValueName = "Local Directory"
strValue = "c:\VISUAL\vmfg_ini"  '<- removed the '%'

objReg.CreateKey(HKEY_CURRENT_USER, strKeyPath) ' <- added this - you must create the key first

objReg.SetExpandedStringValue _
    HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
0
 
LVL 26

Accepted Solution

by:
Pber earned 125 total points
ID: 17107937
I've modified it slightly once again since I removed the return value from the CreateKey and thus must also remove the parentheses.

Anyhow, this should work good:

Const HKEY_CURRENT_USER = &H80000001  '<- changed this to 1 from 2
strComputer = "."

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Lilly Software\VISUAL Manufacturing\Configuration"
strValueName = "Local Directory"
strValue = "c:\VISUAL\vmfg_ini"  '<- removed the '%'

objReg.CreateKey HKEY_CURRENT_USER, strKeyPath  ' <- added this - you must create the key first

objReg.SetStringValue  HKEY_CURRENT_USER,strKeyPath,strValueName,strValue   '<- changed from Expanded to Just String.
0
 
LVL 5

Author Comment

by:TheMetrix
ID: 17108349
Pber,

The reason for not wanting to run the .reg file through a .bat script is I don't want users to see the script run and give them the chance to possibly cancel.

I used the second post to create the .vbs script, it works perfectly.

Thank you very much.

Points Awarded.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

822 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