Sign in to follow this  
Followers 0
SoftVoile

delete files from network shared folders

19 posts in this topic

#1 ·  Posted (edited)

hi,

i want to delete all *.doc , *.docx and a file Old_Update.txt from all shared folders.

i think i can use the following registry key + RegEnumKey to get path of all shared folder of my pc.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\WorkgroupCrawler\Shares
am i right?

but i don't know how to use this key for deleting files from shared folders of my computer.

and maybe i am guessing wrong and there is some other way to do this task. i am not sure please guide me and tell how to do it.

Edited by SoftVoile

Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them.

Share this post


Link to post
Share on other sites



What about Drivegettype? Wouldn't that return if the folder is networked?


Giggity

Share this post


Link to post
Share on other sites

Success: Returns the type of drive: "Unknown", "Removable", "Fixed", "Network", "CDROM", "RAMDisk"

but the (Shared) Folder's names 'll be different on all computers. and i don't know what will be the names of shared folders. also there will be more then on shared folder.

Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Straight from the help file, with a little mod. :):

$var = DriveGetDrive( "all" )
If NOT @error Then
    For $i = 1 to $var[0]
        $type = DriveGetType($var[$i])
        if $type = "Network" then
            MsgBox(1,"Drives" & $i, $var[$i] & " is a network-drive")
        EndIf
    Next
EndIf

Neo

Edited by NeoFoX

[center][font="Arial"]--- The Neo and Only --- [/font][font="Arial"]--Projects---[/font]Image to Text converterText to ASCII converter[/center]

Share this post


Link to post
Share on other sites

Hi there,

Should this help you? :)

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output &= "Computer: " & $strComputer  & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ShareToDirectory", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output &= "Share: " & $objItem.Share & @CRLF
      $Output &= "SharedElement: " & $objItem.SharedElement & @CRLF
   Next
   ConsoleWrite($Output)
   FileWrite(@TempDir & "\Win32_ShareToDirectory.TXT", $Output )
   Run(@Comspec & " /c start " & @TempDir & "\Win32_ShareToDirectory.TXT" )
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ShareToDirectory" )
Endif

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

why i can not start a new thread in other sections of this forum?

Hi,

First: Did you run the script that i posted?

Second : I beliave you can, just dont start a hello topic.

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

Hi again...

Maybe you'll get the picture with this :

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost";change to a machine name

$Output=""
$Output &= "Computer: " & $strComputer  & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Share", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output &= "Name: " & $objItem.Name & @CRLF
      $Output &= "Path: " & $objItem.Path & @CRLF
   Next
   ConsoleWrite($Output)
ConsoleWrite($Output)
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ShareToDirectory" )
Endif

Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

Hi again...

Maybe you'll get the picture with this :

...

Cheers

thanks, this script gives a list of shared folders in $OutPut along with all info, but i need retrieve/get only path of folders. can you modify it to suit my needs?

Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them.

Share this post


Link to post
Share on other sites

Dim $path[1000000]
$n = 1
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost";change to a machine name

$Output=""
$Output &= "Computer: " & $strComputer  & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Share", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output &= "Name: " & $objItem.Name & @CRLF
      $Output &= "Path: " & $objItem.Path & @CRLF
          $path[$n] = $objitem.path
$n += 1
   Next
   ConsoleWrite($Output)
ConsoleWrite($Output)
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ShareToDirectory" )
Endif

Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

Maybe something like that?


Giggity

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Hi again,

You can shape it as you wish...

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost";change to a machine name

$Output=""
$Output &= "Computer: " & $strComputer  & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Share", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output &= "Path: " & $objItem.Path & @CRLF
   Next
   ConsoleWrite($Output)
ConsoleWrite($Output)
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ShareToDirectory" )
Endif

Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

P.S. - i'm not currently in my laptop, later i'll come and check this again :)

Cheers

Edited by November

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Hi again,

You can shape it as you wish...

code in previous script

Cheers

Hi november,

i created a folder D:\Shared_Test and shared it on network. now after running your [last] script the result is as follow.

Computer: localhost
Path: E:\
Path: 
Path: D:\
Path: F:\
Path: C:\WINDOWS
Path: D:\Shared_Test
Path: C:\
Computer: localhost
Path: E:\
Path: 
Path: D:\
Path: F:\
Path: C:\WINDOWS
Path: D:\Shared_Test
Path: C:\
>Exit code: 0   Time: 0.635

