Solved

lock file

Posted on 2008-10-09
22
676 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
 

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 500 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now