Solved

Logon Script Brain Cramp

Posted on 2006-07-14
4
305 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The HP utility "HP Lights-Out Online Configuration Utility for Windows Server 2003/2008" could be of great use when it comes to remotely configure a HP servers ILO WITHOUT rebooting the server. We would only need to create and run scripts using thi…
Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

12 Experts available now in Live!

Get 1:1 Help Now