Page 1 of 1 1
Topic Options
#36608 - 2003-02-18 05:39 PM registry Key (trying to rename registry key)
Anonymous
Unregistered


Hy Everyone,

In my Kix Script I am trying to rename a key under

HKCU\Printers\Connection\?????

And I am not able to do it, I am new to Kix.

Can someone help please.

Thanks.

(MCA: complete subject)

[ 18. February 2003, 17:48: Message edited by: MCA ]

Top
#36609 - 2003-02-18 05:43 PM Re: registry Key (trying to rename registry key)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Show us what code you use. KiX does not have any rename function. You need to recreate the key and recreate all the values under it. Be aware that you could affect permissions in the process.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#36610 - 2003-02-18 05:46 PM Re: registry Key (trying to rename registry key)
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Take a look at the topics

moving renaming and coping registry keys
Registry

The related scripts can be downloaded from novastar site.
greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#36611 - 2003-02-18 05:50 PM Re: registry Key (trying to rename registry key)
Anonymous
Unregistered


Here is the Code. All I want is to change the name of the key. Simply rename it.

code:
:GetKey

$KeyName = EnumKey($HomeKey,$index) ;read the next printer name

CHR(13) + CHR(10); carriage return line feed for debugging purposes only
if @error = 0
$FullKey = $HomeKey + "\" + $KeyName
;get the full path for the printer registry key
$Port = READVALUE($FullKey,"Server")
;get the port for current printer

;if the old server name is in the port, replace it with the new server name
if INSTR($PORT,$OLDSVR)
$Prt = SUBSTR($PORT,$L + 3,0 )
;separate the printer share name from the port name
$NewPort = "\\" + $NEWSVR + $Prt
;generate new port using new server and printer share
WriteValue($FullKey,"Server",$NewPort,"REG_SZ")
;write this new port to the registry

if @ERROR = 0 ;if successful, write to the log file
OPEN(2,"C:\Winnt\PrintMig.log",5)
WRITELINE(2,"Successfully moved printer " + $Prt + " from " + $OLDSVR + " to " + $NEWSVR +Chr(13) +Chr(10))
$count = $count + 1 ;increase the count of printers migrated
else
BEEP
? "There was an error redirecting your printers. Please contact the Help Desk."
OPEN(2,"C:\Windows\PrintMig.log",5)
WRITELINE(2,"Errors while moving printer " + $Prt + " from " + $OLDSVR + " to " + $NEWSVR +Chr(13) +Chr(10))
endif
endif
$index = $index + 1 ;increment index for next pass
goto GetKey ;loop and read next printer
Endif
; --------------------------------------------------------------;
; ----------- End section Enumerate Printer Ports --;
; --------------------------------------------------------------;

:END

EXIT 0

(MCA: add CODE tages)

[ 18. February 2003, 17:53: Message edited by: MCA ]

Top
#36612 - 2003-02-18 06:50 PM Re: registry Key (trying to rename registry key)
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Willo,

This looks like an offshoot of my fnRemapDrives() function. I have a new function to remap printers that I haven't posted yet that looks like this...



Break On CLS
$NUL=SetOption("Explicit","On")
Dim $,$ticks,$rc

$ticks=@ticks
$rc = fnRemapPrinters("OldServer","NewServer")
@ERROR ":" @SERROR
If @INWIN=2 and $RC ? "Reboot Required" EndIf
"Remapped "$rc + " Printers in "+(@ticks-$ticks)/1000+" seconds."

Get $

Function fnRemapPrinters($sOldServer,$sNewServer)
    Dim $lIndex,$sPrinters,$sPrinter,$sServer,$sPrint,$sPort,$sSplit,$lS,$sShare,$NUL,$Err,$sDevice
    $fnRemapPrinters=0
    $lIndex=0
    If @INWIN=1
        $sPrinters="HKCU\Printers\Connections\"
        Do
            $sPrinter=EnumKey($sPrinters,$lIndex)
            If $sPrinter
                $sServer=ReadValue($sPrinters+$sPrinter,"Server")
                If SUBSTR($sServer,3,LEN($sServer))=$sOldServer
                    $sPrint=Split($sPrinter,",")
                    $NUL=DelPrinterConnection("\\"+$sOldServer+"\"+$sPrint[3])
                    If @ERROR $Err=@ERROR EndIf
                    $NUL=AddPrinterConnection("\\"+$sNewServer+"\"+$sPrint[3])
                    If @ERROR $Err=@ERROR Else $fnRemapPrinters=$fnRemapPrinters+1 EndIf
                EndIf
            EndIf
        $lIndex=$lIndex+1
        Until $sPrinter=""
    Else
        $sPrinters="HKLM\System\CurrentControlSet\control\Print\Printers\"
        Do
            $sPrinter=EnumKey($sPrinters,$lIndex)
            If $sPrinter
                $sPort=ReadValue($sPrinters+$sPrinter,"Port")
                $sSplit=Split($sPort,"\")
                If $sSplit[2]=$sOldServer
                    $lS=Len($sPort)-Len($sOldServer)-2
                    $sShare=Right($sPort,$lS)
                    $NUL=WriteValue($sPrinters+$sPrinter,"Port","\\"+$sNewserver+$sShare,"REG_SZ")
                    If @ERROR $Err=@ERROR EndIf
                    $sDevice=ReadProfileString ("Win.ini""Windows""Device")
                    $sDevice=Split($sDevice,",")
                    If $sDevice[2]=$sPort
                        $NUL=WriteProfileString ("Win.ini""Windows""Device"
                            $sDevice[0]+","+$sDevice[1]+","+"\\"+$sNewserver+$sShare)
                        If @ERROR $Err=@ERROR EndIf
                    EndIf
                    $NUL=WriteProfileString ("Win.ini""Ports"$sPort)
                    $NUL=WriteProfileString ("Win.ini""Ports""\\"+$sNewserver+$sShare" ")
                    If @ERROR $Err=@ERROR EndIf
                    $sPrinterPorts=ReadProfileString ("Win.ini""PrinterPorts"$sPrinter)
                    $sPrinterPorts=Split($sPrinterPorts,",")
                    $NUL=WriteProfileString ("Win.ini""PrinterPorts"$sPrinter
                        $sPrinterPorts[0]+","+"\\"+$sNewserver+$sShare+","+$sPrinterPorts[2]
                            +","+$sPrinterPorts[3])
                    If @ERROR $Err=@ERROR EndIf
                    $sDevices=ReadProfileString ("Win.ini""Devices"$sPrinter)
                    $sDevices=Split($sDevices,",")
                    $NUL=WriteProfileString ("Win.ini""Devices"$sPrinter$sDevices[0]+","
                        +"\\"+$sNewserver+$sShare)
                    If @ERROR $Err=@ERROR EndIf
                    If Not $Err $fnRemapPrinters=$fnRemapPrinters+1 EndIf
                EndIf
            EndIf
            $lIndex=$lIndex+1
        Until $sPrinter=""
    EndIf
    If Not $Err $Err=0 EndIf
    Exit $Err
EndFunction



I've tested it and it works. I haven't posted it yet because I was going to test it in against a test server that we're setting up this week.

Anyway, see if this will meet your needs. It is designed to work on Windows 9x computers as well.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1110 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.052 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org