but i want the script to show only the shared path one by one like following

D:\Shared_Test

can you please tell me how remove all extra paths which script is showing in result?

any example of deleting files from shared folders?

hi,

i want to delete all *.doc , *.docx and a file Old_Update.txt from all shared folders.

i think i can use the following registry key + RegEnumKey to get path of all shared folder of my pc.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\WorkgroupCrawler\Shares

am i right?

but i don't know how to use this key for deleting files from shared folders of my computer.

and maybe i am guessing wrong and there is some other way to do this task. i am not sure please guide me and tell how to do it.

i think you converted VBS to AU3, right? but i don't know VBS... trying to do it using autoit.

thanks for your efforts and help.

Edited by SoftVoile

Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them.

Share this post


Link to post
Share on other sites

Hi there,

Is this ok 4 you m8?

#include <array.au3>

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "127.0.0.1";change to a machine name

dim $array[1]

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Share", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $objItem.Path
      ConsoleWrite($Output & @CRLF)
      _ArrayAdd($array, $Output)
   Next
  $Alim = UBound($array)
  ConsoleWrite("lim : " & $Alim & @CRLF)
  _ArrayDelete($array, $Alim)
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ShareToDirectory" )
Endif

_ArrayDisplay($array, "teste")

Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

Hi again november,

i created a folder D:\Shared_Test and shared it on network. now after running your [last] script shows the following.

Posted Image http://i38.tinypic.com/2en3ki9.png

just notice that i have shared only one folder which is 'D:\Shared_Test' but the script also shows extra paths like 'F:\Windows' why?

and i want the script to show only the shared path one by one like following

D:\Shared_Test

can you please tell me how remove all extra paths which script is showing in result?

any example of deleting files from shared folders using your script?

hi,

i want to delete all *.doc , *.docx and a file Old_Update.txt from all shared folders.

i think i can use the following registry key + RegEnumKey to get path of all shared folder of my pc.

CODE

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\WorkgroupCrawler\Shares

am i right?

but i don't know how to use this key for deleting files from shared folders of my computer.

and maybe i am guessing wrong and there is some other way to do this task. i am not sure please guide me and tell how to do it.

Thanks for your efforts and help.

Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them.

Share this post


Link to post
Share on other sites

Hi there,

The script is giving you all the shares including the administrative shares, i've changed the script to give you only the your shared folders:

#include <array.au3>

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "127.0.0.1";change to a machine name

dim $array[1]

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Share WHERE TYPE = 0", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $objItem.Path
      ConsoleWrite($Output & @CRLF)
     ;Sleep(3000)
      _ArrayAdd($array, $Output)
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ShareToDirectory" )
Endif

_ArrayDisplay($array, "Your Shared Places")

Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

I hope this helps,

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

Hi,

you get the shares from regkey HKLM\SYSTEM\CurrentControlSet\Services\lanmanservers\shares.

you have to extract the sharekeys: e.g. c:\temp as temp$ -> then you have a REG_Multi_SZ key temp$ with the following contents:

CSCFlags=0

MaxUses=4294967295

Path=C:\temp

Permissions=0

Remark=

Type=0

you have to extract the path.

this may help you.

Share this post


Link to post
Share on other sites

Hi there,

The script is giving you all the shares including the administrative shares, i've changed the script to give you only the your shared folders:

#include <array.au3>

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "127.0.0.1";change to a machine name

dim $array[1]

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Share WHERE TYPE = 0", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $objItem.Path
      ConsoleWrite($Output & @CRLF)
    ;Sleep(3000)
      _ArrayAdd($array, $Output)
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ShareToDirectory" )
Endif

_ArrayDisplay($array, "Your Shared Places")

Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

I hope this helps,

Cheers

Hi again november,

Thanks for your efforts and help.

one last question.

what should be $strComputer = ?

you said change it to a machine name in comments....

you mean @ComputerName, right?


Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them.

Share this post


Link to post
Share on other sites

Hi again,

Yes... if you want to. But you can sort remote shares in remote hosts aswell, if you have link and permissions :)

That depends in what your script is intend to do :)

Cheers m8


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0