Link to home
Start Free TrialLog in
Avatar of New_Alex
New_AlexFlag for Cyprus

asked on

VBscript, Win7, FSO.CreateTextFile, Where is my Newly Created File?

Hi guys, I have Windows7 installed on my PC and my vbScript includes a Sub that attempts to create a new settings.ini file (with my program's settings) inside the "c:\program files\".

This is my code:

Sub CreateMyFile()

    Set oFSO = CreateObject("Scripting.FileSystemObject")
       
          sFilePath = "C:\Program Files\Vbsedit\settings.ini "
            Set FileObject = oFSO.CreateTextFile(sFilePath)
	      FileObject.WriteLine "Hello World"
	          FileObject.Close()

End Sub

Open in new window


The code does not give an error but I can not find the file "C:\Program Files\Vbsedit\settings.ini ". It is not get created.  Any ideas how I can make it work in folders like "C:\Program Files\" ???
Thank you
Avatar of rajvihari
rajvihari
Flag of India image

Could you please check with your user id has admin rights ?
Also check with :
Disable simple file sharing: in explorer, go to the 'Tools' menu and select 'Folder Options'. Select the 'View' tab and scroll to the bottom. Untick 'Use simple file sharing (recommended)'.

Right click on the 'Program Files' folder and select 'Properties'. Go to the 'Security' tab and select 'Advanced'. You can check the permissions of the admin account under 'Effective Permissions'.

If the admin account does not have 'full control' of the folder:

1) Check what permissions the admin user has in the 'Permissions' tab. In fact, the user name should not be present here at all. The only entries here should be for Administrators, CREATOR OWNER, System and Users. If the admin account is listed here with permissions other than 'Full control' you can either edit them to give the user full control or delete the restricting permissions all together.

2) Go to the 'Owner' tab, and verify which user or group is the owner of the folder. This should probably be set to Administrators. If not, select Administrators and apply.
Avatar of New_Alex

ASKER

Hi guys, is it possible to do it using vbScript, because I plan to share the code freely to many people.
ASKER CERTIFIED SOLUTION
Avatar of X Layer
X Layer
Flag of Slovenia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes. This is a good idea

Thanks matey
As suggested, it is restricted, but if the script is running with admin rights, it should work.

If you run cmd.exe by right clicking, then Run As Administrator, then type
cscript C:\YourScript.vbs

Rob.