Hi,

i am currently wanting to create a VBS script that will do the following in this order:

run gpedit.msc then close
delete the default user folder in "c:\documents and settings"
delete the gpedit folder in "c:windows\system32"

copy the "default user" folder from my "memory stick" to the "documents and settings" folder (bearing in mind the drive letter will change as it is removable, however the location on the folder it is copying will always be in the same directory as the script its self on the memory stick.)

copy the "gpedit" folder from the memory stick into the "C:\windows\system32\" folder (bearing in mind the drive letter will change as it is removable, however the location on the folder it is copying will always be in the same directory as the script its self on the memory stick.)

copy a "boot.ini" file to the "c:\ directory"


if anyone has any lines of code i could use to create this or is willing to help i would be most appreciative

Thanks in advance

Elise

Personally, I'd go after building something like this with a tool like full-fledged VB (instead of vbscript), as VB gives you better control, and would simplify some of the tasks at hand. I believe It can, however, be done in VBS....

1) I don't know if gpedit.msc goes through any kind of a setup process, window, or anything like that, since I'm on XP home (home doesn't have gpedit). So, I need to know if there is a window that comes up, and if it requires any button presses or anything like that.

2) What do you mean by: the default user folder in c:\documents and settings? Is this actually a folder called "default user" or are you refering to the "currently logged in" user?

3) is the "default user" folder that is on your memory drive on the root, and is it called "default user"?

4) is the "gpedit" folder that in on your memory drive on the root?

5) is boot.ini on the root of your memory drive?

Personally, I'd go after building something like this with a tool like full-fledged VB (instead of vbscript), as VB gives you better control, and would simplify some of the tasks at hand. I believe It can, however, be done in VBS....

1) I don't know if gpedit.msc goes through any kind of a setup process, window, or anything like that, since I'm on XP home (home doesn't have gpedit). So, I need to know if there is a window that comes up, and if it requires any button presses or anything like that.

2) What do you mean by: the default user folder in c:\documents and settings? Is this actually a folder called "default user" or are you refering to the "currently logged in" user?

3) is the "default user" folder that is on your memory drive on the root, and is it called "default user"?

4) is the "gpedit" folder that in on your memory drive on the root?

5) is boot.ini on the root of your memory drive?

thanks for the response, ill answer your questions.

1 - For the gpedit i just need to run it once as windows will then create the gpedit folder, when it runs a window opens then all i need to do is immedietly close it. I run it simply to allow windows to create the folder.

2 - The default user is a actual folder in the "c:\documents and settings\" directory on windows xp home and prof. You just need to unhide hidden folders to see it.

3 - yes

4 - yes

5 - yes

A vbscript would do the job, probably sloppy but i am not a coder/programer by nature, more support. However i am trying to simplify aspects of my current role by making my job easier and quicker. I like the sound of a fully fledged VB prog but i would have no idea where to begin and i think a script would be easier. However it sounds like you know far more in excess of i in terms of coding etc and would be most appreciative of your help.

Ill pm you my SKYPE username so if you want to talk and exchange advice in real time we can. If there is any areas i can help you in also dont hesitate to ask... As long as its not how to code.. ;)

Thanks again hope i can get something working it would shave at least 1hr per master clone i create if i can get the whole process complete. The worst thing is because i have no programing/coding skills and there is no part of my job that requires it it makes it difficult to fit learning a programing lanauge in.

Thanks again for the help, hopefully we can get something sorted

Hi C~

Have went over the above text again and compiled a step by step of what i need the script to do.


run
gpedit.msc then close gpedit immedietly.

delete the default user folder in "c:\documents and settings\"

delete the gpedit folder in "c:windows\system32\"

Copy over the "all users" folder from the mem key to "c:\documents and settings"

Copy the "default user" folder from my "memory stick" to the "c:\documents and settings\" folder (bearing in mind the drive letter will change as it is removable, however the location on the folder it is copying will always be in the same directory as the script its self on the memory stick.)

Copy the "gpedit" folder from the memory stick into the "C:\windows\system32\" folder (bearing in mind the drive letter will change as it is removable, however the location on the folder it is copying will always be in the same directory as the script its self on the memory stick.)

copy a "boot.ini" file to "c:\" from the root of my mem stick. (or if this is at all possible, to be able to change the attributes of the pc's boot.ini by making it not read only, them opening the document in notepad and changing all instances of the number 3 to the number 1) WOW :eek: i wouldnt know where to begin. That would be amazing if that was at all possible.

Then

create 3 NEW folders on "c:\" "temp" "ccs" and "airlock"


