Access denied when using findstr windows command - windows

I'm running a windows batch file containing the following command: echo ABC | findstr A which returns Access denied when executed in a specific folder.
I copied and executed the file in any random folder and it returned the result correctly, there is one specific folder from which the execution will return access denied, I checked the Security configuration for the folder and everything is identical to the configuration of other folders, please any insights?

Related

Batch script permissions issues

I have a batch script written to auto start and capture traffic on a server for me but for some reason when I run it wireshark tells me it doesn't have permission to the folder where the script is trying to save the file. I have tried multiple different folders on and off the server I have tried giving everyone including SYSTEM full access to the folder. I have tried remaking the folder. I have tried running under and not under admin credentials I have tried letting the system task run it. Always get a permissions issue.
The weirdest part is if I run wireshark manually and save the data manually it has no permissions issues. Just if I run the script is the problem. Although they're both run under the same admin account.
Here is the script in case you need to see the flags I used.
#echo off
cd C:\Program Files\Wireshark
Wireshark.exe -i 4 -k -a duration:10 -w C:\Temp
pause
I did try to use a powershell script I had found online but it was pretty old and I couldn't get it to actually run. So any recommendations are welcome that include powershell or batch
C:\Temp isn't a file; it's a folder. Try specifying an actual filename, like this:
#echo off
cd C:\Program Files\Wireshark
Wireshark.exe -i 4 -k -a duration:10 -w C:\Temp\foo.pcapng
pause

Difference between copy /b and cat - windows refuses to execute file (self extracting archive)

I'm working on a script to package up an installer into a self extracting archive. Initially I was working on batch script using
copy /b .\7zSD.sfx + .\config.txt + .\installer.7z .\installer.exe
and the self extracting archive functioned as expected.
As the developers are working in a cygwin environment I tried converting to a bash script for this particular part using
cat 7zSD.sfx config.txt installer.7z > installer.exe
The file is properly created and can be extracted using for example winrar, yet executing results in the attached windows error:
Are there differences that I should be aware of or does somebody know of the right way to approach this?
While I did unsuccessfully try yesterday to change the permissions via the windows file properties, I did not try changing the permissions with chmod.
Checking the permissions using ls -l installer.exe revealed them as only having read/write permissions for users and groups.
My solution was to do a
chmod 770 installer.exe
to get this working.

Windows - Writing to file with `.txt` or `.zip` says Access denied

I'm trying to write data to a text file in Windows programatically (either through cmd directly or from a scripting language like Lua), but if I try to open any file with the following conditions, an error occurs, saying permission denied.
the file name ends with .txt or .zip
I try to create the file inside some subfolders of my user folder, e.g. %USERPROFILE%\Documents\**\file.txt or %USERPROFILE%\Pictures\**\file.zip.
this is done programatically (works fine using any GUI).
This happens only on Windows, and even if I run cmd with admin rights.
C:\Users\Username\Pictures>echo aaaa > a.txt
Access denied.
C:\Users\Username\Documents>echo aaaa > a.txt
Access denied.
EDIT: I noticed this was specific to subfolders of %USERPROFILE%, and not related to Lua, which the original text of this question was about. So I rewrote the question to reflect the problem properly.
I still can't find any pattern of which folders are affected by this, currently only Pictures and Documents.

Windows can access file, DOS file copy gets Access Denied

I'm trying to set up a set of folders on a Windows NT server 2008 (yes, I know, old) where a user doesn't have access to see the list of files within the folder, but can read a file if they know the full file path.
So I've set up the following AD permissions:
Permissions on the containing folder ("This folder only"):
Traverse folder / execute file
Read attributes
Read extended attributes
Read permissions
Permissions on the files ("Files only"):
Traverse folder / execute file
List folder / read data
Read attributes
Read extended attributes
Read permissions
... and from windows, everything looks great! I can't see inside the folder, but if I know the full path to a file within, I can type it into an address bar and open the file.
But when I run in Command Prompt:
COPY "FullPathToSameFileAsBefore.txt" "C:\someLocalSpot.txt"
... I get:
Access is denied.
0 file(s) copied.
Any ideas? Is there some special access Command Prompt needs to perform the copy that windows doesn't in order to read the file? Any alternatives that will work instead? I can set any of the permissions that are needed, with the caveat that the user cannot see the list of files within the directory.
EDIT with additional info:
So I tried to perform a copy with VBScript using a FileSystemObject. Same error. But using VBScript to read the file with an ADODB binary stream does work.
So it seems to boil down to "You can read this file, but you can't perform a copy." Which seems weird, since if you can read the file, you can certainly copy it (read it, then write the contents someplace else.)

How to Make Folder Only Accesible when User Run the Script

My question is how I can make one folder accessible when script running.
In this case lets call there is bob who copying his folder by using script to specific location and there is jeff who also sharing the same group as bob also he copying his file to there with using script.
The problem is that when I set file group they need write and execute permission and when I gave to them they are able to see each other file content if they know full path of the file.
To stop that I am thinking to completely deleting all permission on folder and only giving the permission when script running and doing copying process.
But problem is that when those users run the script and script try to chmod the file permission they are not going to be able to because they don't have enough permission to do it. Also if I add them on sudoers, they are going to be able to chmod and change anything as they want to change.
So I am so confused about how I can make the script change permission of folder and when copying completed turn back to previous permission
You should add a sudoers entry to allow ALL or the selected group to run a given script that does the copy to a restricted directory, with NOPASSWD to avoid the password prompt.
Then the users invoke
$ sudo /path/to/copy-to-restricted-dir files*
but users don't have access to restricted directory nor to chmod.

Resources