Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Guimenez

vbs script to change documents paths do another location

Recommended Posts

Hi everyone

i'm searching on the net without any result :(

i'm trying to create a vbs script that change the default documents folder do another location (ex: d:)

i need this to work in XP,Vista and Seven

Can anyone help me on this

many thanks

Share this post


Link to post
Share on other sites

Post moved to more appropriate location, (than Windows XP Forum).

i'm trying to create a vbs script that change the default documents folder do another location (ex: d:)

i need this to work in XP,Vista and Seven

Can anyone help me on this

What have you got so far, we have no idea what you've tried or which part you need help with

Share this post


Link to post
Share on other sites

The user's folderroot is declared in the %USERPROFILE% variable, but you can

change the My Documents-folder in the registry manually with the keys at:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders

If (and how) this can be done with VBS... I don't know, I'm a programmer not

script-kiddie :rolleyes:

Greetz,

Peter.

Share this post


Link to post
Share on other sites

Hi, thanks for replying

i've made the script now and its working

the main problem its that sometimes a need to move to another location that its not D:

i need to make a question to choose destination folder that can be D:, E: or F:

and then it will copy to destination choose by the user

this is my code


if MsgBox("Do you want to change documents folder to drive D:", vbYesNo) = vbYes then
msgbox "verify that D: its formatted"
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.FolderExists("d:\os meus documentos") then
else
set f = fso.CreateFolder("d:\Os meus documentos")
End if
if fso.FolderExists("d:\os meus documentos\As minhas imagens") then
else
set f = fso.CreateFolder("d:\Os meus documentos\As minhas imagens")
End if
if fso.FolderExists("d:\os meus documentos\A minha m˙sica") then
else
set f = fso.CreateFolder("d:\Os meus documentos\A minha m˙sica")
End if
if fso.FolderExists("d:\os meus documentos\Os meus vÌdeos") then
else
set f = fso.CreateFolder("d:\Os meus documentos\Os meus vÌdeos")
End if
WshShell.RegWrite"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal", "D:\OS MEUS DOCUMENTOS"
WshShell.RegWrite"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Pictures", "D:\OS MEUS DOCUMENTOS\AS MINHAS IMAGENS"
WshShell.RegWrite"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Music", "D:\OS MEUS DOCUMENTOS\A MINHA M⁄SICA"
WshShell.RegWrite"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Video", "D:\OS MEUS DOCUMENTOS\OS MEUS VÕDEOS"
else
End if

many thanks

Share this post


Link to post
Share on other sites

This doesn't do what you requested!

It only changes the references in the registry and creates directories if they don't exist. (If the directories do exist should you not move the contents to the new location too?)

The script is only using a specific language, meaning that it is useless for people using a different language version of Windows.

Also you've requested it to be suitable for XP, Vista and 7; however in Vista and 7; Music, Pictures and Videos are not found as subdirectories of the Documents directory.

I would also suggest that you think about using a directory structure beneath the Users Name in your new location, i.e. X:\UserName\DocsFolderName

Share this post


Link to post
Share on other sites

If (and how) this can be done with VBS... I don't know, I'm a programmer not

script-kiddie :rolleyes:

Very nice of you for us (rather oldish) "script-kiddies".

Since you are a programmer, why not showing it? :unsure:

Please post the source code AND the compiled version of an utility capable of doing this in (your choice):

  1. C
  2. C+
  3. C++
  4. C#
  5. Delphi

You have exactly 8 (eight) minutes from now, or you may take notice, once and for all, that for simple tasks, simple approach is faster.

It would take to this "script-kiddie" far less than 5 minutes to write a batch for it (2K/XP only), but I am giving you a fair advantage. ;)

Tick... tick...tick...

jaclaz

Edited by jaclaz

Share this post


Link to post
Share on other sites

Thanks for replying

this script works with all language. The only thing that need to be modified

is the name of the destination folder.

I want to change the location even if the folder exists. I think i need

to Make some chances on this.

This script can be better but i'm not a great programmer

i'm just trying to make this working :) but the last

steps to make the user choose the destination folder its getting complicated for me

i know that windows vista/7 have diferent struture folder but i prefer join all

user folders in the same dir. Like Windows XP

