vbscript >> Cacls help

by res0ew3q » Sat, 23 Feb 2008 06:00:56 GMT

Hello folks,

I am trying to figure out why this snippetof the script I have
keeps giving me an invalid character error when I run it. I have
declared the variables and am trying to fill in the "Cacls" comand
switches. any Idea where I messed this one up?

Thanks again for any and all help.

Daryl


'Option Explicit
Dim strusername
Dim strHomeFolder
Dim intRunError, objShell, objFSO
Dim oShell
strusername = "UserLoginID"
strHomeFolder = "homeDirectory"

Set objShell = WScript.creatobject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Assign user permissions to home directory
objShell.run ("%COMSPEC% /c Echo y|cacls"," & strHomeFolder & " /T /E /
G " & strusername & ":F)
End If
If intRunError <> 0 Then
Wscript.Echo "Error Assigning Permissions for User"
'End If
End

vbscript >> Cacls help

by Tom Lavedas » Sat, 23 Feb 2008 06:14:43 GMT



I'm not well versed in CALCS' arguments, but I think you want this for
the Run statement to get the right syntax ...

objShell.run "%COMSPEC% /c Echo y|cacls " & strHomeFolder _
& " /T /E /G " & strusername & ":F"

Also, when I have such problem, I put the whole command string in a
variable and then wsh.echo it (for testing) to see EXACTLY what it
says when the variables are replaced, as in ...

sCmd = "%COMSPEC% /c Echo y|cacls " & strHomeFolder _
& " /T /E /G " & strusername & ":F"
wsh.echo sCmd ' comment out or remove when things work as expected
objShell.Run sCmd

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

vbscript >> Cacls help

by Pegasus (MVP) » Sat, 23 Feb 2008 06:28:18 GMT


The RUN method expects one long string, optionally followed by an
integer and a boolean variable. You gave it two strings. There is also
a double-quote missing at the very end. Try it like so:

objShell.run ("%COMSPEC% /c Echo y|cacls " & strHomeFolder & " /T /E /G " &
strusername & ":F")

Note that the command will file if strHomeFolder has embedded spaces.

vbscript >> Cacls help

by Richard Mueller [MVP] » Sat, 23 Feb 2008 23:40:52 GMT


Also, if the path specified in strHomeFolder must be enclosed in quotes
(perhaps there is a space in the path), double the quotes in the quoted
string. For example:

