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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot use parentheses when calling a Sub 2

Status
Not open for further replies.

PCBrandon

IS-IT--Management
Jan 6, 2007
17
0
0
Hello,

I have a small script that pulls usernames from an excel sheet and creates a folder/sets permissions for each user. I'm getting the following error when running it:

Line: 26
Char: 110
Error: Cannot use parentheses when calling a Sub
Code: 800A0414
Source: Microsoft VBScript compilation error

The code is posted in its entirety below:

Code:
Dim oFSO, oExcel, oSheet, sUser, iRow
iRow = 2

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oExcel = CreateObject("Excel.Application") 
Set oSheet = oExcel.Workbooks.Open("C:\Documents and Settings\Administrator\Desktop\student.xls")

Do Until oExcel.Cells(iRow,5).Value= ""
sUser=oExcel.Cells(iRow,5).Value
iRow = iRow+1
Call HomeDir()
Loop
oExcel.Quit
Wscript.Quit

Sub HomeDir()
Dim sHome, sHomeDir, oFolder
sHome = "D:\roamingprofiles2\"
sHomeDir = sHome&sUser

If oFSO.FolderExists(sHomeDir) Then
   Set oFolder = oFSO.GetFolder(sUser)
  Else
   oFSO.CreateFolder(sHomeDir)
   Set oShell = Wscript.CreateObject(Wscript.Shell)
   oShell.Run("%COMSPEC% /c cacls Echo Y| "& sHomeDir & " /t /c /g Administrators:F "& sUser & ":F", 2, True)

End If 

End Sub

The line the error references is the oShell.Run line. The file is saved as a .vbs file.

Any thoughts? Thanks!

 
Use either this:
oShell.Run "%COMSPEC% /c cacls Echo Y| " & sHomeDir & " /t /c /g Administrators:F " & sUser & ":F", 2, True
Or this:
Call oShell.Run("%COMSPEC% /c cacls Echo Y| " & sHomeDir & " /t /c /g Administrators:F " & sUser & ":F", 2, True)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
After trying both of your suggestions I get the error:

Line: 24
Char: 4
Error: Object doesn't support this property or method: 'Wscript.Shell'
Code: 800A01B6
Source: Microsoft VBScript runtime error

Any thoughts?

 
>Set oShell = Wscript.CreateObject(Wscript.Shell)
[tt]Set oShell = Wscript.CreateObject([red]"[/red]Wscript.Shell[red]"[/red])[/tt]
 
That was the problem tsuji, thank you!

I'm now finding that my command doesn't work. It doesn't set the permissions at all. If I remove the Echo Y part, it'll work, but I have the press Y to confirm for each user. How can I get it to either not ask me to confirm or echo Y to the screen without causing it to fail?

Thanks!
 
Fixed it, I had to change it to:

Code:
Call oShell.Run("%SYSTEMROOT%\system32\cmd.exe /c echo y| cacls " & sHomeDir & " /t /c /g Administrators:F " & sUser & ":F")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top