We help IT Professionals succeed at work.

Windows 7 Run VBS script to hide file and folders as administrator

DC10 asked
Hi there, i need some help, i am working on a project, where we need to restrict some access to file and folders, that is default install on Windows 7.

So fare i know that the vbs has to run as administrator on the local PC, i have found a old sribt that will handle the job of hiding the files

To hide files simply use this code
Dim FS, F
Set FS = CreateObject("Scripting.FileSystemObject")
Set F = FS.GetFile(%FILEPATH%) 'Replace %FILEPATH% with the files path
F.Attributes = -1 ' -1 Makes it a system file so its hidden from windows explorer(works for me on xp)

But now i need it to run as administrator, because windows 7 dont give access to normal user to change the path.

Anyone know how to handle this ???
Watch Question

Hold the Shift key and then right click the script. Then select "Run As Administrator"

You can do this from the Command Line to by pathing to the script and using the RunAs command. Using the GUI is the easiest way if you aren't familiar with the Command Line.


Well its not that, this is going to run whit GPO.

What i need help whit is a way for me to run the script in the top, as admin on the 1000 PC, whitout giving the user admin rights.

The user will not have any adminrights at all.
You can modify the script to run on your machine and modify the system remotely. Therefore, assuming you have admin rights on the boxes that you are modifying, passthrough authentication would cause the script to run with your credentials. The attached code script may help give you a starting point type example, although I admit it is just a quick and dirty script.
Dim objFSO
Dim strFolderToHide
Dim strFileToHide
Dim strServerPath
Dim objFolder
Dim objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
strServerPath = "\\%machineName%\"
strFileToHide = "someFile.txt"
strFolderToHide = "someFolder"

Set objFile = objFSO.GetFile(strServerPath & strFileToHide)
objFile.Attributes = -1

Set objFolder = objFSO.GetFolder(strServerPath & strFolderToHide)
objFolder.Attributes = -1

Open in new window


thanks some of the code works, but i can use it.