/build/static/layout/Breadcrumb_cap_w.png

Using cacls in VB

In a followup on this topic, i ran into some issues.. I found out that cacls is the way to go about when settings rights on files locally. Unfortunately, SMS 2003 seems top be unable to distribute using CMD's, so i'm going about using a VBS. This is what i have so far:


Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")

On Error Resume Next

WSHShell.Run"C:\WINDOWS\System32\cacls.exe C:\Program Files\Windows Media Player\wmplayer.exe /E /P USERS:n", 1,true
WSHShell.Run"C:\WINDOWS\System32\cacls.exe C:\Program Files\Windows Media Player\wmplayer.exe /E /P POWER USERS:n", 1, true
Wscript.Quit(0)


Only problem is, when using cacls, the path (or file) must be between quotes. ("") That doesn't work with the VB script.. The WSHShell.Run need to be between quotes. Any way around this? I could try to use variables, but i'm still a newbie to VB so any help would be greatly appreciated.. Thanks!

0 Comments   [ + ] Show comments

Answers (4)

Posted by: yarborg 18 years ago
Blue Belt
0
I gave up on using the shell with command lines. I'm sure there is some syntax guru out there that can figure it out. I actually use WMI for this kind of stuff because I think it's easier and once you start learning it there really is a lot more you can do. Try the code below and see if that works:


Option Explicit
Dim objWMIService, objProcess, objCalc
Dim strShell, objProgram, strComputer, strExe

strComputer = "."
strExe = "cacls.exe" & " " & "C:\Program Files\Windows Media Player\wmplayer.exe /E /P USERS:n"
' Connect to WMI
set objWMIService = getobject("winmgmts://"_
& strComputer & "/root/cimv2")

' Obtain the Win32_Process class of object.
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_( _
"Create").InParameters.SpawnInstance_
objProgram.CommandLine = strExe

'Execute the program now at the command line.
Set strShell = objWMIService.ExecMethod( _
"Win32_Process", "Create", objProgram)

'WScript.echo "Created: " & strExe & " on " & strComputer
WSCript.Quit

Just duplicate it for the second cacls command you want to use.

Hope that helps.
Posted by: neo2000 18 years ago
Purple Belt
0
Unfortunately, still no go.. The script runs ok, but Cacls is giving me problems.. The problem is in the command. Should read:

C:\WINDOWS\System32\cacls.exe "C:\Program Files\Windows Media Player\wmplayer.exe" /E /P USERS:n

VB doesn't seem to like the quotes around the path.. But they need to be there, or else the calcs command doesn't work. [:(] (Did I say "Thank you Microsoft! today?") So i'm basically stuck with the same issue as before.
Thanks for your help though, i'm going to look into WMI, cause that seems to open up a lot more possibilities.. Maybe you have some other suggestions regarding my "problem"? Thanks!
Posted by: yarborg 18 years ago
Blue Belt
0
Ok here is the correct syntax to accomplish this. Seems to work with notepad.exe. Basically it is the Chr(34) character reference that we needed.

Option Explicit
Dim objWMIService, objProcess, objCalc
Dim strShell, objProgram, strComputer, strExe

strComputer = "."
strExe = "C:\WINDOWS\System32\cacls.exe" & " " & Chr(34) & "C:\Program Files\Windows Media Player\wmplayer.exe" & Chr(34) & " /E /P USERS:n"
' Connect to WMI
set objWMIService = getobject("winmgmts://"_
& strComputer & "/root/cimv2")

' Obtain the Win32_Process class of object.
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_( _
"Create").InParameters.SpawnInstance_
objProgram.CommandLine = strExe

'Execute the program now at the command line.
Set strShell = objWMIService.ExecMethod( _
"Win32_Process", "Create", objProgram)

WScript.echo "Created: " & strExe & " on " & strComputer
WSCript.Quit

I left the echo in there so you could see the quotes in the strExe.
Posted by: neo2000 18 years ago
Purple Belt
0
That seems to work! [:D] Thank you for all the help! [;)]
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