Solved

using WScript.shell and "cacls" through vba

Posted on 2011-02-24
3
1,683 Views
Last Modified: 2012-05-11
Hi folks

I'm trying to use VB6 to run the "Cacls" command to get the permissions of a folder. My code is below. Am i missing something?

Public Function getPermissions()     
    Dim stdOut, objScriptExec, strResults, objShell
    Set objShell = CreateObject("WScript.Shell")
    On Error Resume Next
     objShell.exec ("cacls \\PCNAME\FILENAME")
     strResults = LCase(objScriptExec.stdOut.ReadAll)
     Set stdOut = Nothing
     Set objScriptExec = Nothing
     
     MsgBox strResults
End Function

Open in new window

0
Comment
Question by:ITUCIRL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

by:ITUCIRL
ID: 34971628
Should have mentioned that I have the correct reference set, and when i step through the code, the line
strResults = LCase(objScriptExec.stdOut.ReadAll)

Open in new window

is empty.
0
 
LVL 3

Expert Comment

by:sam0x01
ID: 34972046
Try changing
objShell.exec ("cacls \\PCNAME\FILENAME")

to

objScriptExec=objShell.exec ("cacls \\PCNAME\FILENAME")

not sure if VB can access WScript object, be worth commenting out the On Error Resume Next
 with an apostrophe
0
 
LVL 1

Accepted Solution

by:
MARCOSALVES earned 500 total points
ID: 34972394
Hi!
Try this:

Set objShell = CreateObject("WScript.Shell")
Set objWshScriptExec = objShell.Exec("cacls \\PCNAME\FILENAME")
Set objStdOut = objWshScriptExec.StdOut
strOutput = objStdOut.ReadAll
WScript.Echo strOutput

Must work.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question