Hello,
I've make this script using two functions (udfSqueeze and WshPipe) and all goes just fine but when I write the value to the reg the value shows at right place but at the end a strange character that looks like a Pipe ("|") is added to the value.
The value sould be:
\\servername\NSSVOL1\USERS\ICT\BILLG
but it shows:
\\servername\NSSVOL1\USERS\ICT\BILLG|
this is my code:
Code:
; -----------------------------------------------------------------------
; Doc_path.kix
; -----------------------------------------------------------------------
; The script changes the destination of the default document location of
; the applications:
; MS Excel
; MS Word
; MS Powerpoint
; -----------------------------------------------------------------------
; Samengesteld door Frans Erich
; -----------------------------------------------------------------------
; Updated by
;
; -----------------------------------------------------------------------
; Dependencies
; - Kixtart version 4.1 or later
; - Function udfSqueeze
; - Function WshPipe
; - Windows Script Host
; -----------------------------------------------------------------------
; Credits to
; The builetin board communities of www.kixtart.org and www.kixscripts.com
; Special thanks to builetin board modorators:
; - Richard H.
; - sealeopard
; - Chris S.
; - NTDOC
; -----------------------------------------------------------------------
; Variables
$search=" H:"
$word_key="HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\Word\Options"
; -----------------------------------------------------------------------
Function udfSqueeze($sSource,Optional $sDelimiters, Optional $bTrim)
Dim $iSourceLength $iSourceLength=0
Dim $iIndex $iIndex=0
Dim $iLastGood $iLastGood=0
Dim $bFound $bFound=0
$udfSqueeze=""
; --------------------------
; Defaults and sanity checks
; --------------------------
If $sDelimiters="" $sDelimiters=" " EndIf
If $bTrim $bTrim=1 Else $bTrim=0 EndIf
; ----------------------------------------
; High speed squeeze for single characters
; ----------------------------------------
If Len($sDelimiters)=1
$sDelimiters=""+$sDelimiters+$sDelimiters
$iIndex=InStr($sSource,$sDelimiters)
While $iIndex
$sSource=""+SubStr($sSource,1,$iIndex)+SubStr($sSource,$iIndex+2,Len($sSource))
$iIndex=InStr($sSource,$sDelimiters)
Loop
If $bTrim
$sDelimiters=SubStr($sDelimiters,1,1)
; -------------
; Trim leading.
; -------------
While SubStr($sSource,1,1)=$sDelimiters
$sSource=SubStr($sSource,2,Len($sSource))
Loop
; --------------
; Trim Trailing.
; --------------
$iIndex=Len($sSource)
While SubStr($sSource,$iIndex,1)=$sDelimiters
$sSource=SubStr($sSource,1,$iIndex-1)
$iIndex=Len($sSource)
Loop
EndIf
$udfSqueeze=$sSource
Else
; --------------------------------------
; Slower squeeze for multiple characters
; --------------------------------------
$iSourceLength=Len($sSource)
For $iIndex = 1 To $iSourceLength
$cChar=SubStr($sSource,$iIndex,1)
If InStr($sDelimiters,$cChar)
If $bFound=0 AND ( $iLastGood OR $bTrim=0 )
$udfSqueeze=""+$udfSqueeze+SubStr($sDelimiters,1,1)
EndIf
$bFound=1
Else
$bFound=0
$udfSqueeze=""+$udfSqueeze+$cChar
If $bTrim $iLastGood=Len($udfSqueeze) EndIf
EndIf
Next
If $iLastGood $udfSqueeze=SubStr($udfSqueeze,1,$iLastGood) EndIf
EndIf
EndFunction
Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
Dim $oExec, $Output
$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
If NOT VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
While NOT $oExec.Status Loop
$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
If NOT $NoEcho $Output EndIf
$WshPipe=Split($Output,Chr(10))
Exit($oExec.ExitCode)
EndFunction
Break on
$rc=WshPipe("%comspec% /c net use",1)
For Each $line In $rc
If InStr($line,$search)
$linepart=Split(udfSqueeze($line," ","true"))
$ = WriteValue ($word_key,"DOC-PATH",$linepart[2],"reg_sz")
? $linepart[2]
EndIf
Next
:END
Thanks,
GP