Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scripting syntax error, W2K server 2

Status
Not open for further replies.

billieT

MIS
Dec 11, 2001
107
NZ
Hi there:

I know very little about VBScript - anyone know of any good online resources for learning? - but I'm currently in an enviroment where VBScript is used to carry out routine network tasks.

The script I'm having problems with is basically a wrapper for standard NT commands to remove user directories and shares. The error I'm getting is Line 22, "Expected ')'", which seems to me that I've left out a bracket or failed to escape some control character.

Here is a part of the script in question - I've bolded the first line where an error occurs. The aim of the line is to xcopy the directory \\server\Y:\users\<username> to \\server\T:\home-archive\<username>:
Code:
dim fso, oShell
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set oShell = WScript.CreateObject (&quot;WSCript.shell&quot;)
Set objArgs = WScript.Arguments

if objArgs.Count <> 2 then
	wscript.echo &quot;Usage: test.vbs OU USERNAME&quot;
	wscript.quit
end if

Wscript.echo &quot;Organisational Unit: &quot; & objArgs(0)
Wscript.echo &quot;Username: &quot; & objArgs(1)
Wscript.echo &quot;Full Path on <SERVER> Y:\&quot; & objArgs(0) & &quot;\users\&quot; & objArgs(1)

If (lcase(objArgs(0)) = &quot;xxx&quot;) THEN
If (fso.FolderExists(&quot;\\<SERVER>\y$\&quot; & objArgs(0) & &quot;\users\&quot; & objArgs(1))) Then

Result = oShell.run (&quot;cmd /c xcopy /e /i /q \\<SERVER>\y$\&quot; & objArgs(0) & &quot;\users\&quot; & objArgs(1) &quot;t:\Home-Archive\&quot; & objArgs(1),1,true)
Code:
Wscript.echo &quot;RESULT - MOVE FOLDER TO (0=Yes,1=No): &quot; & Result 

		Result = oShell.run (&quot;cmd /c ntnetshr /d \\<SERVER>\&quot; & objArgs(1) & &quot;$ y:\&quot; & objArgs(0) & &quot;\users\&quot; & objArgs(1),1,true)
		Wscript.echo &quot;RESULT - REMOVE SHARE (0=Yes,1=No): &quot; & Result 

		Result = oShell.run (&quot;cmd /c rd /s /q \\<SERVER>\y$\&quot; & objArgs(0) & &quot;\users\&quot; & objArgs(1),1,true)
		Wscript.echo &quot;RESULT - DELETE ORIGINAL FOLDER (0=Yes,1=No): &quot; & Result
	
end if
 
You forgot an & after the first objArgs(1). Also, it's organiZational unit :)

There are some other changes i'd make as well. I prefer to avoid shelling out whenever possible. In order to achieve that goal, I'd use the FileSystemObject to do the copying and deleting. For the share, I'd use WMI. I'll post you a sample tomorrow, it's 5 till 1:00am and I'm heading to bed :)
 
Hello billieT,

Code:
Result = oShell.run (&quot;cmd /c xcopy /e /i /q \\<SERVER>\y$\&quot; & objArgs(0) & &quot;\users\&quot;  & objArgs(1)
&
Code:
 &quot;t:\Home-Archive\&quot; & objArgs(1),1,true)

regards - tsuji
 
Oh, Strahan and tsuji, DUH!!!!!! How completely stupid of me.

And Strahan, I completely agree with you about the shelling out. I mean, I don't know anything about VBScript, but I think it's completely ludicrous to script something in a language and not make use of its true functionality (eg. FSOs and WMI access). Personally, I would have left it in batch if I was writing it from scratch - at least until I knew something more about how to do it properly in VB. But that's the go when you're &quot;inheriting&quot; stuff.

If you still feel motivated, I'd really appreciate pointers to the proper way of doing it...

(PS. We aren't Americans, it galls to write &quot;organisational&quot; incorrectly! :))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top