#69712 - 2002-09-10 08:42 PM
push file
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I have written a utility script that can push a file (or folder of files) to a remote PC.
It will prompt you to find the file(s) to send Ask the name of the destination PC Ask for the destination folder, choose (D)esktop, (F)avorites, (S)tartmenu, (C):\, or (B)rowse) the first letter is sufficient) And then it will copy the file.
I’m still working a bit on the Browse section, as it browses the local machine, not the remote one. If a folder is selected, it copies the contents of the folder, but not the folder itself. I’m also planning on having it accept multiple PCs if separated by commas.
Any suggestions/comments are welcome.
code:
break on $=setconsole("hide")
$objShell = CreateObject("Shell.Application") $objFolder = $objShell.BrowseForFolder(0, "Select a file or folder to push:", 16384) $objFolderItem = $objFolder.Self $path = $objFolderItem.Path
:findpc $computer =XlsInputBox("Enter Name of PC to push to", "Destination Computer", @wksta) $p=wshping($computer) if $p[1]=0 ? "PC not found" goto findpc endif
$index=0 :sidloop $sids=enumkey("\\$computer\hkey_users\",$index) if not @error and not instr($sids,"_") $sid=$sids $index=$index+1 goto sidloop endif $HKUsidSMWCV ="HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion"
$destfolder=XlsInputBox("Type (D)esktop, (F)avorites, (S)tartmenu, (C):\, or (B)rowse", "Select destination folder", "Desktop") select case left($destfolder,1)="D" $dest=readvalue("\\$computer\$HKUsidSMWCV\Explorer\Shell Folders","Desktop") case left($destfolder,1)="F" $dest=readvalue("\\$computer\$HKUsidSMWCV\Explorer\Shell Folders","Favorites") case left($destfolder,1)="S" $dest=readvalue("\\$computer\$HKUsidSMWCV\Explorer\Shell Folders","Start Menu") case left($destfolder,1)="C" $dest="c:" case left($destfolder,1)="B" $destFolder = $objShell.BrowseForFolder(0, "Select destination folder", 16400) $destFolderItem = $destFolder.Self $dest=$destFolderItem.Path case 1 $=sendmessage(@wksta,"Bad Destination, Quitting") quit endselect $dest="\\$computer\c$"+right($dest,len($dest)-2)
if exist($dest) copy "$path" "$dest" if @error $=sendmessage(@wksta,@serror) endif else $=sendmessage(@wksta,"can't find $dest") endif $objShell = 0 quit
;******************************************************************************************************** function XlsInputBox( $prompt, optional $title, optional $default, optional $left, optional $top, optional $type) dim $xls $xls = createobject("excel.application") if $xls $xlsInputBox = $xls.inputbox($prompt,$title,$default,$left,$top,,,2) if not $xlsInputBox $xlsInputBox = @wksta endif $xls.quit $xls = 0 endif endfunction ;******************************************************************************************************** FUNCTION WSHPing($Computer,optional $replies) dim $ip, $l, $r, $count, $return, $line if not $replies $replies=1 endif $ip=0 $Count=0 $shell='%comspec% /c ping $Computer -n $replies ' $return=WSHPipe($shell,1) if not @error for each $line in $return select case instr($line,"[") $l=instr($line,"[")+1 $r=instr($line,"]") $ip=substr($line,$l,$r-$l) case instr($line,"reply from") $Count=$Count+1 case instr($line,"timed out") $Count=$Count-1 endselect next $WSHPing=$ip,$count else $WSHPing="0.0.0.0","0" exit(487) endif ENDFUNCTION ;******************************************************************************************************** Function WshPipe($ShellCMD, OPTIONAL $NoEcho) Dim $WshShell, $oExec, $AllOutput, $Exit, $WshExitCode $WshErrorMsg="" $WshShell=CreateObject("WScript.Shell") $oExec=$WshShell.Exec($ShellCMD) While $Exit<>1 Dim $Output Select Case Not $oExec.StdOut.AtEndOfStream $Output=$oExec.StdOut.ReadAll Case Not $oExec.StdErr.AtEndOfStream $Output=$oExec.StdErr.ReadAll $WshErrorMsg = $Output Case 1 $Output=-1 EndSelect If $Output=-1 If $oExec.Status=1 $Exit=1 Endif Else If $NoEcho<>1 ? $Output Endif $AllOutput = $AllOutput + $Output Endif Loop $WshExitCode=$oExec.ExitCode $WshPipe=split($AllOutput,chr(10)) Exit($WshExitCode) EndFunction
|
Top
|
|
|
|
#69713 - 2002-09-10 11:03 PM
Re: push file
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
I added GUICopy to it to show progress. Worked Ok.
When copying a folder of files using GUICopy it also copies the folder. Just using copy, it only copied the files and not the folder or sub-folders.
Anyway, here's my addition...
code:
break on $=setconsole("hide")
$objShell = CreateObject("Shell.Application") $objFolder = $objShell.BrowseForFolder(0, "Select a file or folder to push:", 16384) $objFolderItem = $objFolder.Self $path = $objFolderItem.Path
:findpc $computer =XlsInputBox("Enter Name of PC to push to", "Destination Computer", @wksta) $p=wshping($computer) if $p[1]=0 ? "PC not found" goto findpc endif
$index=0 :sidloop $sids=enumkey("\\$computer\hkey_users\",$index) if not @error and not instr($sids,"_") $sid=$sids $index=$index+1 goto sidloop endif $HKUsidSMWCV ="HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion"
$destfolder=XlsInputBox("Type (D)esktop, (F)avorites, (S)tartmenu, (C):\, or (B)rowse", "Select destination folder", "Desktop") select case left($destfolder,1)="D" $dest=readvalue("\\$computer\$HKUsidSMWCV\Explorer\Shell Folders","Desktop") case left($destfolder,1)="F" $dest=readvalue("\\$computer\$HKUsidSMWCV\Explorer\Shell Folders","Favorites") case left($destfolder,1)="S" $dest=readvalue("\\$computer\$HKUsidSMWCV\Explorer\Shell Folders","Start Menu") case left($destfolder,1)="C" $dest="c:" case left($destfolder,1)="B" $destFolder = $objShell.BrowseForFolder(0, "Select destination folder", 16400) $destFolderItem = $destFolder.Self $dest=$destFolderItem.Path case 1 $=sendmessage(@wksta,"Bad Destination, Quitting") quit endselect $dest="\\$computer\c$"+right($dest,len($dest)-2)
if exist($dest) ;copy "$path" "$dest" GUICopy("Copy", $path, $dest) if @error $=sendmessage(@wksta,@serror) endif else $=sendmessage(@wksta,"can't find $dest") endif $objShell = 0 quit
;******************************************************************************************************** function XlsInputBox( $prompt, optional $title, optional $default, optional $left, optional $top, optional $type) dim $xls $xls = createobject("excel.application") if $xls $xlsInputBox = $xls.inputbox($prompt,$title,$default,$left,$top,,,2) if not $xlsInputBox $xlsInputBox = @wksta endif $xls.quit $xls = 0 endif endfunction ;******************************************************************************************************** FUNCTION WSHPing($Computer,optional $replies) dim $ip, $l, $r, $count, $return, $line if not $replies $replies=1 endif $ip=0 $Count=0 $shell='%comspec% /c ping $Computer -n $replies ' $return=WSHPipe($shell,1) if not @error for each $line in $return select case instr($line,"[") $l=instr($line,"[")+1 $r=instr($line,"]") $ip=substr($line,$l,$r-$l) case instr($line,"reply from") $Count=$Count+1 case instr($line,"timed out") $Count=$Count-1 endselect next $WSHPing=$ip,$count else $WSHPing="0.0.0.0","0" exit(487) endif ENDFUNCTION ;******************************************************************************************************** Function WshPipe($ShellCMD, OPTIONAL $NoEcho) Dim $WshShell, $oExec, $AllOutput, $Exit, $WshExitCode $WshErrorMsg="" $WshShell=CreateObject("WScript.Shell") $oExec=$WshShell.Exec($ShellCMD) While $Exit<>1 Dim $Output Select Case Not $oExec.StdOut.AtEndOfStream $Output=$oExec.StdOut.ReadAll Case Not $oExec.StdErr.AtEndOfStream $Output=$oExec.StdErr.ReadAll $WshErrorMsg = $Output Case 1 $Output=-1 EndSelect If $Output=-1 If $oExec.Status=1 $Exit=1 Endif Else If $NoEcho<>1 ? $Output Endif $AllOutput = $AllOutput + $Output Endif Loop $WshExitCode=$oExec.ExitCode $WshPipe=split($AllOutput,chr(10)) Exit($WshExitCode) EndFunction function GUICopy($CMD, $Source, $Destination, OPTIONAL $Flags) If not $Flags $Flags=0 Endif If not exist($Source) Beep ? "Source does not exist." Exit (1) Endif If not exist($Destination) Beep ? "Destination does not exist." Exit (2) Endif $objShell=CreateObject("Shell.Application") $objFolder=$objShell.NameSpace($Destination) If not $objFolder Beep ? "Cannot create namespace. Incorrect Shell32.dll version." Exit (3) Endif Select Case $CMD="Copy" $objFolder.CopyHere($Source, $Flags) Case $CMD="Move" $objFolder.MoveHere($Source, $Flags) Case 1 Beep ? "GUICopy Syntax Incorrect. Use COPY or MOVE." $objShell=0 Exit (4) EndSelect $objShell=0 Exit @error endfunction
|
Top
|
|
|
|
#69715 - 2002-09-12 03:05 PM
Re: push file
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
usually, I just browsed to the client machine and copied the file by hand...
but when I had to do a dozen... there had to be a better way.
|
Top
|
|
|
|
#69716 - 2002-09-12 04:24 PM
Re: push file
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
Put this in the select to open explorer on the remote PC.
code:
case left($destfolder,1)="E" run 'explorer /n,/root,\\$computer\c$' quit
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 262 anonymous users online.
|
|
|