run a regfile called "classic search.reg" located on the root of the mem stick (same place as boot.ini etc..." by running this
windows will by default ask you if you wish to enter this file to the regestry. I need the script to "press enter or yes" to allow this
information to be added.


Reboot pc

:eek:

Seriously if that was possible and you helped me with that i would be in your debt. A file like that would save hundreds of man hours for me and other IT guys in my company.

I would not be able to create a file like this withiout taking time to research VBS indepth, however with your help i can get the file and research the common aspects of the file and possible be able to do something similar in the future.

Talk to you soon,

And thank you again for helping me on this one. You should also add in some cheeky advertising in the file somewhere and ill post it on our internal intranet .

I'm not 100% sure if this is exactly what you need... if there are any troubles with the code, just let me know, and I'll see if I can't correct them, but give this a shot. Copy This code into the VBS File (whatever you want to name it).

' /* Declare Variables */
dim wsh
dim fso

' /* Get current App Path, And Drive Letter */
MyPath =  WScript.ScriptFullName
ThisDrive = left(MyPath, 1) & ":"

' /* Get Shell Object */
set wsh = createobject("WScript.Shell")

' /* Get File System Object */
set fso = CreateObject("Scripting.FileSystemObject")

' /* Launch The Program In Question (Change The First 1 to 0 to hide the window) Change This to: gpedit.msc*/
wsh.Run "gpedit.msc"

' /* Wait 1/2 a Second */
WScript.Sleep 500

' /* Make The Currently Active Window */
ret = wsh.appactivate("Group Policy")

' /* Wait 1/2 a Second */
WScript.Sleep 500

' /* Close The Active Window */
wsh.SendKeys "%{F4}"

' /* If The folder Exists */
if fso.FolderExists("C:\documents and settings\all users") then
	' /* Get The Folder, And Change the Attributes To Normal */
	Set fld = fso.GetFolder("C:\documents and settings\all users")
	fld.Attributes = 16

	' /* delete the default user folder in "c:\documents and settings" */
	fso.DeleteFolder "C:\Documents and Settings\all users", 1
end if

' /* delete the gpedit folder in "c:\windows\system32" */
if fso.FolderExists("C:\windows\system32\gpedit") then
	' /* Get The Folder, And Change the Attributes To Normal */
	Set fld = fso.GetFolder("C:\windows\system32\gpedit")
	fld.Attributes = 16

	' /* delete the gpedit folder in "c:\windows\system32" */
	fso.DeleteFolder "C:\windows\system32\gpedit", 1
end if

' /* Copy All Users Folder To "c:\documents and settings" */
fso.CopyFolder ThisDrive & "\all users","c:\documents and settings\", 1

' /* Copy default User Folder To "c:\documents and settings" */
fso.CopyFolder ThisDrive & "\default user","c:\documents and settings\", 1

' /* Copy gpedit Folder To "c:\windows\system32" */
fso.CopyFolder ThisDrive & "\gpedit","c:\windows\system32\", 1

' /* Check If c:\temp exists, if not, create it */
if Not fso.FolderExists("C:\temp") then
	fso.CreateFolder "C:\temp"
end if

' /* Check If c:\ccs exists, if not, create it */
if Not fso.FolderExists("C:\ccs") then
	fso.CreateFolder "C:\ccs"
end if

' /* Check If c:\airlock exists, if not, create it */
if Not fso.FolderExists("C:\airlock") then
	fso.CreateFolder "C:\airlock"
end if

' /* Import "classic search.reg" Into The Registry */
wsh.Run "regedit /s " & ThisDrive & "\classic search.reg", 0, 1

' /* Copy Boot.ini to C:\ */
Set file = fso.GetFile("C:\boot.ini")
file.Attributes = 0
fso.CopyFile ThisDrive & "\boot.ini", "c:\boot.ini", 1
file.Attributes = 6

wsh.Run "shutdown -r -t 2", 0, 0

I MAY have to build you an EXE to do everything that you want, but I'm hoping that this method will for you. Let me know.

Fantastic,

That works perfectly. Thank you so much.

There are a few little problems but i can research
and try and fix them (not with your code just to get it optimised for my pc's),

amazing piece of code. Im very very grateful.

Would it be possible to edit the end of the file so that instead of copying over the boot.ini, it actually opens it looks for the text saying timeout=30 and replaces it for timeout=10?

Im doing some research now and trying to see if i can figure it out.. (ohh dear..:))

I did however manage to add a few extras into the script, i put the attributes of the files\folders back to what they were after the folders are copied over, (i just copied your code and changed from 16 to 2) hope thats right, it seems to hide them so i hope it aint doing anything bad.

Its great having a piece of code like this because i can now learn this code and how to do these things directly, you can not understand how helpful you have been. Im not blowing smoke up your ass, i am just very appreciative of your help.

what i am worried about is it seems to run the program and reboot the pc quicker than it takes me to copy the files from the memory stick to the local machine,
for example, it takes 10 seconds for the script to do its job...

but if i just go into the memory stick and copy the folders they alone take over 20 seconds? any ideas?

Sure, I'll work on editing the boot.ini instead of coping it over. 2, should be the correct number for files, but for folders, I think it's 18... I could be mistaken. I know the default for "no attributes" for a directory is 16. Have you checked to see that the files have copied over correctly and totally, before the reboot takes affect? If not, I'll have to find a different way to copy the files over (maybe using wsh.run), Which also won't be a problem.

When writing code (for other people), I always comment the code. This way, you get an understand of exactly what I've done line for line. I find, also, that commenting code this way, also gives me a better understand of the code I write. I'm glad that I could be of help, and if you need assitance with other matters, just ask. Let me know what you come up with, by way of the copy process (does it copy everything totally and correctly), and if it does not, I'll work on a solution.

ill go over files copied and see exactly what was copied. It does seem to work correctly, just seems really fast. (Not complaining.) :)

