Link to home
Start Free TrialLog in
Avatar of TheMetrix
TheMetrixFlag for United States of America

asked on

Logon Script Brain Cramp

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
Avatar of Pber
Pber
Flag of Canada image

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


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
ASKER CERTIFIED SOLUTION
Avatar of Pber
Pber
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
Avatar of TheMetrix

ASKER

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.