Archive

Posts Tagged ‘command line’

how to create/share a directory over a SMB network, using the command line

14 October 2008 Leave a comment

@echo off
if x%1x==xx goto usage
if +%2+ == ++ goto usage
if +%1+ == +/?+ goto usage
if +%1+ == +?+ goto usage
:command
md %1
net share %2=%1 /grant:Everyone,FULL
CACLS %1 /E /G Everyone:F
goto end
:usage
echo salut mon gars, ce script va creer le dossier que tu passe comme premier paramètre
echo et le partage sur le reseau (pour Everyone) avec le nom que t'as passé comme deuxième paramètre.
echo exemple:
echo cescript.bat c:\totocaca totocacapartage
:end

Categories: Uncategorized Tags: , , , ,

javascript code to use WScript parameters

27 August 2008 3 comments

The following code makes use of the WScript.Arguments.Named and Unnamed properties to retrieve and use the WshNamed and WshUnnamed objects.

You can find something on MSDN about this topic, but this is a useful and till-now-missing example (IMHO).

For example, call it with “cscript /Nologo libparam.js /debug bla=bla key=value /verbose”.

var argsNamed = WScript.Arguments.Named;
var argsUnnamed = WScript.Arguments.Unnamed;

function Parameters (argumentsNamed, argumentsUnnamed, splitCharacter) {
    this.splitChar = splitCharacter;
	this.named = argumentsNamed;
    this.unnamed = argumentsUnnamed;
	this.unnamedOptions = new Array()
	
	this.decomposeUnnamedOptions = function ()
	{
		if (typeof(this.unnamed) == 'undefined')
			return
		//WScript.Echo("this.unnamed.length: " + this.unnamed.length);
		for (var j = 0; j  2)
				continue;
			if(typeof(parts[1]) == 'undefined')
				this.unnamedOptions[parts[0]] = 'undefined';
			this.unnamedOptions[parts[0]] = parts[1];
		}
	}

	this.debug = function () {
		WScript.Echo("Parameters class inited.");
		WScript.Echo("There are " + this.named.length + " named arguments.");
		WScript.Echo("There are " + this.unnamed.length + " unnamed arguments.");
		WScript.Echo("The split character is '" + this.splitChar + "'");
		WScript.Echo("The named args are "+this.named.length+" :");
		for (var j in this.named) {
			WScript.Echo("named(" + j+"):"+this.named.Item(j));
		}
		WScript.Echo("The unnamed args are "+this.unnamed.length+" :");
		for (var j = 0; j < this.unnamed.length; j = j + 1) {
			WScript.Echo("unnamed(" + j+"):"+this.unnamed.Item(j));
		}
	}

}


params = new Parameters(argsNamed, argsUnnamed, "=");

params.decomposeUnnamedOptions();

if (params.named.Exists("debug"))
	params.debug();

if (params.named.Exists("verbose"))
	WScript.Echo("---begin processing unnamed args");

if (!params.named.Exists("noresults")) {
	for (var i in params.unnamedOptions) {
		WScript.Echo('key is: ' + i + ', value is: ' + params.unnamedOptions[i]);
	}
}

if (params.named.Exists("verbose"))
	WScript.Echo("---end processing unnamed args");