Yeah the comments were very helpful, by doing it that way i almost feel confident that i could ammend similar pieces of code to do similar jobs.. This has taught me more, in a shorter period of time.

I am currently working on a master clone pc now, so i will give the code a test on that machine and see how it works in the field. And repost back any changes made or needed.

I feel like you have helped me out immensley and i have done nothing in return, so again i will say thanks for the help.

Ill let you know exactly how much time this actually saves me out in the field as well, because all we need do now is,

install windows, install client, run code, install programs, issue.

normally, its install windows, install client, set up default user account and settings, create folders, ammend boot files and system settings, input gpedit...blah blah blah blah..... the process eats away minutes than soon leak into hours.

Ill do this clone and update you with the progress.

Thanks again

Talk soon

Ok, here is the modified VBS File (without any changes that you made to the other [since I don't have them]) so that it updates the boot.ini file, instead of copying it over from the memory stick. here is the modified VBS File in it's entirety:

' /* Declare Variables */
dim wsh
dim fso

' /* Get current App Path, And Drive Letter */
MyPath =  WScript.ScriptFullName
ThisDrive = left(MyPath, 1) & ":"

' /* Get Shell Object */
set wsh = createobject("WScript.Shell")

' /* Get File System Object */
set fso = CreateObject("Scripting.FileSystemObject")

' /* Launch The Program In Question (Change The First 1 to 0 to hide the window) Change This to: gpedit.msc*/
wsh.Run "gpedit.msc"

' /* Wait 1/2 a Second */
WScript.Sleep 500

' /* Make The Currently Active Window */
ret = wsh.appactivate("Group Policy")

' /* Wait 1/2 a Second */
WScript.Sleep 500

' /* Close The Active Window */
wsh.SendKeys "%{F4}"

' /* If The folder Exists */
if fso.FolderExists("C:\documents and settings\all users") then
	' /* Get The Folder, And Change the Attributes To Normal */
	Set fld = fso.GetFolder("C:\documents and settings\all users")
	fld.Attributes = 16

	' /* delete the default user folder in "c:\documents and settings" */
	fso.DeleteFolder "C:\Documents and Settings\all users", 1
end if

' /* delete the gpedit folder in "c:\windows\system32" */
if fso.FolderExists("C:\windows\system32\gpedit") then
	' /* Get The Folder, And Change the Attributes To Normal */
	Set fld = fso.GetFolder("C:\windows\system32\gpedit")
	fld.Attributes = 16

	' /* delete the gpedit folder in "c:\windows\system32" */
	fso.DeleteFolder "C:\windows\system32\gpedit", 1
end if

' /* Copy All Users Folder To "c:\documents and settings" */
fso.CopyFolder ThisDrive & "\all users","c:\documents and settings\", 1

' /* Copy default User Folder To "c:\documents and settings" */
fso.CopyFolder ThisDrive & "\default user","c:\documents and settings\", 1

' /* Copy gpedit Folder To "c:\windows\system32" */
fso.CopyFolder ThisDrive & "\gpedit","c:\windows\system32\", 1

' /* Check If c:\temp exists, if not, create it */
if Not fso.FolderExists("C:\temp") then
	fso.CreateFolder "C:\temp"
end if

' /* Check If c:\ccs exists, if not, create it */
if Not fso.FolderExists("C:\ccs") then
	fso.CreateFolder "C:\ccs"
end if

' /* Check If c:\airlock exists, if not, create it */
if Not fso.FolderExists("C:\airlock") then
	fso.CreateFolder "C:\airlock"
end if

' /* Import "classic search.reg" Into The Registry */
wsh.Run "regedit /s " & ThisDrive & "\classic search.reg", 0, 1

' /* Edit Boot.ini's Timeout Line */
call edit_bootini("c:\boot.ini")

wsh.Run "shutdown -r -t 2", 0, 0


sub edit_bootini(bootpath)
	dim objFileSystem
	' /* Get The File System Object */
	set objFileSystem = createobject("Scripting.FileSystemObject")

	' /* Get The file Object (For Properties) */
	Set file = objFileSystem.GetFile(bootpath)

	' /* Set The File's Attributes To Normal (not system, hidden, or read only) */
	file.Attributes = 0

	' /* open bootpath (path to boot.ini, passed to sub from calling procedure) for reading */
	Set objInputFile = objFileSystem.OpenTextFile(bootpath, 1)

	' /* Read In the Entire file, and rip it apart by the newline character, storing it in an array */
	inputData = Split(objInputFile.ReadAll, vbNewline)

	' /* Set Our Counter Variable to 0 */
	cnt = 0
	
	' /* For Each Element In our Array (for each line of the file) */
	For each strData In inputData
	
		' /* If the first 7 characters of this line of the file is "timeout" then */
		if left(lcase(strData), 7) = "timeout" then
			' /* change This Array's Value (This Line of the file) */
			inputData(cnt) = "timeout=10"
		end if	

		' /* Add One to Our Counter Varaible */
		cnt = cnt + 1
	Next

	' /* Close The File, No changes have been to the file, only to the array (variable) that holds the lines of the file */
	objInputFile.Close

	' /* Create An Object To overwrite the file indicated by bootpath */
	Set objOutputFile = objFileSystem.CreateTextFile(bootpath, TRUE)

	' /* For each element in our array (each line of the file, Modified from original) */
	for each strData in inputData
		' /* Write That Line to The File */
		objOutputFile.WriteLine strData
	next 

	' /* Close the File (now saved with new changes) */
	objOutputfile.Close

	' /* Set The file To system and hidden attributes */
	file.Attributes = 6

	' /* Clear The File System Object */
	Set objFileSystem = Nothing
end sub

Just a reminder, the changes that you made, to the previous VBS are not intact on this one. Let me know how it turns out.

Wow :)

For lack of a better work........

I will take that and try it and let you know how it works.... I have to admit that i understood some of the code, but wow, that edit of the boot ini file must have take you ages, that is way beond my comprehension.

i just added the boot.ini edit part to the end of the slighly edited version and ill test it on another machine i have to do tomorrow.

Again thankyou very much indeed, ill certainly keep you posted as to whats going and how it works, whats weird is, i'm looking forward to tomorrow to test it out.. :) .. haha.. not very often i an exited about creating a master clone.

So far though i believe that this whole process has saved over 1hr or my time per master clone. That is a massive amount of time per person, per clone. I am very very happy with the end result.
If there is anything i can possibly do to help you anytime please just let me know and i will most certainly do all i can.

another cheeky little question.. ;)
Is there a way i can give a file more than 1 attribute and do you know of a resource so i can copy what all the numbers mean?