objShell.run "%COMSPEC% /c Echo y|cacls """ & strHomeFolder _
& """ /T /E /G " & strusername & ":F"

This should display correctly if you echo the command to the console as
suggested.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

vbscript >> Cacls help

by res0ew3q » Tue, 26 Feb 2008 02:16:02 GMT

n Feb 23, 7:40m, "Richard Mueller [MVP]" <rlmueller-
XXXX@XXXXX.COM > wrote:
> >>>En> >>
> > I'm not well versed in CALCS' arguments, but I think you want this>f>r
> > the Run statement to get the right syntax>..> >>
> > objShell.run "%COMSPEC% /c Echo y|cacls " & strHomeFold>r>_
> > & " /T /E /G " & strusername & >:F> >>
> > Also, when I have such problem, I put the whole command string >n>a
> > variable and then wsh.echo it (for testing) to see EXACTLY wha> >t
> > says when the variables are replaced, as in>..> >>
> > sCmd = "%COMSPEC% /c Echo y|cacls " & strHomeFold>r>_
> > & " /T /E /G " & strusername > >:F"
> > wsh.echo sCmd ' comment out or remove when things work as ex>e>ted
> > objShell.Ru> s>m>
>
> > Tom L>v>das
> > =====>=>===
> >http://members.cox.net/tglbatc>/w>h/
>
> Also, if the path specified in strHomeFolder must be enclosed in >uotes
> (perhaps there is a space in the path), double the quotes in the >uoted
> string. For ex>mp>e:
>
> objShell.run "%COMSPEC% /c Echo y|cacls """ & strHomeFo>der _
> & """ /T /E /G " & strusernam> &>":F"
>
> This should display correctly if you echo the command to the co>sole as
> su>ge>ted. >>
> --
> Richard>Mueller
> Microsoft MVP Scripting >nd ADSI
> Hilltop Lab -http://www.rlmue>ler.net
> --- Hide quote> t>xt -
>
> - Show quoted text -

Thank you all for the help. The Script now runs without spitting out
an error, but the CACLS command isn't doing anything. From what I
have been reading it should Change the ACL for the folder and add the
users with Full control. The script displays what I think I want to
happen, but nothing does. The username adn home folder are created
further up the script. Could it not be taking the variable that I
have declared ? I will post the rest of the script and hopefully it
is just my general stupidity in calling something. There is no error
checking in this I know the top portion works. The User is created
correctly and the home share is created aswell. This last bit is to
assign the user with full control for thier share. any help is
greatly appreciated.

Daryl

'Option Explicit
Dim WshShell, fso, objOU, objUser
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")


DomainName = "ctc.ctcclient.com" ' "DC=CTC, DC=CTCCLIENT, DC=COM"
'ctc.ctcclient.com"
OUNamePt1 = "CTC Staff"
DefaultPassword = "Pass#word1"
Set objOU = GetObject("LDAP://" & DomainName)
InputPrompt1 = "Domain = "&DomainName&vbCrLf&"Container =
"&OUName&vbCrLf&vbCrLf&"Enter Users Login ID:"
InputPrompt2 = "Domain = "&DomainName&vbCrLf&"Container =
"&OUName&vbCrLf&vbCrLf&"Enter Users First Name:"
InputPrompt3 = "Domain = "&DomainName&vbCrLf&"Container =
"&OUName&vbCrLf&vbCrLf&"Enter Users lastname:"
InputPrompt4 = "Domain = "&DomainName&vbCrLf&"Container =
"&OUName&vbCrLf&vbCrLf&"Enter Users Job Title:"
UserName = InputBox(InputPrompt1, "UserLoginID")
FirstName = InputBox(InputPrompt2, "FirstName")
lastname = InputBox(InputPrompt3, "lastname")
Department = InputBox(InputPrompt4, "Job Title")

Set objUser = objOU.Create("User", "CN=" & FirstName & " " & lastname
& ",OU=" & OUNamePt1)
Set ProfileServer = fso.GetFolder("\\ctcpdxdb01\home$")
'Creat

vbscript >> Cacls help

by res0ew3q » Thu, 28 Feb 2008 01:45:18 GMT

n Feb 25, 10:16m, XXXX@XXXXX.COM wrote:
> > > I'm not well versed in CALCS' arguments, but I think you want this>f>r> > > > the Run statement to get the right syntax>..> >>> > > > objShell.run "%COMSPEC% /c Echo y|cacls " & strHomeFold>r>_> > > > & " /T /E /G " & strusername & >:F> >>> > > > Also, when I have such problem, I put the whole command string >n>a> > > > variable and then wsh.echo it (for testing) to see EXACTLY wha> >t> > > > says when the variables are replaced, as in>..> >>> > > > sCmd = "%COMSPEC% /c Echo y|cacls " & strHomeFold>r>_> > > > & " /T /E /G " & strusername > >:>"
> > > wsh.echo sCmd ' comment out or remove when things work as ex>e>t>d
> > > objShell.Ru> s>m> >>
> > > Tom L>v>d>s
> > > =====>=>=>=
> > >http://members.cox.net/tglbatc>/w>h>
>
> > Also, if the path specified in strHomeFolder must be enclosed in >u>tes
> > (perhaps there is a space in the path), double the quotes in the >u>ted
> > string. For ex>mp>e>
>
> > objShell.run "%COMSPEC% /c Echo y|cacls """ & strHomeFo>d>r _
> > & """ /T /E /G " & strusernam> &>">F"
>
> > This should display correctly if you echo the command to the co>s>le as
> > su>ge>t>d.
>> > > Richard>M>eller
> > Microsoft MVP Scripting >n> ADSI
> > Hilltop Lab -http://www.rlmue>l>r.net
> > --- Hide quote> t>x> -
>
> > - Show quote> t>xt -
>
> Thank you all for the help. he Script now runs without spit>ing out
> an error, but the CACLS command isn't doing anything. ro> what I
> have been reading it should Change the ACL for the folder and>add the
> users with Full control. he script displays what I think I>want to
> happen, but nothing does. he username adn home folder are>created
> further up the script. ould it not be taking the variabl> that I
> have declared ? will post the rest of the script and hope>ully it
> is just my general stupidity in calling something. here is >o error
> checking in this know the top portion works. he User is>created
> correctly and the home share is created aswell. his last b>t is to
> assign the user with full control for thier share. ny>help is
> greatly appr>ci>ted.
> >> >aryl
>
> 'Option >xplicit
> Dim WshShell, fso, objOU,>objUser
> Set WSHShell = WScript.CreateObject("WScript>Shell")
> Set fso = CreateObject("Scripting.FileSystem>bject")
> Set WshNetwork = WScript.CreateObject("WScript.N>tw>rk")
>
> DomainName = "ctc.ctcclient.com" ' "DC=CTC, DC=CTCCLIENT,>DC=COM"
> 'ctc.ctccli>nt.com"
> OUNamePt1 = "CT> Staff"
> DefaultPassword = "Pas>#word1"
> Set objOU = GetObject("LDAP://" & Dom>inName)
> InputPrompt1 = "Domain = "&DomainName&vbCrLf&"Con>ainer =
> "&OUName&vbCrLf&vbCrLf&"Enter Users Lo>in ID:"
> InputPrompt2 = "Domain = "&DomainName&vbCrLf&"Con>ainer =
> "&OUName&vbCrLf&vbCrLf&"Enter Users Firs> Name:"
> InputPrompt3 = "Domain = "&DomainName&vbCrLf&"Con>ainer =
> "&OUName&vbCrLf&vbCrLf&"Enter Users la>tname:"
> InputPrompt4 = "Domain = "&DomainName&vbCrLf&"Con>ainer =
> "&OUName&vbCrLf&vbCrLf&"Enter Users Job>Title:"
> UserName = InputBox(InputPrompt1, "UserL>ginID")
> FirstName = InputBox(InputPrompt2, "Fir>tName")
> lastname = InputBox(InputPrompt3, "la&

Similar Threads

1. csharp version of cacls in VBScript - CSharp/C#

2. Helllp with CACLS in VB.NET!

in VB.NET, I am trying to assign Group rights to a network file.  I am 
successfull at impersonating a domain account with rights but the following 
code is failing, ie, nothing happens at the file level.

MyProcessString = "cacls.exe """ + ICopyTo + """ /E /G """ + ICopyRights + 
""":R"
System.Diagnostics.Process.Start(MyProcessString)
msgbox(MyProcessString)
the MyProcessString MsgBox shows:     cacls.exe 
"\\main\documents\filename.txt"  /E /G "DOMAIN\group name":R
cacls does work with group names and I can get this code to run as a batch 
file under the impersonation runas account just fine

I have also tried:


p.StartInfo.FileName = "cacls.exe"
p.StartInfo.Arguments = MyProcess '"" + ICopyTo + """ /E /G """ + 
ICopyRights + """:R"
p.StartInfo.Arguments = ICopyTo + " /E /G " + ICopyRights + ":R"
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.UseShellExecute = False
p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
p.StartInfo.CreateNoWindow = True
p.Start()
p.WaitForExit()
ProcessOutput = p.ExitCode.ToString()

