Solved

using WScript.shell and "cacls" through vba

Posted on 2011-02-24
3
1,668 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 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