for example, can i give a folder, system, read only, hidden attributes all at the same time?

Ill create the clone tomorrow and pop over the all the details of how the new part worked... again very impressed with your coding skills and the speed and acuracy in which you were able to execute my request.

Thanks again C~

See you tomorrow.

http://www.windowsitpro.com/Files/07/8389/Table_02.html
http://www.windowsitpro.com/Files/07/8184/Table_01.html

are links to a pages of numbers relevant to files and folders.... you just add. So, system, being 4, and hidden being 2, means setting attributes to 6 makes it system and hidden. 7 would be system, hidden, and read only. With folders, if base is 16, that would be the equivelent of 0. So 17 should be a read only folder. Let me know how things work with that script. I'm going to mark this thread as solved (I'm guessing the copy went over correctly). :)

Yeah everything is perfect,

Tried, tested and running flawlessly.

A great time saver.

Thanks again C~ i couldnt have paid someone for a better response. Ill try not to bug you to much with any other problems.

Great Response,
Great Resolution,
Great Work.

I now have a much easier time when having to create boring master clones.

For anyone else, just copy and paste the code on screen posted bt C~ and make the slight ammendments for your systems etc... and it will work flawlessley. Id be surprised if this doesnt come in hand for any other I.T folk!

Take it easy,

Ill hang around and see if i can help someone as much as C~ has helped me..... Just not a VBS script question... ;)

Elise

It's my pleasure to help Elise. Don't hesitate to ask if you have further questions or need additional assistance, and certainly don't feel as though you are bother, since nothing is futher from the truth. Helping the I.T. Community is the best part of my day. I'm glad I could help you out. Hope to help you out again soon ;)

This question has already been answered. Start a new discussion instead.