Quantcast
Channel: Hackviking.com » VBScript
Viewing all articles
Browse latest Browse all 5

PSC: Move share

$
0
0

shareerrorI have decided what the Power of scripting script should do! If you move a share by moving it in windows explorer the share will stop work. If you move the folder with File System Object from vbscript the share will still be there but will be pointing at the old path that no longer exists. So how to solve this?

I know a few ways that you don't. First attempt was to use the winnt://localhost/lanmanserver/ object to try updating the path of the share. No luck the property is read only!

Next attempt was using WMI instead. Same thing, unable to update the path. So i thought I delete the share and then create it again. Well enough that worked how ever I didn't manage to get the rights for the share to come along to the new one. There is methods to extract the access mask for the share and supply it when creating a new one, so I think it can be solved. I didn't have the time to do so this time and I think I proved my point about the power of scripting.

At the same time I have learned or realized a few things that I didn't thought about. Most scripts I have written in the past has been for controlled environments.  By that I mean a system where a specific task was asked from the script and the run was always with the same parameters. Here I'm writing a script that should run on different versions of the operating system and with several different variables.

So some of the limitations I ran into can be expressed in the words: Access Denied! It was issues with running some of the commands from the script without running it with elevation. This is no issue running it from the command prompt with cscript moveshare.vbs as long as you start the cmd with elevation (right-click and select Run As Administrator). There are ways around this even with the "double-click execution" of scripts that are discussed in detail here.

So the window version of the script is pretty useless with a standard setup. How ever if you run the script with elevation from the cmd you will be able to move shares around on the disk. The script is pretty ruff around the edges and some more error handling and stuff needs to be added. There probably will be solvable to get the share to keep it's access list as well. This script should be seen as a proof of concept.


'********************************************************************************************
'*
'*		Power of scripting challange!	
'*
'*		moveshare.vbs
'*
'*		Purpose: Move a shared folder from one location to another
'*		without losing the share!
'*
'*		Written by Kristofer Källsbo 
'*
'*		http://www.hackviking.com
'*
'********************************************************************************************
Option explicit
Dim FSO

'Get the filesystem object ready
Set FSO = CreateObject("Scripting.FileSystemObject")

'First check if we are running in console mode or window mode
If (InStr(1, WScript.FullName, "cscript", vbTextCompare)) Then
    InitConsole
ElseIf (InStr(1, WScript.FullName, "wscript", vbTextCompare)) Then
    InitWindow
Else
	' Hope this never fires! :) 
    wscript.echo "How the hell did you start this script?"
End If

'Clean up
Set FSO = Nothing

'Handles the command line run of the script
Sub InitConsole()
	'Check if we have any parameters
	If (Wscript.Arguments.Count 

Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images