this script os working and i'm testing it a little more

can anyone help me on this?

This script is very usefull because i format and install Windows for

about 10 times in a day and i need to change every time the documents

folder do another partition

thanks

Edited by Guimenez

Share this post


Link to post
Share on other sites

Here try this VBS script, Inputbox to get a drive letter.


Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
'-> Array To Hold The Reg Keys And Users Folders
Dim Loc :Loc = Array( _
"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal - os meus documentos", _
"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Pictures - os meus documentos\As minhas imagens", _
"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Music - os meus documentos\A minha m`sica", _
"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Video - os meus documentos\Os meus vÌdeos")
'-> Varibles For The Script
Dim A1, A2, Dir, Obj
If MsgBox("Would you like to change your Users Folder to another Drive", 4132,"Change User Profile") = 6 Then
DrvLetter()
End If
'-> Loop Threw Inputbox To Get Drive Letter
Function DrvLetter()
A1 = InputBox( _
"Type in the drive letter that you want to use." & vbCrLf & _
"To end this dialog, just type Quit or Exit." & vbCrLf & _
"EXAMPLE : D:\ Or E:\")
'-> Loop While Waiting For Drive Letter
Do While A1 = ""
If A1 = "quit" Or A1 = "exit" Then
WScript.Quit(0)
End If
Loop
'-> Check To Make Sure :\ This In The String And A Or B Is Not Used As Drive letter
If InStr(1,A1,"a",1) Or InStr(1,A1,"b",1) Then
MsgBox "Error A Or B Is Not A Valid Drive Letter" , 4128,"Error 1"
DrvLetter()
ElseIf InStr(A1,":\") Then
'-> Check To See If Drive Exists
If Fso.DriveExists(A1) Then
Work()
Else
MsgBox "Drive Does Not Exists", 4128,"Error 2"
DrvLetter()
End If
Else
MsgBox "Error No :\ Was Found", 4128,"Error 3"
DrvLetter()
End If
End Function
'-> Function That Splits The Array Contents
'-> And Then Makes The Needed Folders And
'-> Add The New Registry Changes
Function Work()
For Each Obj In Loc
A2 = Split(Obj," - ")
Dir = A1 & A2(1)
If Not Fso.FolderExists(Dir) Then Fso.CreateFolder(Dir)
Act.RegWrite(A2(0),Dir)
Next
End Function

VideoRipper, on 16 March 2010 - 12:40 AM, said:

If (and how) this can be done with VBS... I don't know, I'm a programmer not

script-kiddie

Very nice of you for us (rather oldish) "script-kiddies".

Since you are a programmer, why not showing it?

Please post the source code AND the compiled version of an utility capable of doing this in (your choice):

1.C

2.C+

3.C++

4.C#

5.Delphi

:thumbup

I would like to see this also, being that your a programmer.

Here is a HTA version of the above script

Save As ProLocChange.hta


<TITLE>Change Music, Personal, Pictures, Video </TITLE>
<HTA:APPLICATION
Id="ChangeLoc"
APPLICATIONNAME="LocChange"
SCROLL="no"
SINGLEINSTANCE="yes"
SELECTION="NO"
CONTEXTMENU = "NO"
BORDER="Thin"
BORDERStyle = "Normal"
INNERBORDER = "YES"
MAXIMIZEBUTTON = "NO"
MINIMIZEBUTTON = "NO"
SYSMENU = "NO">
<STYLE Type='text/css'>
Body
{
Font-Size:12.25pt;
Font-Weight:Bold;
Font-Family:Segoe Ui, Lucida Console, Arial, Tahoma, Comic Sans MS;
Color:Black;
BackGround-Color:Transparent;
Filter:progid:DXImageTransform.Microsoft.Gradient
(StartColorStr='#ece6e0',EndColorStr='#c0bab4');
Margin-Top:1;
Margin-Bottom:1;
Margin-Left:4;
Margin-Right:4;
Padding-Top:1;
Padding-Bottom:1;
Padding-Left:4;
Padding-Right:4;
Text-Align:Center;
Vertical-Align:Top;
Border-Top:0px Transparent;
Border-Bottom:0px Transparent;
Border-Left:0px Transparent;
Border-Right:0px Transparent;
}
.Txt
{
Font-Size:8.25pt;
Font-Weight:Bold;
Font-Family:Segoe Ui, Lucida Console, Arial, Tahoma, Comic Sans MS;
Margin-Left:1;
Margin-Right:1;
}
BUTTON
{
Width:71pt;
Height:14pt;
Cursor:Hand;
Font-Size:8.25pt;
Font-Weight:Bold;
Font-Family:Segoe Ui, Lucida Console, Arial, Tahoma, Comic Sans MS;
Color:#001137;
Text-Align:Center;
Vertical-Align:Middle;
Filter:progid:DXImageTransform.Microsoft.Gradient
(StartColorStr='AliceBlue',endColorStr='LightSlateGray');
Border-Top:0px Transparent;
Border-Bottom:0px Transparent;
Border-Left:0px Transparent;
Border-Right:0px Transparent;
Padding-Top:0;
Padding-Bottom:2;
Padding-Left:0;
Padding-Right:0;
Margin-Top:1;
Margin-Bottom:1;
Margin-Left:1;
Margin-Right:1;
BackGround-Color:Transparent;
}
.B1
{
Color:#003711;
Filter:progid:DXImageTransform.Microsoft.Gradient
(StartColorStr='#BAEABA',endColorStr='#226644');
}
</STYLE>
<script LANGUAGE='JScript'>
window.resizeTo (425,201)
window.moveTo(screen.availWidth / 2 - (472/2),screen.availHeight / 2 - (267/2));
var Act = new ActiveXObject("Wscript.Shell");
var Fso = new ActiveXObject("Scripting.FileSystemObject");
</SCRIPT>
<script language="VBScript">
'-> Array To Hold The Reg Keys And Users Folders
Dim Loc :Loc = Array( _
"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal - os meus documentos", _
"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Pictures - os meus documentos\As minhas imagens", _
"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Music - os meus documentos\A minha m`sica", _
"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Video - os meus documentos\Os meus vÌdeos")
Function Work(Drv)
If Drv = "" Then
alert("Please Input A Drive Letter" & vbcrlf & "Error Number 1")
ElseIf InStr(1,Drv,"a",1) Or InStr(1,Drv,"b",1) Then
alert("Error A Or B Is Not A Valid Drive Letter" & vbcrlf & "Error Number 2")
ElseIf InStr(Drv,":\") Then
'-> Check To See If Drive Exists Then Do The Work
If Fso.DriveExists(Drv) Then
Dim A1, Dir, Obj
For Each Obj In Loc
A1 = Split(Obj," - ")
Dir = Drv & A1(1)
If Not Fso.FolderExists(Dir) Then Fso.CreateFolder(Dir)
Act.RegWrite A1(0),Dir
Next
Else
alert("Drive Does Not Exists" & vbcrlf & "Error Number 3")
End If
Else
alert("Error No :\ Was Found" & vbcrlf & "Error Number 4")
End If
End Function
</SCRIPT>
<BODY Scroll='No'>
<TABLE Style='Margin-Top:3;Margin-Bottom:5;'>
<TD CLass='Txt'>Change User Music, Personal, Pictures, Video Drive Location</TD></TABLE>
<TABLE><P CLass='Txt'>
Type In The New Drive Letter To Set The New Location<BR>Correct EG D:\ Or E:\<BR>Wrong EG D, E Or D:, E:<BR>
<TD><INPUT Type='Text' Name='DR' Size='3' Class='Txt'></TD>
<TD><BUTTON ID='Btn01' OnMouseOver="this.className='B1'" OnMouseOut="this.className=''" OnClick='Work(DR.value)'>Change</BUTTON></TD>
</P></TABLE>
<TABLE Style='Margin-Top:12pt;'>
<BUTTON ID='Btn02' OnMouseOver="this.className='B1'" OnMouseOut="this.className=''" OnClick='window.close();'>Close</BUTTON>
</TABLE>
</BODY>

Share this post


Link to post
Share on other sites

Very nice of you for us (rather oldish) "script-kiddies".

Since you are a programmer, why not showing it? :unsure:

Please post the source code AND the compiled version of an utility capable of doing this in (your choice):

  1. C

  2. C+

  3. C++

  4. C#

  5. Delphi

You have exactly 8 (eight) minutes from now, or you may take notice, once and for all, that for simple tasks, simple approach is faster.

It would take to this "script-kiddie" far less than 5 minutes to write a batch for it (2K/XP only), but I am giving you a fair advantage. ;)

Tick... tick...tick...

jaclaz

The way I see it is, he has too high of a self-esteem to use the industry standard way to do this (vbscript or powershell or even jscript -- batch files would also be usable as well as autoit and several others) because that's too lowly for him, and he would rather waste his employer's valuable time to write a fancy program for something so trivial instead, basically so he can feel good about himself. I very well could be wrong (hopefully I am), but it does sound quite like that to me.

Out of that list, I could do it in C++ and C# as many, many others could (it's not exactly hard -- nothing worth patting yourself on the back for). I still wouldn't do that as it would be a pointless, massive waste of time. There is nothing gained by doing it that way (both would execute ~instantly, using very little resources), and it would be an unnecessary pain to maintain e.g. other employees who might have to make changes might not know C++ or whatever, or might not have ready access to a suitable compiler, etc. The script can easily be edited by anyone with plain old text editor, in very little time, using minimal knowledge, works out of the box and all that. It's simply quicker, more effective, easier and better overall.

Share this post


Link to post
Share on other sites

thanks for the help and the script.

when i save the script in notepad and save it as vbs(like i always do)

when i run it gives me an error on the line 51 character 28

it says "its not possible to use brackets while calling a function"

but the character 28 it doesn't exist!!!

many thanks once again

Share this post


Link to post
Share on other sites

Which script?

Surely not this one!

Save As ProLocChange.hta

Share this post


Link to post
Share on other sites

Well... I feel insulted :realmad:

Nah... just kidding :P

It's a pity I didn't notice the bashing @ my person earlier, because now the 8 minute

limit of jaclaz has passed a long time :(

But be honoust: even if you would write a script instead of using a programming language (I use

Delphi BTW), it's not the scripting that takes much time, but the research up front and testing

and tweaking afterwards.

Typing the code (like the vbs-script given by Guimenez or the one by SmokingMan) only

takes about 5 minutes (at the most); it's the rest that needs more time than that.

It even took me about 5-8 minutes to find the correct variable and registry-keys using

Google (in my first reply); you didn't think I knew that beforehand, did you?

(I hardly ever mess with the registry, other than to write configuration-settings of my own

applications).

And no: I'm not employed as a programmer (I work for the Dutch government, but in an entirely

different, albeit technical, type of field) and at this time I'm on sick-leave (10 months

already), so my response wasn't meant to start a flame war between coders and scripters; I

only program purely for the fun of it and to keep myself busy.

So I'm sorry if I gave the impression of being an a**; I only used two words: "Script kiddie"

and "Programming" and I'm immediatly getting flamed... why is that? :unsure:

(Well... maybe I'm an a** after all?) :angel

I prefer coding instead of scripting because it's easy, fast and you don't need an interpreter

or run-time libraries: everything is compiled into one self-contained exe and you can debug

your code to your hearts content.

The only downside is that an executable is a lot larger than a script (gosh: even an "Empty"

form doing nothing, compiled under Delphi is around 400kB in size) :wacko:

So if you wish (and the contest is still on) I would be happy to send in a simple (command-line)

version (thus without any thrills), but don't complain if it wasn't fully tested and thought

through and it hangs (or f*cks up) your computer :lol:

Greetz,

Peter.

PS. I do like to emphasize it's not my intention to insult anyone here

Share this post


Link to post
Share on other sites

thanks for the help and the script.

when i save the script in notepad and save it as vbs(like i always do)

when i run it gives me an error on the line 51 character 28

it says "its not possible to use brackets while calling a function"

but the character 28 it doesn't exist!!!

many thanks once again

Change This

  Act.RegWrite(A2(0),Dir)

To This

  Act.RegWrite A2(0),Dir 

The only downside is that an executable is a lot larger than a script (gosh: even an "Empty" 
form doing nothing, compiled under Delphi is around 400kB in size)

The hta which has a GUI is only 4.42 kb, I could do this in VB.net at around 100 kb or less.

ChangeUserlocProfile.png

Share this post


Link to post
Share on other sites

Yes... but VB uses runtime modules... ;)

With Delphi you can also use Runtime-modules (*.bpl) and then my "application" would

be under 100kB as well :yes:

...and a HTA-script uses an interpreter (which is well over several 100's of kB's)

Edited by VideoRipper

Share this post


Link to post
Share on other sites

I prefer coding instead of scripting because it's easy

It's nowhere near as easy as something like vbscript or a simple batch file using reg.exe or the like. vbscript wins here, hands down (could anything be easier than BASIC really? That would have to be like Logo :lol: )

fast

It's definitely not fast(er) to write, and as for execution time, basically all methods are measured in ridiculously tiny fractions of 1 second (instantly) so I think it's pretty much irrelevant. I'm hesitant between a tie, or a win for vbscript (mostly for being quicker to write)

and you don't need an interpreter

With all of these methods, no "3rd party" interpreter is required, it works out of the box (unlike say, a non-compiled autoit script). I fail to see how this really matters when you look at the big picture. I'd call that a tie, mostly because I fail to see the relevance (much like it doesn't really matter when I read a web page if it was served as static HTML or generated by an interpreted PHP script -- ultimately it's the content that matters to me, not whether if it was pulled from disk or a database)

or run-time libraries: everything is compiled into one self-contained exe

Actually, the scripts (vbscript/jscript/batchfiles at least) are mostly self-contained, as in they need nothing extra installed on freshly installed copy of Windows (no runtime or anything to install). Whereas with most programming languages... not so! With C++ you'd often need the MS VC++ redist (2005 or 2008, with the proper SP), with C# or VB (".Net") or C++/CLI you'd need the .Net framework installed, for older VB (yuck) you'd need the VB runtimes installed and so on. And if you're making reference to the script relying on standard, built-in components of Windows (like cscript) to run, then so does you app (using many DLLs like advapi32.dll for the registry stuff and so on). vbscript wins here too.

and you can debug your code to your hearts content

Just like you can debug a vbscript by passing the //X command line arg. Yet another tie.

...and a HTA-script uses an interpreter (which is well over several 100's of kB's)

So what? I fail to see how this matters as well. It gets the job done, it's quick to write, easy to maintain and modify, no need to compile anything, works out of the box, etc. Sounds like a winner to me!

Windows admins use vbscript for a reason. It's great for these kinds of things (especially when combined with WMI and ADSI). You can whip up something to do simple tasks easily and VERY quickly, often reusing large chunks of previous scripts. jscript is nicer in some ways (nicer syntax IMO, and also decent error handling) but a lot of admins aren't too familiar with the syntax so it's not used nearly as much. Powershell is slowly catching on too. It's great for a lot of things, once you get the hang of it. A couple quick examples just to show (works out of the box on Win7):

1) How to disable services whose names are listed in disablesvcs.txt (for all the folks into that kind of stuff):

Get-Content c:\somewhere\disablesvcs.txt | Set-Service -StartupType disabled

It's definitely a LOT faster than opening a file (permissions, error handling, etc), reading the names into memory, closing the file, and then iterating through the services one by one looking for a match, setting their properties as you go (or something along those lines)...

2) How to enumerate all the services installed, their running status, and then create HTML out of it, and write that to disk (simple to do, but normally requires lots of boring mind-numbing, time-consuming code to be written, and then debugged and maintained), with PS:

Get-Service | ConvertTo-Html | Out-File c:\somewhere\services.html

You can do something like this (from scratch) in like 15 seconds flat. Say, you changed your mind, or need to do something slightly different and want to reuse this script (code reuse!), or you just need the info in another format for processing/analyzing it, and it needs to be in XML instead or perhaps CSV? No problem! Just use ConvertTo-Xml or ConvertTo-Csv instead, problem solved. Want to do sorting, picking what columns to display, change the page title or whatever? Sure thing... (Obviously it does FAR more than just playing with services)

They're great, time saving, efficient tools, and they most definitely have their uses. They're popular for a reason. I definitely wouldn't want to use C++ for this (that would be crazy, I'm sure it would drive a lot of admins to drink), and even C# would be a real drag in most cases.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...