[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

lock file

Posted on 2008-10-09
22
Medium Priority
?
687 Views
Last Modified: 2012-05-05
suppose i create text /dll file with vbs script. can i lock it so that unauthorised person can not open it . pls provide code.
0
Comment
Question by:ankur3020
  • 13
  • 9
22 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 22699042
The only way you can do so with a text file is to apply NTFS security settings to the file.

For example, if you right-click the file, and go to the security tab, and apply permissions to only the Administrators group, then any user that is not a member of that group will not be able to read it.

Regards,

Rob.
0
 

Author Comment

by:ankur3020
ID: 22702660
u means there is no way to do it by coding?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22706909
Well, it *can* be done, but it still requires that you modify the NTFS permissions with a script, using a tool like SetACL.exe
http://setacl.sourceforge.net/html/examples.html

where for a specific file, you could run a command something like:

C:\Tools\SetACL.exe -on "C:\my dir\my text file.txt" -ot file -actn ace -ace "n:administrators;p:full"

Regards,

Rob.
0
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!

 

Author Comment

by:ankur3020
ID: 22708127
i think the code mentioned in link u gave are not for vbs. they are for batch file. m i right?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22708146
Yes, that's right.  These commands are run on a command line.

If you wanted to use my example command in a VBS, you'd use the below.

Regards,

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strSetACL = "C:\Tools\SetACL.exe"
strFileToSecure = "C:\My Dir\My Text File.txt"
strGroup = "administrators"
 
strSetACL = objFSO.GetFile(strSetACL).ShortPath
strFileToSecure = objFSO.GetFile(strFileToSecure).ShortPath
strCommand = strSetACL & " -on """ & strFileToSecure & """ -ot file -actn ace -ace ""n:" & strGroup & ";p:full"""
objShell.Run strCommand, 1, True

Open in new window

0
 

Author Comment

by:ankur3020
ID: 22717570
i was trying ur code. it was giving error of path not found for c:\tools\setacl.exe, do i need to download it from above link u gave before using code.? how to use this
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22717815
Yes, download setacl.exe CmdLine tool from
http://sourceforge.net/project/showfiles.php?group_id=69165

and then change the path in the code to where-ever you place the SetACL.exe file.

Regards,

Rob.
0
 

Author Comment

by:ankur3020
ID: 22751199
i tested ur code it is giving error in last line pls check it.

objShell.Run strCommand, 1, True
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22754210
Hi, the above code should work as long as these two lines

strSetACL = "C:\Tools\SetACL.exe"
strFileToSecure = "C:\My Dir\My Text File.txt"

point to file paths that already exist.  Adjust the paths so that they point to the location of the SetACL.exe file, and the path of the file whose permissions you want to modify.

If that still doesn't work, please post the description and line number of the error that you get.

Regards,

Rob.
0
 

Author Comment

by:ankur3020
ID: 22759091
still getting same error. error attached.
error.jpg
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 2000 total points
ID: 22762954
I do not get any error, and the permissions apply successfully....please try this, again, changing the paths to SetACL.exe and the file to secure.

This time you should see a DOS box that shows you the result of the SetACL.exe command.

Regards,

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strSetACL = "C:\Temp\Temp\Test Script\SetACL.exe"
strFileToSecure = "C:\Temp\Temp\Test Script\Computers.txt"
strGroup = "Power Users"
 
strSetACL = objFSO.GetFile(strSetACL).ShortPath
strFileToSecure = objFSO.GetFile(strFileToSecure).ShortPath
strCommand = "cmd /k " & strSetACL & " -on """ & strFileToSecure & """ -ot file -actn ace -ace ""n:" & strGroup & ";p:full"""
objShell.Run strCommand, 1, True
MsgBox "Done"

Open in new window

SetACL-1.jpg
0
 

Author Comment

by:ankur3020
ID: 22798346
i tried and got following attached message . i tested on vista
0
 

Author Comment

by:ankur3020
ID: 22798351
find message received
message.jpg
0
 

Author Comment

by:ankur3020
ID: 22798354
the message is saying , exe it not compatible
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22805654
Do you have 32-bit or 64-bit Vista?  Are you using the 32-bit or 64-bit Exe of SetAcl.exe?
0
 

Author Comment

by:ankur3020
ID: 22805755
i am using 32 bit and i do not know about setacl.exe.how can i check setacl.exe. i am using the downloaded file available at you specified location.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22809309
When you look at this location:
http://sourceforge.net/project/showfiles.php?group_id=69165&package_id=68032&release_id=597837

there's a
....x64.zip
file, and a
....x86.zip
file.

The x86 is the 32-bit version, so make sure you're using that one.

Is it possible for you to test this on an XP machine?  That's what I tested on....

Regards,

Rob.
0
 

Author Comment

by:ankur3020
ID: 22819240
i download as u suggested and run the attached code.i got following error.

setacl finished with error,  setacl error message : the sid for a trustee could not found. pls guide.

in the mean time i try it on xp too.
0
 

Author Comment

by:ankur3020
ID: 22819246
code tested as attached.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strSetACL = "C:\SetACL.exe"
strFileToSecure = "C:\TEST.vbs"
strGroup = "Power Users"
 
strSetACL = objFSO.GetFile(strSetACL).ShortPath
strFileToSecure = objFSO.GetFile(strFileToSecure).ShortPath
strCommand = "cmd /k " & strSetACL & " -on """ & strFileToSecure & """ -ot file -actn ace -ace ""n:" & strGroup & ";p:full"""
objShell.Run strCommand, 1, True
MsgBox "Done"

Open in new window

0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 22827447
Hi, if you're trying to add the "local" (not domain) group, called Power Users, try using the well-known SID instead...
The SIDs for common groups are here:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q243330

and the SID for Power Users is S-1-5-32-547

I have now added the following flag:
strMode = "SID"

which can be "SID" or "NAME", so the scirpt knows whether you are entering a sid or group name.

Regards,

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strSetACL = "C:\SetACL.exe"
strFileToSecure = "C:\TEST.vbs"
'strGroup = "Power Users"
strGroup = "S-1-5-32-547"
' Set strMode to "SID" or "NAME" depending on whether you're specifying a
' SID for the account / group name, or the name itself
strMode = "SID"
'strMode = "NAME"
 
strSetACL = objFSO.GetFile(strSetACL).ShortPath
strFileToSecure = objFSO.GetFile(strFileToSecure).ShortPath
If UCase(strMode) = "SID" Then
	strCommand = "cmd /k " & strSetACL & " -on """ & strFileToSecure & """ -ot file -actn ace -ace ""n:" & strGroup & ";p:full;s:y"""
Else
	strCommand = "cmd /k " & strSetACL & " -on """ & strFileToSecure & """ -ot file -actn ace -ace ""n:" & strGroup & ";p:full"""
End If
objShell.Run strCommand, 1, True

Open in new window

0
 

Author Comment

by:ankur3020
ID: 22878064
thanks it is working fine.
0
 

Author Closing Comment

by:ankur3020
ID: 31504900
thnks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month19 days, left to enroll

834 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