Any way to open security tab on folder via vbscript?
-
Wednesday, December 05, 2012 4:00 PM
We have to audit our images before we make then distributable to our user base. Part of the verification process is to verify the permissions on folders the image builders create without changing the baseline at all. Different systems have different folders, but that's kind of easy to manage. What I can't figure out is how to use vbscript (what I am using for the rest of the extensive verification process) to simulate a right click on the windows folder and selecting properties and then selecting the security tab. I wouldn't think it would be this difficult, but alas, it is.
I realize this site is not "Scripts R Us", so any help would be appreciated. If I find the answer before someone has a chance to help, I'll gladly post it here. Here is a snip of my verification code that allows the validator to input the path to the parent folder, then the actual folder that needs to be checked:
'Folder to Check do while X=0 strFolderPath = InputBox(" Parent folder ", "Please input the path to the Parent folder") If strFolderPath <> "" Then strFolderToChk = InputBox(" Folder Name to Check ", "Please input the folder to check") strmessage = "Check File Permissions on - " & strFolderPath & "\" & strFolderToChk & "?" intAnswer = _ Msgbox(strmessage, vbYesNo, "Verify Folder to Check") If intAnswer = vbYes Then wscript.echo "Check Permissions on Folder " & strFolderPath & "\" & strFolderToChk exit do else Msgbox "Folder Location Cleared" End if else Msgbox "Folder Location is Blank" End If loopThank you all!!
Bill the Cat
All Replies
-
Wednesday, December 05, 2012 4:30 PM
Use iCACLS to get folder and file permissions.
No. You cannot get to the security tab with VBScript.
¯\_(ツ)_/¯
-
Wednesday, December 05, 2012 6:36 PM
I've got it figured out. I still need a simple way to tell it not to execute the msgbox again until I close out the explorer window...
'Folder to Check Public Sub FolderChk do while X=0 strFolderPath = InputBox(" Parent folder ", "Please input the path to the Parent folder") If strFolderPath <> "" Then strFolderToChk = InputBox(" Folder Name to Check ", "Please input the folder to check") strmessage = "Check File Permissions on - " & strFolderPath & "\" & strFolderToChk & "?" intAnswer = _ Msgbox(strmessage, vbYesNo, "Verify Folder to Check") If intAnswer = vbYes Then strPath = "explorer.exe /e," & strFolderPath & "\" & strFolderToChk objShell.Run strPath WScript.Sleep 1000 objShell.SendKeys "+{F10}" WScript.Sleep 100 objShell.SendKeys "r" WScript.Sleep 100 objShell.SendKeys "+{tab}" WScript.Sleep 100 objShell.SendKeys "+{tab}" WScript.Sleep 100 objShell.SendKeys "{right}" WScript.Sleep 100 objShell.SendKeys "{right}" exit do else Msgbox "Folder Location Cleared" End if else Msgbox "Folder Location is Blank" End If loop End Sub do while X=0 intAnswer = _ Msgbox("Check Folder", vbYesNo, "Check a Folder?") If intAnswer = vbYes Then FolderChk else exit do end if loop -
Wednesday, December 05, 2012 6:48 PMModerator
A quick search of this forum for the term "SendKeys" yields the repeated recommendation: "Don't use SendKeys."
The security dialog is designed to be accessed via GUI. You simply cannot reliably automate what you are trying to do.
Bill
-
Thursday, December 06, 2012 2:41 PM
I understand the reasons behind the cautionary recommendations, but it seems to meet my needs and works admirably when I run the script. No users will be executing the script, and the other technician who is running it knows not to click anything else while it is checking the folder permissions. I appreciate the warning.
Now, is there a way to tell the script to wait until the explorer window has exited to continue?
-
Thursday, December 06, 2012 2:56 PMModerator
You can create a wait loop that checks for the explorer window using a modification of the approach I posted in the repository a couple of years ago ...
do until not CheckExplorerWindow(sFolderPath) wsh.sleep 50 ' milliseconds loop Function CheckExplorerWindow(sFolderPath) ' as boolean Dim wndw CheckExplorerWindow = false with createobject("shell.application") for each wndw in .windows if typename(wndw.document) = "IShellFolderViewDual2" then if lcase(wndw.document.folder.self.path) = lcase(sFolderPath) then CheckExplorerWindow = true exit for end if end if Next ' wndw end with ' shell.application End functionJust supply the appropriate folder path.
Tom Lavedas
- Marked As Answer by Bill the Cat 005 Friday, December 07, 2012 5:54 PM
-
Thursday, December 06, 2012 11:26 PM
I took this and modified it, and had some good results, then had a blue screen! ARGH!!!
Where you had:
for each wndw in .windows if typename(wndw.document) = "IShellFolderViewDual2" then
I used something else instead of the IShellFolderViewDual2 that gave me the url of the Internet Explorer and Windows Explorer open windows. Windows Explorer would display as:
file:///c:/users/me/desktop/Test
I then cleared the consecutive delimeters and split the url of the Explorer window's url and grabbed the last item in the split, which was the folder I wanted to pause the script while it was open. Was almost perfect, until the BSOD. I got it all reconstructed, except the command that gave me the open Windows Explorer url, and I can't find it on the MSDN library now... ARGH!! Anyone know what that command was?
-
Thursday, December 06, 2012 11:49 PMNow you are beginning to see the terror of SendKeys in action.
¯\_(ツ)_/¯
-
Thursday, December 06, 2012 11:53 PMHas nothing to do with sendkeys. I want to look for a specific folder and halt my script until it is closed.
-
Friday, December 07, 2012 12:17 AM
It's locationurl

