Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Logon Script Brain Cramp

Posted on 2006-07-14
4
309 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add user account for APC PowerChute Business Edition. 6 103
How to virtualize old server? (2003) 7 113
Auto Login Script 3 51
ESXi VM of Server 2003 Saving Slow. 7 83
Organizations create, modify, and maintain huge amounts of data to help their businesses earn money and generally function.  Typically every network user within an organization has a bit of disk space to store in process items and personal files.   …
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.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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