but I get a variety of error numbers like error 5, etc.. and I do not know 
where I can find error code interpretations and this does not work either 
...

Any suggestions !

Thanks

Terry




3. Calling cacls.exe from Excel vb - Excel

4. Running CACLS.exe as user

I have written a script that starts Outlook 2003 and creates a new user 
profile when a user logs in. Howeve, I want to get rid of the shortcut in the 
programs menu, but users do not have permissions on th C: drive. I have added 
the following line to change the permissions on th efile but it does not work 
when run as a user.
I am presuming that CACLS.exe will only run as an administrator. Just 
looking for confirmation that I am right.
WshShell.Run("cmd /c echo y| cacls " & menuicon  & " /T /E /g 
Everyone:F"),0,true
If I am right is there another way to delete these shortcuts?
Thanks

5. managing NTFS permissions - cacls or wmi?

6. VBScript & Cacls.exe

I want to use vbscript and cacls to automate some directory settings under 
XP.  Having little experience with this commandline utility, I have a 
question for the group.  While cacls displays <IO>, <OI>, and <CI>, how do I 
cause cacls to set one or more of these?

For example: how do I set a folder to Change permissions with <OI> & <CI>?

Dick 


7. Changing Folder permission on remote computer using cacls

8. Remote Cacls

Is there a way to change NTFS permissions on a remote server through a 
script.  For example from Computer1 can I execute a script that will add 
Server1\Group1 to \\Server1\d$\Data with change access.  I know I can use 
Cacls.exe and give a "domain" user or a "Domain" group permission to a remote 
server, but following Microsoft standards they say I should only apply 
permissions to Local Groups

Thanks again.  I found this site today and I have a few questions that I 
have been searching for answers to for a long time.
-- 
Thanks for the help!
Brian