Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Registry Script

Status
Not open for further replies.

thec0dy

IS-IT--Management
Apr 16, 2010
41
US
Ok, so basically I am wanting to copy a registry entry then save it to the users profile. Once the user connects to a different server I want that registry entry to run and import in that registry. I am having a problem importing the registry key. I have the script check to see if the file exists on the other server. If it doesn't then the script doesn't run. If it does exist then run the registry key. For some reason that file exist command does not work. Can anyone shed some light?



'Script to copy Printer settings from 2003 profiles and import setting to 2008 profile.
Set WshShell = CreateObject("WScript.Shell")
Dim objFSO
Set objFso = CreateObject("Scripting.FileSystemObject")
set objWshShell = WScript.CreateObject("WScript.Shell")
strOS = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")
If strOS = "Microsoft Windows Server 2003" Then
If Not objFso.FileExists("\\SERVER\profile$\%username%\printers.reg") Then
objWshShell.Run "regedit /e \\SERVER1\profile$\%username%\printers.reg HKEY_CURRENT_USER\Printers",0,TRUE
Else
Wscript.Quit
End If
End If

If strOS = "Windows Server (R) 2008 Enterprise" Then
If Not objFso.FileExists("\\SERVER\profile$\%username%\printers.reg") Then
Wscript.Quit
Else
objWshShell.Run "regedit /s \\SERVER\profile$\%username%\printers.reg",0,TRUE
End If
End If
 
I think you need to pull the value of the username environment variable and build an explicit file name string. Something like:
[tt]
Set oShell = CreateObject( "WScript.Shell" )
user=oShell.ExpandEnvironmentStrings("%UserName%")
fileFqn = "\\SERVER\profile$\" & user & "\printers.reg"
If Not objFso.FileExists(fileFQN) Then
...[/tt]

Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
That worked perfectly! Thanks Jeff! I guess it was something dealing with server 2008's interpretation the command.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top