Moey_G
asked on
How to create a folder using VB Script
Hi All,
I need to create an additional folder in the Documents folder called "SharePoint" using an existing VB script. I am pretty much new to VB , but this will be a logon script using Group Policy. I pretty much can do this using a batch file by UNC (\\servername\users$\%user name%\docu ments\Shar epoint ).
Can this be done using the existing VB Script ?
Moey
I need to create an additional folder in the Documents folder called "SharePoint" using an existing VB script. I am pretty much new to VB , but this will be a logon script using Group Policy. I pretty much can do this using a batch file by UNC (\\servername\users$\%user
Can this be done using the existing VB Script ?
Moey
I assume this are you homedrive folder for the users on a server.
Sou you could execute the following script one time directly on the server to create the sharepoint folder in each user folder:
Sou you could execute the following script one time directly on the server to create the sharepoint folder in each user folder:
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objFolder = objFSO.GetFolder("D:\Users")
'Now loop throught each user folder
For each subfolder in objFolder.SubFolders
objFSO.CreateFolder subfolder &"\Sharepoint"
Next
If you need to use the username variable you can use the ExpandEnvironmentStrings to access the username variable and use that in your folder path:
Dim objFso, ofolder
Set oShell = CreateObject( "WScript.Shell" )
user=oShell.ExpandEnvironmentStrings("%UserName%")
Set objFso = CreateObject("Scripting.FileSystemObject")
Set ofolder = objFso.CreateFolder("C:\Users\" & user & "\Sharepoint")
%USERPROFILE% delivers the full path directly ;)
ASKER
sorry for the late reply all . I have tried all the recommendations except for running the vb script on the server.
I am still unable to see the folder once I run the logon script on a test machine. Any ideas what will be the cause?
I am still unable to see the folder once I run the logon script on a test machine. Any ideas what will be the cause?
ASKER
Corrected the script which now creates the folder. Ideally , the folder needs to be created in the Documents folder which is re-directed to the File server. The script is creating a folder in the
%useprofile% folder. This is not re-directed to the server. The Documents folder is re-directed user Group Policy (\\fileserver\users$\%user name%\Docu ments ).
Any other ideas ?
Sorry merowinger , your script will need to be run everyday to make sure all users have the folder. I would prefer this to be part of the logon script.
%useprofile% folder. This is not re-directed to the server. The Documents folder is re-directed user Group Policy (\\fileserver\users$\%user
Any other ideas ?
Sorry merowinger , your script will need to be run everyday to make sure all users have the folder. I would prefer this to be part of the logon script.
this should then do it
Set objShell = CreateObject( "WScript.Shell" )
strUserProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ofolder = objFSO.CreateFolder(strUserProfile &"\Documents\Sharepoint")
ASKER
Hi merowinger,
Thank you for your help thus far. I am still not having the folder created to the right directory. When you enable Group policy for folder redirection , it creates another path pointing to the server on the network via the properties of documents on a windows 7 machine.
The above works great if you are trying to create a directory locally on the machine ie ( C:\users\%username%\Docume nts ).
I need the vb script to create a folder on the network (\\fileserver\users$\%user name%\Docu ments ).
Apologies if I have not explained this clearly.
Thank you for your help thus far. I am still not having the folder created to the right directory. When you enable Group policy for folder redirection , it creates another path pointing to the server on the network via the properties of documents on a windows 7 machine.
The above works great if you are trying to create a directory locally on the machine ie ( C:\users\%username%\Docume
I need the vb script to create a folder on the network (\\fileserver\users$\%user
Apologies if I have not explained this clearly.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works a treat !!! Thanks for all your help.
Function CreateFolderDemo
Dim fso, f
Set fso = CreateObject("Scripting.Fi
Set f = fso.CreateFolder("c:\New Folder")
CreateFolderDemo = f.Path
End Function
Reference is here:
http://msdn.microsoft.com/en-us/library/7kby5ae3(v=VS.85).aspx
~bp