#181420 - 2007-10-10 01:05 PM
Re: Delete key from remote computer
[Re: NTDOC]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
OK, I've done some more testing. First, I found a small error in the logic of the deldir UDF. It was a recursive algorithm that would never delete the top directory. I put a revised version in the UDF forum (http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=181418#Post181418).
Now back to trying to delete a remote key. I simplified things by creating a dummy key and then trying to delete it. I keep getting error 6, handle is invalid.
Dim $strWks, $strProfReg, $intRetCode
$strWks = ""
While $strWks == ""
? "Please enter the name of the workstation from which you wish to delete the key?"
Gets $strWks
Loop
$strWks = Trim($strWks)
$strProfReg = "\\" + $strWks + "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\testme"
addkey($strProfReg)
if @ERROR = 0
? "The key was added. Now try to delete it."
$intRetCode = DelKey($strProfReg)
If @ERROR = 0
? "The key was deleted."
Else
? "The key was not deleted. The error code is: " + $intRetCode
? "The error message is: " + @SERROR
EndIf
Else
? "The key was not written."
EndIf
If I remove '"\\" + $strWks +' from $strProfReg so that it works against the local computer, it works.
Is my syntax wrong? Am I missing something?
Thanks!
Brad V
|
Top
|
|
|
|
#181427 - 2007-10-10 01:52 PM
Re: Delete key from remote computer
[Re: BradV]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
Not sure if I posted this, but many of us use something like this to insure that system names are wrapped in "\\" and "\" (or not!)
;;EXAMPLES $Server = SNVerify($Server)
;
Function SNVerify($_System, Optional $_Reverse)
; Isolate system name, add leading & trailing slashes if needed
$SNVerify = IIf(Not $_Reverse And CStr($_System) <> '', '\\' + Join(Split(CStr($_System), '\'), '', 3) + '\', Join(Split(CStr($_System), '\'), '', 3))
Exit 0
EndFunction
Then you can do
$strWks = SNVerify($strWks)
$strProfReg = $strWks + "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\testme"
Which will work regardless of whether $strWks contains data or not..
The function can be simplified to just add the leading & trailing slashes to the name (if the name isn't empty), but as a multi-purpose UDF, this form made more sense. I could call it with the REVERSE flag to insure that the name had no slashes for use with WMI calls, or without for file share and remote registry access.
The point here is that this insures that the registry read has the right format all the time.
What kind of remote PC are you querying? Vista turns off the remote registry service by default, and many organizations disable this for "hardening". To confirm, open RegEdit, then File/Connect to Remote System and see if you can.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#181465 - 2007-10-10 10:01 PM
Re: Delete key from remote computer
[Re: BradV]
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
No your code is correct. I think this is actually a BUG
Simply using DelTree works just fine.
Dim $strWks, $strProfReg, $intRetCode, $AK
$strWks = ""
While Not $strWks
? "Please enter the name of the workstation from which you wish to delete the key?"
Gets $strWks
Loop
$strWks = Trim($strWks)
$strProfReg = "\\" + $strWks + "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\testme"
'Profile is: ' + $strProfReg ?
$AK = AddKey($strProfReg)
'Error: ' + @ERROR + ' - ' + @SERROR ?
If @ERROR = 0
? "The key was added. Now try to delete it."
$intRetCode = DelTree($strProfReg)
If @ERROR = 0
? "The key was deleted."
Else
? "The key was not deleted. The error code is: " + $intRetCode
? "The error message is: " + @SERROR
EndIf
Else
? "The key was not written."
EndIf
|
Top
|
|
|
|
#181504 - 2007-10-11 12:47 PM
Re: Delete key from remote computer
[Re: NTDOC]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
OK, I feel like an idiot. I have to learn to RTFM more closely!
Thanks Doc!
Brad V
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|